Skip to content

Commit db60682

Browse files
committed
feat: Improve image loading and styling with opacity transitions and simplified layout
1 parent a194921 commit db60682

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Image: React.FC<ImageProps> = ({
3939
}, [src]);
4040

4141
return (
42-
<figure className={imageContainer}>
42+
<div className={imageContainer}>
4343
<div
4444
className={imageWrapper({
4545
hasWidth: !!format?.block_width,
@@ -53,20 +53,20 @@ const Image: React.FC<ImageProps> = ({
5353
? '100%'
5454
: `${format.block_width}px`
5555
: '100%',
56+
aspectRatio: format?.block_aspect_ratio
57+
? `${format.block_aspect_ratio}`
58+
: 'auto',
5659
}}
5760
>
5861
{!isLoaded && (
5962
<div
6063
className={placeholder}
6164
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%',
65+
width: format?.block_width
66+
? format.block_width > MAX_WIDTH
67+
? '100%'
68+
: `${format.block_width}px`
69+
: '100%',
7070
aspectRatio: format?.block_aspect_ratio
7171
? `${format.block_aspect_ratio}`
7272
: 'auto',
@@ -104,7 +104,7 @@ const Image: React.FC<ImageProps> = ({
104104
})}
105105
src={src}
106106
alt={alt}
107-
loading={priority ? 'eager' : 'lazy'}
107+
loading="lazy"
108108
onLoad={() => setIsLoaded(true)}
109109
width={format?.block_width}
110110
height={format?.block_height}
@@ -120,7 +120,7 @@ const Image: React.FC<ImageProps> = ({
120120
<MemoizedRichText richTexts={imageCaption} />
121121
</figcaption>
122122
)}
123-
</figure>
123+
</div>
124124
);
125125
};
126126

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)