-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathImageViewerMini.tsx
More file actions
119 lines (112 loc) · 3.08 KB
/
ImageViewerMini.tsx
File metadata and controls
119 lines (112 loc) · 3.08 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
import React, { KeyboardEvent, MouseEvent } from 'react';
import classNames from 'classnames';
import { TNode } from '../common';
import Dialog from '../dialog';
import useConfig from '../hooks/useConfig';
import { ImageModalItem, ImageViewerUtils } from './ImageViewerModal';
import type { ImageInfo, ImageScale, ImageViewerScale, TdImageViewerProps } from './type';
export interface ImageModalMiniProps {
visible: boolean;
title?: TNode;
draggable: boolean;
index: number;
scale: number;
mirror: number;
images: ImageInfo[];
imageScale: ImageScale;
viewerScale: ImageViewerScale;
rotateZ: number;
currentImage: ImageInfo;
zIndex: number;
errorText: string;
tipText: {
mirror: string;
rotate: string;
originalSize: string;
};
imageReferrerpolicy?: TdImageViewerProps['imageReferrerpolicy'];
className?: string;
style?: React.CSSProperties;
prev: () => void;
next: () => void;
onMirror: () => void;
onZoomIn: () => void;
onZoomOut: () => void;
onReset: () => void;
onRotate: () => void;
onClose: (context: { trigger: 'close-btn' | 'overlay' | 'esc'; e: MouseEvent<HTMLElement> | KeyboardEvent }) => void;
innerClassName: TdImageViewerProps['innerClassName'];
}
export const ImageModalMiniContent: React.FC<ImageModalMiniProps> = (props) => {
const { classPrefix } = useConfig();
return (
<div className={`${classPrefix}-image-viewer-mini__content`}>
<ImageModalItem
rotateZ={props.rotateZ}
scale={props.scale}
mirror={props.mirror}
src={props.currentImage.mainImage}
preSrc={props.currentImage.thumbnail}
errorText={props.errorText}
imageReferrerpolicy={props.imageReferrerpolicy}
isSvg={props.currentImage.isSvg}
innerClassName={props.innerClassName}
/>
</div>
);
};
export const ImageModalMini: React.FC<ImageModalMiniProps> = (props) => {
const {
visible,
title,
scale,
currentImage,
draggable,
tipText,
className,
style,
onZoomOut,
onZoomIn,
onClose,
onRotate,
onMirror,
onReset,
innerClassName,
} = props;
const { classPrefix } = useConfig();
const footer = (
<div className={`${classPrefix}-image-viewer-mini__footer`}>
<ImageViewerUtils
scale={scale}
tipText={tipText}
currentImage={currentImage}
zIndex={props.zIndex + 1}
onZoomIn={onZoomIn}
onZoomOut={onZoomOut}
onRotate={onRotate}
onMirror={onMirror}
onReset={onReset}
/>
</div>
);
return (
<Dialog
className={classNames(`${classPrefix}-image-viewer__dialog`, className)}
dialogClassName={innerClassName}
style={style}
draggable={draggable}
visible={visible}
width="min(90vw, 1000px)"
placement="center"
mode="modeless"
closeOnOverlayClick={false}
cancelBtn={null}
confirmBtn={null}
header={<span className={`${classPrefix}-image-viewer__dialog-title`}>{title}</span>}
footer={footer}
onClose={onClose}
>
<ImageModalMiniContent {...props} />
</Dialog>
);
};