@@ -21,16 +21,56 @@ export interface ImageProps {
21
21
caption ?: RichTextItem [ ] ;
22
22
priority ?: boolean ;
23
23
format ?: ImageFormat ;
24
+ isColumn ?: boolean ;
24
25
}
25
26
26
27
const MAX_WIDTH = 720 ;
27
28
29
+ // 이미지 스타일 유틸리티 함수
30
+ const getImageStyles = ( format ?: ImageFormat , isColumn : boolean = false ) => {
31
+ // width 계산 로직
32
+ const getWidthStyle = ( ) => {
33
+ if (
34
+ ! isColumn &&
35
+ format ?. block_aspect_ratio &&
36
+ format . block_aspect_ratio < 1
37
+ ) {
38
+ return `${ format . block_aspect_ratio * 100 } %` ;
39
+ }
40
+
41
+ if ( format ?. block_width ) {
42
+ return format . block_width > MAX_WIDTH
43
+ ? '100%'
44
+ : `${ format . block_width } px` ;
45
+ }
46
+
47
+ return '100%' ;
48
+ } ;
49
+
50
+ // aspectRatio 계산 로직
51
+ const getAspectRatioStyle = ( ) => {
52
+ return format ?. block_aspect_ratio ? `${ format . block_aspect_ratio } ` : 'auto' ;
53
+ } ;
54
+
55
+ return {
56
+ width : getWidthStyle ( ) ,
57
+ aspectRatio : getAspectRatioStyle ( ) ,
58
+ } ;
59
+ } ;
60
+
61
+ // 이미지 태그에 사용되는 aspectRatio 스타일
62
+ const getImageTagStyle = ( format ?: ImageFormat ) => {
63
+ return format ?. block_aspect_ratio
64
+ ? { aspectRatio : `${ format . block_aspect_ratio } ` }
65
+ : undefined ;
66
+ } ;
67
+
28
68
const Image : React . FC < ImageProps > = ( {
29
69
src,
30
70
alt,
31
71
caption : imageCaption ,
32
- priority = false ,
33
72
format,
73
+ isColumn = false ,
34
74
} ) => {
35
75
const [ isLoaded , setIsLoaded ] = useState ( false ) ;
36
76
@@ -44,34 +84,10 @@ const Image: React.FC<ImageProps> = ({
44
84
className = { imageWrapper ( {
45
85
hasWidth : ! ! format ?. block_width ,
46
86
} ) }
47
- style = { {
48
- width :
49
- format ?. block_aspect_ratio && format . block_aspect_ratio < 1
50
- ? `${ format . block_aspect_ratio * 100 } %`
51
- : format ?. block_width
52
- ? format . block_width > MAX_WIDTH
53
- ? '100%'
54
- : `${ format . block_width } px`
55
- : '100%' ,
56
- aspectRatio : format ?. block_aspect_ratio
57
- ? `${ format . block_aspect_ratio } `
58
- : 'auto' ,
59
- } }
87
+ style = { getImageStyles ( format , isColumn ) }
60
88
>
61
89
{ ! isLoaded && (
62
- < div
63
- className = { placeholder }
64
- style = { {
65
- width : format ?. block_width
66
- ? format . block_width > MAX_WIDTH
67
- ? '100%'
68
- : `${ format . block_width } px`
69
- : '100%' ,
70
- aspectRatio : format ?. block_aspect_ratio
71
- ? `${ format . block_aspect_ratio } `
72
- : 'auto' ,
73
- } }
74
- >
90
+ < div className = { placeholder } style = { getImageStyles ( format , isColumn ) } >
75
91
< svg
76
92
width = "38"
77
93
height = "38"
@@ -108,11 +124,7 @@ const Image: React.FC<ImageProps> = ({
108
124
onLoad = { ( ) => setIsLoaded ( true ) }
109
125
width = { format ?. block_width }
110
126
height = { format ?. block_height }
111
- style = {
112
- format ?. block_aspect_ratio
113
- ? { aspectRatio : `${ format . block_aspect_ratio } ` }
114
- : undefined
115
- }
127
+ style = { getImageTagStyle ( format ) }
116
128
/>
117
129
</ div >
118
130
{ imageCaption && imageCaption . length > 0 && (
0 commit comments