index.tsx
1.1 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
import { ImageProps, Image as AntdImage } from 'antd';
export interface ImageComponentProps extends ImageProps {
imageSources?: string[];
showImage?: boolean;
toggleImageVisibility?: (value: any) => void;
}
const ImageComponent: React.FC<ImageComponentProps> = ({
src,
style,
preview,
imageSources = [],
showImage,
toggleImageVisibility,
...args
}) => {
let myPreview = preview
? preview
: {
visible: showImage,
src: src,
};
return (
<>
<AntdImage
width={200}
style={style}
src={src}
preview={myPreview}
{...args}
onClick={() => toggleImageVisibility && toggleImageVisibility(!showImage)}
/>
<div style={{ display: 'none' }}>
<AntdImage.PreviewGroup
preview={{
visible: showImage,
onVisibleChange: (vis) => toggleImageVisibility && toggleImageVisibility(vis),
}}
>
{imageSources.map((data: string, index: number) => (
<AntdImage src={data} key={index} />
))}
</AntdImage.PreviewGroup>
</div>
</>
);
};
export default ImageComponent;