Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: operation default icons #297

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 6 additions & 23 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
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';
import { defaultIcons } from './common';

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 (
Expand All @@ -37,7 +17,7 @@ export default function Base() {
console.log('click');
}}
preview={{
icons,
icons: defaultIcons,
onVisibleChange: visible => {
console.log('visible', visible);
},
Expand All @@ -51,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
25 changes: 25 additions & 0 deletions docs/examples/common.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import React from 'react';
import type { PreviewProps } from '@/Preview';
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} />,
};
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
4 changes: 2 additions & 2 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 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
Loading