Skip to content

Commit

Permalink
feat: modify layout and support closeIcon (#267)
Browse files Browse the repository at this point in the history
* feat: modify layout and support closeIcon

* fix: closeIcon

* demo: adjust style

* refactor: adjust dom layout

* demo: updated

* refactor: remove iconClassName
  • Loading branch information
linxianxi authored Jun 29, 2023
1 parent 58519e4 commit 9b25d8c
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 145 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

React Image.

<!-- prettier-ignore -->
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![build status][github-actions-image]][github-actions-url]
Expand Down Expand Up @@ -77,10 +78,11 @@ export default () => (
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| visible | boolean | - | Whether the preview is open or not |
| src | string | - | customize preview src |
| closeIcon | React.ReactNode | - | Custom close icon |
| src | string | - | Customize preview src |
| scaleStep | number | 0.5 | The number to which the scale is increased or decreased |
| minScale | number | 1 | min scale |
| maxScale | number | 50 | max scale |
| minScale | number | 1 | Min scale |
| maxScale | number | 50 | Max scale |
| forceRender | boolean | - | Force render preview |
| getContainer | string \| HTMLElement \| (() => HTMLElement) \| false | document.body | Return the mount node for preview |
| imageRender | (originalNode: React.ReactNode, info: { transform: [TransformType](#TransformType) }) => React.ReactNode | - | Customize image |
Expand Down Expand Up @@ -116,14 +118,15 @@ export default () => (
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| visible | boolean | - | Whether the preview is open or not |
| current | number | - | current index |
| current | number | - | Current index |
| closeIcon | React.ReactNode | - | Custom close icon |
| scaleStep | number | 0.5 | The number to which the scale is increased or decreased |
| minScale | number | 1 | min scale |
| maxScale | number | 50 | max scale |
| minScale | number | 1 | Min scale |
| maxScale | number | 50 | Max scale |
| forceRender | boolean | - | Force render preview |
| getContainer | string \| HTMLElement \| (() => HTMLElement) \| false | document.body | Return the mount node for preview |
| items | (string \| { src: string, alt: string, crossOrigin: string, ... })[] | - | preview group |
| countRender | (current: number, total: number) => string | - | Customize count |
| countRender | (current: number, total: number) => React.ReactNode | - | Customize count |
| imageRender | (originalNode: React.ReactNode, info: { transform: [TransformType](#TransformType), current: number }) => React.ReactNode | - | Customize image |
| toolbarRender | (originalNode: React.ReactNode, info: [ToolbarRenderInfoType](#ToolbarRenderInfoType)) => React.ReactNode | - | Customize toolbar |
| onVisibleChange | (visible: boolean, prevVisible: boolean, current: number) => void | - | Callback when visible is changed |
Expand Down Expand Up @@ -173,7 +176,6 @@ type TransformAction =
rotateRightIcon: React.ReactNode;
zoomOutIcon: React.ReactNode;
zoomInIcon: React.ReactNode;
closeIcon: React.ReactNode;
};
actions: {
onFlipY: () => void;
Expand All @@ -182,7 +184,6 @@ type TransformAction =
onRotateRight: () => void;
onZoomOut: () => void;
onZoomIn: () => void;
onClose: () => void;
};
transform: {
x: number;
Expand Down
68 changes: 39 additions & 29 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,17 @@
user-select: none;
vertical-align: middle;
max-width: 100%;
max-height: 100%;
max-height: 70%;

&-wrapper {
.box;
display: flex;
justify-content: center;
align-items: center;

& > * {
pointer-events: auto;
}

&::before {
content: '';
display: inline-block;
height: 50%;
width: 1px;
margin-right: -1px;
}
}
}

Expand All @@ -138,36 +133,56 @@
-webkit-overflow-scrolling: touch;
}

&-close {
position: fixed;
top: 32px;
right: 32px;
display: flex;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 50%;
padding: 15px;
outline: 0;
border: 0;
cursor: pointer;

&:hover {
opacity: 0.3;
}
}

&-operations-wrapper {
position: fixed;
z-index: @zindex-preview-mask + 1;
}

&-operations {
.reset;
pointer-events: auto;
list-style: none;
&-footer {
position: fixed;
display: flex;
top: 0;
right: 0;
z-index: @zindex-preview-mask + 1;
bottom: 32px;
left: 0;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
z-index: @zindex-preview-mask + 1;
}

&-progress {
margin-bottom: 20px;
}

&-operations {
display: flex;
color: @text-color;
background: fade(@preview-mask-bg, 45%);

&-progress {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
border-radius: 100px;
padding: 0 20px;

&-operation {
padding: 10px;
cursor: pointer;
margin-left: 10px;
font-size: 18px;
&-disabled {
pointer-events: none;
color: @text-color-disabled;
Expand All @@ -176,9 +191,6 @@
margin-left: 0;
}
}
&-icon {
font-size: 18px;
}
}

&-switch-left {
Expand All @@ -194,7 +206,6 @@
align-items: center;
justify-content: center;
z-index: @zindex-preview-mask + 1;
pointer-events: auto;
cursor: pointer;
color: @text-color;
&-disabled {
Expand Down Expand Up @@ -223,7 +234,6 @@
align-items: center;
justify-content: center;
z-index: @zindex-preview-mask + 1;
pointer-events: auto;
cursor: pointer;
color: @text-color;
&-disabled {
Expand Down
23 changes: 23 additions & 0 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import {
CloseOutlined,
LeftOutlined,
RightOutlined,
RotateLeftOutlined,
RotateRightOutlined,
SwapOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';

const icons = {
rotateLeft: <RotateLeftOutlined />,
rotateRight: <RotateRightOutlined />,
zoomIn: <ZoomInOutlined />,
zoomOut: <ZoomOutOutlined />,
close: <CloseOutlined />,
left: <LeftOutlined />,
right: <RightOutlined />,
flipX: <SwapOutlined />,
flipY: <SwapOutlined rotate={90} />,
};

export default function Base() {
return (
<div>
Expand All @@ -15,6 +37,7 @@ export default function Base() {
console.log('click');
}}
preview={{
icons,
onVisibleChange: visible => {
console.log('visible', visible);
},
Expand Down
23 changes: 23 additions & 0 deletions docs/examples/previewgroup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import {
CloseOutlined,
LeftOutlined,
RightOutlined,
RotateLeftOutlined,
RotateRightOutlined,
SwapOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';
import Image from 'rc-image';
import React from 'react';
import '../../assets/index.less';

const icons = {
rotateLeft: <RotateLeftOutlined />,
rotateRight: <RotateRightOutlined />,
zoomIn: <ZoomInOutlined />,
zoomOut: <ZoomOutOutlined />,
close: <CloseOutlined />,
left: <LeftOutlined />,
right: <RightOutlined />,
flipX: <SwapOutlined />,
flipY: <SwapOutlined rotate={90} />,
};

export default function PreviewGroup() {
return (
<div>
<Image.PreviewGroup
icons={icons}
preview={{
countRender: (current, total) => `第${current}张 / 总共${total}张`,
onChange: (current, prev) =>
Expand Down
Loading

1 comment on commit 9b25d8c

@vercel
Copy link

@vercel vercel bot commented on 9b25d8c Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.