Skip to content

Commit d57316d

Browse files
committed
Improve bookmark styling
- Hide image when inside column - Add support for custom background colors - Add alt tags to images
1 parent ed720b1 commit d57316d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/block.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22
import { DecorationType, BlockType, ContentValueType } from "./types";
33
import Asset from "./components/asset";
44
import Code from "./components/code";
5+
import { classNames, getTextContent } from "./utils";
56

67
export const renderChildText = (properties: DecorationType[]) => {
78
return properties.map(([text, decorations], i) => {
@@ -171,7 +172,11 @@ export const Block: React.FC<Block> = props => {
171172
case "callout":
172173
return (
173174
<div
174-
className={`notion-callout notion-${blockValue.format.block_color}_co`}
175+
className={classNames(
176+
"notion-callout",
177+
blockValue.format.block_color &&
178+
`notion-${blockValue.format.block_color}_co`
179+
)}
175180
>
176181
<div>{blockValue.format.page_icon}</div>
177182
<div className="notion-callout-text">
@@ -185,7 +190,11 @@ export const Block: React.FC<Block> = props => {
185190
<a
186191
target="_blank"
187192
rel="noopener noreferrer"
188-
className="notion-bookmark"
193+
className={classNames(
194+
"notion-bookmark",
195+
blockValue.format.block_color &&
196+
`notion-${blockValue.format.block_color}`
197+
)}
189198
href={blockValue.properties.link[0][0]}
190199
>
191200
<div>
@@ -196,12 +205,18 @@ export const Block: React.FC<Block> = props => {
196205
{renderChildText(blockValue.properties.description)}
197206
</div>
198207
<div className="notion-bookmark-link">
199-
<img src={blockValue.format.bookmark_icon} />
208+
<img
209+
src={blockValue.format.bookmark_icon}
210+
alt={getTextContent(blockValue.properties.title)}
211+
/>
200212
<div>{renderChildText(blockValue.properties.link)}</div>
201213
</div>
202214
</div>
203-
<div>
204-
<img src={blockValue.format.bookmark_cover} />
215+
<div className="notion-bookmark-image">
216+
<img
217+
src={blockValue.format.bookmark_cover}
218+
alt={getTextContent(blockValue.properties.title)}
219+
/>
205220
</div>
206221
</a>
207222
</div>

src/styles.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ h3 {
246246
}
247247

248248
.notion-bookmark {
249+
margin: 4px 0;
249250
text-decoration: none;
250251
border: 1px solid rgba(55, 53, 47, 0.16);
251252
border-radius: 3px;
@@ -301,20 +302,24 @@ h3 {
301302
text-overflow: ellipsis;
302303
}
303304

304-
.notion-bookmark > div:last-child {
305+
.notion-bookmark-image {
305306
flex: 1 1 180px;
306307
position: relative;
307308
}
308309

309-
.notion-bookmark > div:last-child img {
310+
.notion-bookmark-image img {
310311
object-fit: cover;
311312
width: 100%;
312313
height: 100%;
313314
position: absolute;
314315
}
315316

317+
.notion-column .notion-bookmark-image {
318+
display: none;
319+
}
320+
316321
@media (max-width: 640px) {
317-
.notion-bookmark > div:last-child {
322+
.notion-bookmark-image {
318323
display: none;
319324
}
320325

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ interface BookmarkValueType extends BaseValueType {
114114
description: DecorationType[];
115115
};
116116
format: {
117+
block_color?: string;
117118
bookmark_icon: string;
118119
bookmark_cover: string;
119120
};

0 commit comments

Comments
 (0)