1
1
import React , { useState } from 'react' ;
2
2
import { Dialog } from '../../base' ;
3
+ import { styled } from '../../theme' ;
3
4
4
5
interface ImageComponentProps {
5
6
src : string ;
@@ -17,13 +18,27 @@ interface ImageComponentProps {
17
18
align ?: 'left' | 'center' | 'right' ;
18
19
onClick ?: ( event : React . MouseEvent < HTMLImageElement , MouseEvent > ) => void ;
19
20
}
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
+ } ) ) ;
20
35
21
- const CustomImage : React . FC < ImageComponentProps > = ( {
22
- src,
23
- alt,
24
- caption,
36
+ const CustomImage : React . FC < ImageComponentProps > = ( {
37
+ src,
38
+ alt,
39
+ caption,
25
40
align = 'left' ,
26
- ...props
41
+ ...props
27
42
} ) => {
28
43
const [ isZoomed , setIsZoomed ] = useState ( false ) ;
29
44
const handleZoomClick = ( ) => {
@@ -32,24 +47,10 @@ const CustomImage: React.FC<ImageComponentProps> = ({
32
47
const handleZoomClose = ( ) => {
33
48
setIsZoomed ( false ) ;
34
49
} ;
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
+
50
51
return (
51
52
< >
52
- < figure style = { figureStyle } >
53
+ < Figure align = { align } >
53
54
< img
54
55
src = { src }
55
56
alt = { alt || caption || '' }
@@ -65,9 +66,9 @@ const CustomImage: React.FC<ImageComponentProps> = ({
65
66
width : '50%'
66
67
} }
67
68
/>
68
- { caption && < figcaption style = { captionStyle } > { caption } </ figcaption > }
69
- </ figure >
70
-
69
+ { caption && < FigCaption align = { align } > { caption } </ FigCaption > }
70
+ </ Figure >
71
+
71
72
< Dialog
72
73
open = { isZoomed }
73
74
onClose = { handleZoomClose }
0 commit comments