Skip to content

Commit

Permalink
feat: operation default icons
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang committed Nov 28, 2023
1 parent 06939db commit 1d6c82f
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 31 deletions.
2 changes: 2 additions & 0 deletions docs/examples/album.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Image from 'rc-image';
import React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function PreviewGroup() {
return (
<div>
<Image.PreviewGroup
icons={defaultIcons}
items={[require('./images/1.jpeg'), require('./images/2.jpeg'), require('./images/3.jpeg')]}
>
<Image src={require('./images/1.jpeg')} />
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Image from 'rc-image';
import * as React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';


export default function Base() {
Expand All @@ -16,6 +17,7 @@ export default function Base() {
console.log('click');
}}
preview={{
icons: defaultIcons,
onVisibleChange: visible => {
console.log('visible', visible);
},
Expand All @@ -29,24 +31,27 @@ export default function Base() {
style={{
marginRight: 24,
}}
preview={{ mask: 'Click to Preview' }}
preview={{ icons: defaultIcons, mask: 'Click to Preview' }}
/>
<Image
src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*ngiJQaLQELEAAAAAAAAAAABkARQnAQ"
width={200}
style={{
marginRight: 24,
}}
preview={{icons: defaultIcons}}
/>
<Image
src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*NZuwQp_vcIQAAAAAAAAAAABkARQnAQ"
width={200}
preview={{icons: defaultIcons}}
/>

<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
height={100}
preview={{icons: defaultIcons}}
/>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/controlled.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import Image from 'rc-image';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function Base() {
const [visible, setVisible] = React.useState(false);
Expand All @@ -20,6 +21,7 @@ export default function Base() {
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
preview={{
icons: defaultIcons,
visible,
onVisibleChange: value => {
setVisible(value);
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/controlledWithGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as React from 'react';
import Image from 'rc-image';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function Base() {
const [visible, setVisible] = React.useState(false);
Expand All @@ -19,6 +20,7 @@ export default function Base() {
</div>
<Image.PreviewGroup
preview={{
icons: defaultIcons,
visible,
onVisibleChange: value => {
setVisible(value);
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import Image from 'rc-image';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function Base() {
return (
<Image
preview={{ mask: 'preview!' }}
preview={{ mask: 'preview!', icons: defaultIcons }}
src="error1"
fallback="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/imageRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Image from 'rc-image';
import React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function imageRender() {
return (
Expand All @@ -9,6 +10,7 @@ export default function imageRender() {
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
preview={{
icons: defaultIcons,
toolbarRender: () => null,
imageRender: () => (
<video
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/placeholder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import Image from 'rc-image';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function Base() {
const [random, setRandom] = React.useState(Date.now());
Expand All @@ -21,6 +22,7 @@ export default function Base() {
src={`${require('./images/placeholder.png')}?random=${random}`}
width={400}
placeholder
preview={{icons: defaultIcons}}
/>
</div>

Expand All @@ -30,6 +32,7 @@ export default function Base() {
// eslint-disable-next-line global-require
src={`${require('./images/placeholder.png')}?random=${random + 1}`}
width={400}
preview={{icons: defaultIcons}}
placeholder={
<Image
width="100%"
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/thumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import * as React from 'react';
import Image from 'rc-image';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function Thumbnail() {
return (
<div>
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/resize,p_10/quality,q_10"
preview={{
icons: defaultIcons,
src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}}
width={200}
/>

<br />
<h1>PreviewGroup</h1>
<Image.PreviewGroup>
<Image.PreviewGroup preview={{icons: defaultIcons}}>
<Image
key={1}
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/resize,p_10/quality,q_10"
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/toolbarRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Image from 'rc-image';
import React from 'react';
import '../../assets/index.less';
import { defaultIcons } from './common';

export default function ToolbarRender() {
return (
Expand All @@ -9,6 +10,7 @@ export default function ToolbarRender() {
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
preview={{
icons: defaultIcons,
toolbarRender: (
_,
{
Expand Down
25 changes: 1 addition & 24 deletions src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@ import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';
import PreviewGroup from './PreviewGroup';

import {
CloseOutlined,
LeftOutlined,
RightOutlined,
RotateLeftOutlined,
RotateRightOutlined,
SwapOutlined,
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';

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

export interface ImagePreviewType
extends Omit<
IDialogPropTypes,
Expand Down Expand Up @@ -121,7 +98,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
mask: previewMask,
maskClassName,
movable,
icons = defaultIcons,
icons,
scaleStep,
minScale,
maxScale,
Expand Down
2 changes: 1 addition & 1 deletion src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Preview: React.FC<PreviewProps> = props => {
movable = true,
onClose,
visible,
icons,
icons = {},
rootClassName,
closeIcon,
getContainer,
Expand Down
6 changes: 3 additions & 3 deletions src/PreviewGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { useState } from 'react';
import { PreviewGroupContext } from './context';
import type { TransformType } from './hooks/useImageTransform';
import usePreviewItems from './hooks/usePreviewItems';
import { defaultIcons, type ImagePreviewType } from './Image';
import { type ImagePreviewType } from './Image';
import type { ImageElementProps, OnGroupPreview } from './interface';
import type { PreviewProps, ToolbarRenderInfoType } from './Preview';
import Preview from './Preview';

export interface PreviewGroupPreview
extends Omit<
ImagePreviewType,
'icons' | 'mask' | 'maskClassName' | 'onVisibleChange' | 'toolbarRender' | 'imageRender'
| 'mask' | 'maskClassName' | 'onVisibleChange' | 'toolbarRender' | 'imageRender'
> {
/**
* If Preview the show img index
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface GroupConsumerProps {
const Group: React.FC<GroupConsumerProps> = ({
previewPrefixCls = 'rc-image-preview',
children,
icons = defaultIcons,
icons = {},
items,
preview,
fallback,
Expand Down

0 comments on commit 1d6c82f

Please sign in to comment.