Skip to content

feat(image): add image flip feature #6785

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

Merged
merged 1 commit into from
Jul 29, 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
3 changes: 3 additions & 0 deletions components/image/PreviewGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ZoomOutOutlined from '@ant-design/icons-vue/ZoomOutOutlined';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
import SwapOutlined from '@ant-design/icons-vue/SwapOutlined';
import useStyle from './style';
import { anyType } from '../_util/type';

Expand All @@ -22,6 +23,8 @@ export const icons = {
close: <CloseOutlined />,
left: <LeftOutlined />,
right: <RightOutlined />,
flipX: <SwapOutlined />,
flipY: <SwapOutlined rotate={90} />,
};
const previewGroupProps = () => ({
previewPrefixCls: String,
Expand Down
30 changes: 28 additions & 2 deletions components/vc-image/src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface PreviewProps extends Omit<IDialogChildProps, 'onClose' | 'mask'
close?: VNode;
left?: VNode;
right?: VNode;
flipX?: VNode;
flipY?: VNode;
};
}

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

const scale = shallowRef(1);
const rotate = shallowRef(0);
const flip = reactive({ x: 1, y: 1 });
const [position, setPosition] = useFrameSetState<{
x: number;
y: number;
Expand Down Expand Up @@ -121,6 +126,15 @@ const Preview = defineComponent({
const onRotateLeft = () => {
rotate.value -= 90;
};

const onFlipX = () => {
flip.x = -flip.x;
};

const onFlipY = () => {
flip.y = -flip.y;
};

const onSwitchLeft: MouseEventHandler = event => {
event.preventDefault();
// Without this mask close will abnormal
Expand Down Expand Up @@ -171,6 +185,16 @@ const Preview = defineComponent({
onClick: onRotateLeft,
type: 'rotateLeft',
},
{
icon: flipX,
onClick: onFlipX,
type: 'flipX',
},
{
icon: flipY,
onClick: onFlipY,
type: 'flipY',
},
];

const onMouseUp: MouseEventHandler = () => {
Expand Down Expand Up @@ -356,7 +380,9 @@ const Preview = defineComponent({
src={combinationSrc.value}
alt={props.alt}
style={{
transform: `scale3d(${scale.value}, ${scale.value}, 1) rotate(${rotate.value}deg)`,
transform: `scale3d(${flip.x * scale.value}, ${flip.y * scale.value}, 1) rotate(${
rotate.value
}deg)`,
}}
/>
</div>
Expand Down