@@ -13,35 +13,61 @@ interface ImageComponentProps {
13
13
srcSet ?: string ;
14
14
className ?: string ;
15
15
style ?: React . CSSProperties ;
16
+ caption ?: string ;
17
+ align ?: 'left' | 'center' | 'right' ;
16
18
onClick ?: ( event : React . MouseEvent < HTMLImageElement , MouseEvent > ) => void ;
17
19
}
18
20
19
- const CustomImage : React . FC < ImageComponentProps > = ( { src, alt, ...props } ) => {
21
+ const CustomImage : React . FC < ImageComponentProps > = ( {
22
+ src,
23
+ alt,
24
+ caption,
25
+ align = 'left' ,
26
+ ...props
27
+ } ) => {
20
28
const [ isZoomed , setIsZoomed ] = useState ( false ) ;
21
-
22
29
const handleZoomClick = ( ) => {
23
30
setIsZoomed ( true ) ;
24
31
} ;
25
-
26
32
const handleZoomClose = ( ) => {
27
33
setIsZoomed ( false ) ;
28
34
} ;
29
-
35
+
36
+ const figureStyle : React . CSSProperties = {
37
+ margin : '1rem 0' ,
38
+ textAlign : align ,
39
+ width : '100%' ,
40
+ ...props . style
41
+ } ;
42
+
43
+ const captionStyle : React . CSSProperties = {
44
+ fontSize : '0.9rem' ,
45
+ color : '#666' ,
46
+ marginTop : '0.5rem' ,
47
+ textAlign : align
48
+ } ;
49
+
30
50
return (
31
51
< >
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
- />
52
+ < figure style = { figureStyle } >
53
+ < img
54
+ src = { src }
55
+ alt = { alt || caption || '' }
56
+ loading = "lazy"
57
+ onClick = { handleZoomClick }
58
+ { ...props }
59
+ style = { {
60
+ cursor : 'pointer' ,
61
+ maxWidth : '100%' ,
62
+ height : 'auto' ,
63
+ boxShadow : 'rgba(149, 157, 165, 0.2) 0px 8px 24px' ,
64
+ borderRadius : '15px' ,
65
+ width : '50%'
66
+ } }
67
+ />
68
+ { caption && < figcaption style = { captionStyle } > { caption } </ figcaption > }
69
+ </ figure >
70
+
45
71
< Dialog
46
72
open = { isZoomed }
47
73
onClose = { handleZoomClose }
@@ -59,7 +85,7 @@ const CustomImage: React.FC<ImageComponentProps> = ({ src, alt, ...props }) => {
59
85
>
60
86
< img
61
87
src = { src }
62
- alt = { alt }
88
+ alt = { alt || caption || '' }
63
89
onClick = { handleZoomClose }
64
90
style = { {
65
91
objectFit : 'contain' ,
0 commit comments