Skip to content

Commit c6dc48a

Browse files
authored
Merge pull request #56 from 01-binary/jsx-update
Jsx update
2 parents 4797e6e + 85f04ea commit c6dc48a

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

.changeset/witty-lands-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"notion-to-jsx": patch
3+
---
4+
5+
Column인 경우 Image size 조절

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: 47 additions & 35 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

@@ -39,39 +79,15 @@ const Image: React.FC<ImageProps> = ({
3979
}, [src]);
4080

4181
return (
42-
<figure className={imageContainer}>
82+
<div className={imageContainer}>
4383
<div
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-
}}
87+
style={getImageStyles(format, isColumn)}
5788
>
5889
{!isLoaded && (
59-
<div
60-
className={placeholder}
61-
style={{
62-
width:
63-
format?.block_aspect_ratio && format.block_aspect_ratio < 1
64-
? `${format.block_aspect_ratio * 100}%`
65-
: 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"
@@ -104,23 +120,19 @@ const Image: React.FC<ImageProps> = ({
104120
})}
105121
src={src}
106122
alt={alt}
107-
loading={priority ? 'eager' : 'lazy'}
123+
loading="lazy"
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 && (
119131
<figcaption className={caption}>
120132
<MemoizedRichText richTexts={imageCaption} />
121133
</figcaption>
122134
)}
123-
</figure>
135+
</div>
124136
);
125137
};
126138

packages/notion-to-jsx/src/components/Renderer/components/Image/styles.css.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ export const imageWrapper = recipe({
2323
position: 'relative',
2424
maxWidth: '100%',
2525
width: fallbackVar(imageWidthVar, '100%'),
26-
display: 'flex',
27-
alignItems: 'center',
28-
justifyContent: 'center',
2926
},
3027
variants: {
3128
hasWidth: {
@@ -51,9 +48,12 @@ export const styledImage = recipe({
5148
},
5249
variants: {
5350
loaded: {
54-
true: {},
51+
true: {
52+
opacity: 1,
53+
},
5554
false: {
56-
display: 'none',
55+
opacity: 0,
56+
height: 0,
5757
},
5858
},
5959
hasAspectRatio: {

0 commit comments

Comments
 (0)