Skip to content

Commit 7f98c27

Browse files
committed
feat: Column인 경우 Image size 조절
1 parent db60682 commit 7f98c27

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

packages/notion-to-jsx/src/components/Renderer/components/Block/BlockRenderer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ export interface Props {
1717
block: any;
1818
onFocus?: () => void;
1919
index: number;
20+
isColumn?: boolean;
2021
}
2122

22-
const BlockRenderer: React.FC<Props> = ({ block, onFocus, index }) => {
23+
const BlockRenderer: React.FC<Props> = ({
24+
block,
25+
onFocus,
26+
index,
27+
isColumn = false,
28+
}) => {
2329
if (!block) return null;
2430

2531
const blockProps = {
@@ -79,6 +85,7 @@ const BlockRenderer: React.FC<Props> = ({ block, onFocus, index }) => {
7985
alt={block.image.caption?.[0]?.plain_text || ''}
8086
caption={block.image.caption}
8187
format={block.image.format}
88+
isColumn={isColumn}
8289
/>
8390
</figure>
8491
);

packages/notion-to-jsx/src/components/Renderer/components/Column/Column.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Column: React.FC<ColumnProps> = ({ block, onFocus }) => {
1818
block={childBlock}
1919
onFocus={onFocus}
2020
index={index}
21+
isColumn
2122
/>
2223
))}
2324
</div>

packages/notion-to-jsx/src/components/Renderer/components/Image/Image.tsx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,56 @@ export interface ImageProps {
2121
caption?: RichTextItem[];
2222
priority?: boolean;
2323
format?: ImageFormat;
24+
isColumn?: boolean;
2425
}
2526

2627
const MAX_WIDTH = 720;
2728

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+
2868
const Image: React.FC<ImageProps> = ({
2969
src,
3070
alt,
3171
caption: imageCaption,
32-
priority = false,
3372
format,
73+
isColumn = false,
3474
}) => {
3575
const [isLoaded, setIsLoaded] = useState(false);
3676

@@ -44,34 +84,10 @@ const Image: React.FC<ImageProps> = ({
4484
className={imageWrapper({
4585
hasWidth: !!format?.block_width,
4686
})}
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)}
6088
>
6189
{!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)}>
7591
<svg
7692
width="38"
7793
height="38"
@@ -108,11 +124,7 @@ const Image: React.FC<ImageProps> = ({
108124
onLoad={() => setIsLoaded(true)}
109125
width={format?.block_width}
110126
height={format?.block_height}
111-
style={
112-
format?.block_aspect_ratio
113-
? { aspectRatio: `${format.block_aspect_ratio}` }
114-
: undefined
115-
}
127+
style={getImageTagStyle(format)}
116128
/>
117129
</div>
118130
{imageCaption && imageCaption.length > 0 && (

0 commit comments

Comments
 (0)