11import React , { useState } from 'react' ;
22import { Dialog } from '../../base' ;
3+ import { styled } from '../../theme' ;
34
45interface ImageComponentProps {
56 src : string ;
@@ -17,13 +18,27 @@ interface ImageComponentProps {
1718 align ?: 'left' | 'center' | 'right' ;
1819 onClick ?: ( event : React . MouseEvent < HTMLImageElement , MouseEvent > ) => void ;
1920}
21+ interface AlignProps {
22+ align : 'left' | 'center' | 'right' ;
23+ }
24+ const Figure = styled ( 'figure' ) < AlignProps > ( ( { align } ) => ( {
25+ margin : '1rem 0' ,
26+ textAlign : align ,
27+ width : '100%' ,
28+ } ) ) ;
29+ const FigCaption = styled ( 'figcaption' ) < AlignProps > ( ( { align } ) => ( {
30+ fontSize : '0.9rem' ,
31+ color : '#666' ,
32+ marginTop : '0.5rem' ,
33+ textAlign : align
34+ } ) ) ;
2035
21- const CustomImage : React . FC < ImageComponentProps > = ( {
22- src,
23- alt,
24- caption,
36+ const CustomImage : React . FC < ImageComponentProps > = ( {
37+ src,
38+ alt,
39+ caption,
2540 align = 'left' ,
26- ...props
41+ ...props
2742} ) => {
2843 const [ isZoomed , setIsZoomed ] = useState ( false ) ;
2944 const handleZoomClick = ( ) => {
@@ -32,24 +47,10 @@ const CustomImage: React.FC<ImageComponentProps> = ({
3247 const handleZoomClose = ( ) => {
3348 setIsZoomed ( false ) ;
3449 } ;
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-
50+
5051 return (
5152 < >
52- < figure style = { figureStyle } >
53+ < Figure align = { align } >
5354 < img
5455 src = { src }
5556 alt = { alt || caption || '' }
@@ -65,9 +66,9 @@ const CustomImage: React.FC<ImageComponentProps> = ({
6566 width : '50%'
6667 } }
6768 />
68- { caption && < figcaption style = { captionStyle } > { caption } </ figcaption > }
69- </ figure >
70-
69+ { caption && < FigCaption align = { align } > { caption } </ FigCaption > }
70+ </ Figure >
71+
7172 < Dialog
7273 open = { isZoomed }
7374 onClose = { handleZoomClose }
0 commit comments