Skip to content

Commit a3ccdef

Browse files
authored
feat(img): add img flip feature (#6785)
1 parent e8c2860 commit a3ccdef

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

components/image/PreviewGroup.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ZoomOutOutlined from '@ant-design/icons-vue/ZoomOutOutlined';
1111
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
1212
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
1313
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
14+
import SwapOutlined from '@ant-design/icons-vue/SwapOutlined';
1415
import useStyle from './style';
1516
import { anyType } from '../_util/type';
1617

@@ -22,6 +23,8 @@ export const icons = {
2223
close: <CloseOutlined />,
2324
left: <LeftOutlined />,
2425
right: <RightOutlined />,
26+
flipX: <SwapOutlined />,
27+
flipY: <SwapOutlined rotate={90} />,
2528
};
2629
const previewGroupProps = () => ({
2730
previewPrefixCls: String,

components/vc-image/src/Preview.tsx

+28-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export interface PreviewProps extends Omit<IDialogChildProps, 'onClose' | 'mask'
3636
close?: VNode;
3737
left?: VNode;
3838
right?: VNode;
39+
flipX?: VNode;
40+
flipY?: VNode;
3941
};
4042
}
4143

@@ -60,10 +62,13 @@ const Preview = defineComponent({
6062
props: previewProps,
6163
emits: ['close', 'afterClose'],
6264
setup(props, { emit, attrs }) {
63-
const { rotateLeft, rotateRight, zoomIn, zoomOut, close, left, right } = reactive(props.icons);
65+
const { rotateLeft, rotateRight, zoomIn, zoomOut, close, left, right, flipX, flipY } = reactive(
66+
props.icons,
67+
);
6468

6569
const scale = shallowRef(1);
6670
const rotate = shallowRef(0);
71+
const flip = reactive({ x: 1, y: 1 });
6772
const [position, setPosition] = useFrameSetState<{
6873
x: number;
6974
y: number;
@@ -130,6 +135,15 @@ const Preview = defineComponent({
130135
const onRotateLeft = () => {
131136
rotate.value -= 90;
132137
};
138+
139+
const onFlipX = () => {
140+
flip.x = -flip.x;
141+
};
142+
143+
const onFlipY = () => {
144+
flip.y = -flip.y;
145+
};
146+
133147
const onSwitchLeft: MouseEventHandler = event => {
134148
event.preventDefault();
135149
// Without this mask close will abnormal
@@ -180,6 +194,16 @@ const Preview = defineComponent({
180194
onClick: onRotateLeft,
181195
type: 'rotateLeft',
182196
},
197+
{
198+
icon: flipX,
199+
onClick: onFlipX,
200+
type: 'flipX',
201+
},
202+
{
203+
icon: flipY,
204+
onClick: onFlipY,
205+
type: 'flipY',
206+
},
183207
];
184208

185209
const onMouseUp: MouseEventHandler = () => {
@@ -365,7 +389,9 @@ const Preview = defineComponent({
365389
src={combinationSrc.value}
366390
alt={props.alt}
367391
style={{
368-
transform: `scale3d(${scale.value}, ${scale.value}, 1) rotate(${rotate.value}deg)`,
392+
transform: `scale3d(${flip.x * scale.value}, ${flip.y * scale.value}, 1) rotate(${
393+
rotate.value
394+
}deg)`,
369395
}}
370396
/>
371397
</div>

0 commit comments

Comments
 (0)