File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React , { useState } from 'react' ;
2
+ import { Dialog } from '../../base' ;
3
+
4
+ interface ImageComponentProps {
5
+ src : string ;
6
+ alt ?: string ;
7
+ width ?: number | string ;
8
+ height ?: number | string ;
9
+ loading ?: undefined | 'eager' | 'lazy' ;
10
+ decoding ?: 'sync' | 'async' | 'auto' ;
11
+ crossOrigin ?: 'anonymous' | 'use-credentials' | '' ;
12
+ sizes ?: string ;
13
+ srcSet ?: string ;
14
+ className ?: string ;
15
+ style ?: React . CSSProperties ;
16
+ onClick ?: ( event : React . MouseEvent < HTMLImageElement , MouseEvent > ) => void ;
17
+ }
18
+
19
+ const CustomImage : React . FC < ImageComponentProps > = ( { src, alt, ...props } ) => {
20
+ const [ isZoomed , setIsZoomed ] = useState ( false ) ;
21
+
22
+ const handleZoomClick = ( ) => {
23
+ setIsZoomed ( true ) ;
24
+ } ;
25
+
26
+ const handleZoomClose = ( ) => {
27
+ setIsZoomed ( false ) ;
28
+ } ;
29
+
30
+ return (
31
+ < >
32
+ < img
33
+ src = { src }
34
+ alt = { alt }
35
+ loading = "lazy"
36
+ onClick = { handleZoomClick }
37
+ { ...props }
38
+ style = { {
39
+ cursor : 'pointer' ,
40
+ maxWidth : '100%' ,
41
+ height : 'auto' ,
42
+ ...props . style
43
+ } }
44
+ />
45
+ < Dialog
46
+ open = { isZoomed }
47
+ onClose = { handleZoomClose }
48
+ style = { {
49
+ backgroundColor : 'rgba(0, 0, 0, 0.8)'
50
+ } }
51
+ PaperProps = { {
52
+ style : {
53
+ background : 'transparent' ,
54
+ boxShadow : 'none' ,
55
+ overflow : 'auto' ,
56
+ maxWidth : '60rem'
57
+ }
58
+ } }
59
+ >
60
+ < img
61
+ src = { src }
62
+ alt = { alt }
63
+ style = { {
64
+ objectFit : 'contain' ,
65
+ maxWidth : '100%' ,
66
+ maxHeight : '100%'
67
+ } }
68
+ />
69
+ </ Dialog >
70
+ </ >
71
+ ) ;
72
+ } ;
73
+
74
+ export default CustomImage ;
Original file line number Diff line number Diff line change
1
+ import CustomImage from './CustomImage' ;
2
+ export { CustomImage } ;
Original file line number Diff line number Diff line change 8
8
CustomColumnVisibilityControl ,
9
9
CustomColumnVisibilityControlProps
10
10
} from './CustomColumnVisibilityControl/CustomColumnVisibilityControl' ;
11
+ import { CustomImage } from './CustomImage' ;
11
12
import { CustomTooltip , InfoTooltip } from './CustomTooltip' ;
12
13
import {
13
14
CustomDialog ,
@@ -54,6 +55,7 @@ export {
54
55
ConnectionChip ,
55
56
CustomColumnVisibilityControl ,
56
57
CustomDialog ,
58
+ CustomImage ,
57
59
CustomTooltip ,
58
60
EmptyState ,
59
61
ErrorBoundary ,
You can’t perform that action at this time.
0 commit comments