-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathOperations.tsx
More file actions
172 lines (167 loc) · 4.03 KB
/
Operations.tsx
File metadata and controls
172 lines (167 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import * as React from 'react';
import classnames from 'classnames';
import CSSMotion from 'rc-motion';
import Portal from '@rc-component/portal';
import { MIN_SCALE, MAX_SCALE } from './previewConfig';
import type { PreviewProps } from './Preview';
interface OperationsProps
extends Pick<
PreviewProps,
| 'visible'
| 'maskTransitionName'
| 'getContainer'
| 'prefixCls'
| 'rootClassName'
| 'icons'
| 'countRender'
| 'onClose'
> {
showSwitch: boolean;
showProgress: boolean;
current: number;
count: number;
scale: number;
onSwitchLeft: React.MouseEventHandler<HTMLDivElement>;
onSwitchRight: React.MouseEventHandler<HTMLDivElement>;
onRefresh: () => void;
onZoomIn: () => void;
onZoomOut: () => void;
onRotateRight: () => void;
onRotateLeft: () => void;
onFlipX: () => void;
onFlipY: () => void;
}
const Operations: React.FC<OperationsProps> = (props) => {
const {
visible,
maskTransitionName,
getContainer,
prefixCls,
rootClassName,
icons,
countRender,
showSwitch,
showProgress,
current,
count,
scale,
onSwitchLeft,
onSwitchRight,
onClose,
onRefresh,
onZoomIn,
onZoomOut,
onRotateRight,
onRotateLeft,
onFlipX,
onFlipY
} = props;
const { rotateLeft, rotateRight, refresh, zoomIn, zoomOut, close, left, right, flipX, flipY } = icons;
const toolClassName = `${prefixCls}-operations-operation`;
const iconClassName = `${prefixCls}-operations-icon`;
const tools = [
{
icon: close,
onClick: onClose,
type: 'close',
},
{
icon: refresh,
onClick: onRefresh,
type: 'refresh',
},
{
icon: zoomIn,
onClick: onZoomIn,
type: 'zoomIn',
disabled: scale === MAX_SCALE,
},
{
icon: zoomOut,
onClick: onZoomOut,
type: 'zoomOut',
disabled: scale === MIN_SCALE,
},
{
icon: rotateRight,
onClick: onRotateRight,
type: 'rotateRight',
},
{
icon: rotateLeft,
onClick: onRotateLeft,
type: 'rotateLeft',
},
{
icon: flipX,
onClick: onFlipX,
type: 'flipX',
},
{
icon: flipY,
onClick: onFlipY,
type: 'flipY',
},
];
const operations = (
<>
{showSwitch && (
<>
<div
className={classnames(`${prefixCls}-switch-left`, {
[`${prefixCls}-switch-left-disabled`]: current === 0,
})}
onClick={onSwitchLeft}
>
{left}
</div>
<div
className={classnames(`${prefixCls}-switch-right`, {
[`${prefixCls}-switch-right-disabled`]: current === count - 1,
})}
onClick={onSwitchRight}
>
{right}
</div>
</>
)}
<ul className={`${prefixCls}-operations`}>
{showProgress && (
<li className={`${prefixCls}-operations-progress`}>
{countRender?.(current + 1, count) ??
`${current + 1} / ${count}`}
</li>
)}
{tools.map(({ icon, onClick, type, disabled }) => (
<li
className={classnames(toolClassName, {
[`${prefixCls}-operations-operation-${type}`]: true,
[`${prefixCls}-operations-operation-disabled`]: !!disabled,
})}
onClick={onClick}
key={type}
>
{React.isValidElement(icon)
? React.cloneElement<{ className?: string }>(icon, { className: iconClassName })
: icon}
</li>
))}
</ul>
</>
);
return (
<CSSMotion visible={visible} motionName={maskTransitionName}>
{({ className, style }) => (
<Portal open getContainer={getContainer ?? document.body}>
<div
className={classnames(`${prefixCls}-operations-wrapper`, className, rootClassName)}
style={style}
>
{operations}
</div>
</Portal>
)}
</CSSMotion>
);
};
export default Operations;