Skip to content

Commit c81046b

Browse files
committed
Prevent jumps when aspect ratio is known
1 parent 51d2c02 commit c81046b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/components/asset.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ const Asset: React.FC<{ block: BlockType }> = ({ block }) => {
1313
}
1414

1515
const format = value.format;
16-
const { block_width, block_height, display_source } = format;
16+
const {
17+
block_width,
18+
block_height,
19+
display_source,
20+
block_aspect_ratio
21+
} = format;
1722

1823
const isImage = type === "image";
1924

@@ -37,7 +42,21 @@ const Asset: React.FC<{ block: BlockType }> = ({ block }) => {
3742

3843
if (type === "image") {
3944
const caption = value.properties.caption?.[0][0];
40-
return <img style={style} alt={caption} src={src} />;
45+
if (block_aspect_ratio) {
46+
return (
47+
<div
48+
style={{
49+
...style,
50+
paddingBottom: `${block_aspect_ratio * 100}%`,
51+
position: "relative"
52+
}}
53+
>
54+
<img className="notion-image-inset" alt={caption} src={src} />
55+
</div>
56+
);
57+
} else {
58+
return <img style={style} alt={caption} src={src} />;
59+
}
4160
}
4261

4362
if (type === "video") {

src/styles.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ li {
211211
.notion-spacer:last-child {
212212
display: none;
213213
}
214+
215+
.notion-image-inset {
216+
position: absolute;
217+
left: 0;
218+
top: 0;
219+
right: 0;
220+
bottom: 0;
221+
width: 100%;
222+
}
223+
214224
.notion-image-caption {
215225
padding: 6px 0px;
216226
white-space: pre-wrap;

0 commit comments

Comments
 (0)