Skip to content

Commit a0a191b

Browse files
committed
Merge branch 'master' of github.com:splitbee/react-notion
2 parents 801ac76 + 563a115 commit a0a191b

File tree

4 files changed

+144
-2
lines changed

4 files changed

+144
-2
lines changed

src/block.tsx

+43-1
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,14 +172,55 @@ 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">
178183
{renderChildText(blockValue.properties.title)}
179184
</div>
180185
</div>
181186
);
187+
case "bookmark":
188+
return (
189+
<div className="notion-row">
190+
<a
191+
target="_blank"
192+
rel="noopener noreferrer"
193+
className={classNames(
194+
"notion-bookmark",
195+
blockValue.format.block_color &&
196+
`notion-${blockValue.format.block_color}`
197+
)}
198+
href={blockValue.properties.link[0][0]}
199+
>
200+
<div>
201+
<div className="notion-bookmark-title">
202+
{renderChildText(blockValue.properties.title)}
203+
</div>
204+
<div className="notion-bookmark-description">
205+
{renderChildText(blockValue.properties.description)}
206+
</div>
207+
<div className="notion-bookmark-link">
208+
<img
209+
src={blockValue.format.bookmark_icon}
210+
alt={getTextContent(blockValue.properties.title)}
211+
/>
212+
<div>{renderChildText(blockValue.properties.link)}</div>
213+
</div>
214+
</div>
215+
<div className="notion-bookmark-image">
216+
<img
217+
src={blockValue.format.bookmark_cover}
218+
alt={getTextContent(blockValue.properties.title)}
219+
/>
220+
</div>
221+
</a>
222+
</div>
223+
);
182224
default:
183225
if (process.env.NODE_ENV !== "production") {
184226
console.log("Unsupported type " + block?.value?.type);

src/styles.css

+77
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,84 @@ h3 {
245245
display: flex;
246246
}
247247

248+
.notion-bookmark {
249+
margin: 4px 0;
250+
text-decoration: none;
251+
border: 1px solid rgba(55, 53, 47, 0.16);
252+
border-radius: 3px;
253+
display: flex;
254+
overflow: hidden;
255+
user-select: none;
256+
}
257+
258+
.notion-bookmark > div:first-child {
259+
flex: 4 1 180px;
260+
padding: 12px 14px 14px;
261+
overflow: hidden;
262+
text-align: left;
263+
color: rgb(55, 53, 47);
264+
}
265+
266+
.notion-bookmark-title {
267+
font-size: 14px;
268+
line-height: 20px;
269+
white-space: nowrap;
270+
overflow: hidden;
271+
text-overflow: ellipsis;
272+
min-height: 24px;
273+
margin-bottom: 2px;
274+
}
275+
276+
.notion-bookmark-description {
277+
font-size: 12px;
278+
line-height: 16px;
279+
opacity: 0.6;
280+
height: 32px;
281+
overflow: hidden;
282+
}
283+
284+
.notion-bookmark-link {
285+
display: flex;
286+
margin-top: 6px;
287+
}
288+
289+
.notion-bookmark-link > img {
290+
width: 16px;
291+
height: 16px;
292+
min-width: 16px;
293+
margin-right: 6px;
294+
}
295+
296+
.notion-bookmark-link > div {
297+
font-size: 12px;
298+
line-height: 16px;
299+
color: rgb(55, 53, 47);
300+
white-space: nowrap;
301+
overflow: hidden;
302+
text-overflow: ellipsis;
303+
}
304+
305+
.notion-bookmark-image {
306+
flex: 1 1 180px;
307+
position: relative;
308+
}
309+
310+
.notion-bookmark-image img {
311+
object-fit: cover;
312+
width: 100%;
313+
height: 100%;
314+
position: absolute;
315+
}
316+
317+
.notion-column .notion-bookmark-image {
318+
display: none;
319+
}
320+
248321
@media (max-width: 640px) {
322+
.notion-bookmark-image {
323+
display: none;
324+
}
325+
249326
.notion-row {
250327
flex-direction: column;
251328
}

src/types.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ export interface BaseTextValueType extends BaseValueType {
106106
};
107107
}
108108

109+
interface BookmarkValueType extends BaseValueType {
110+
type: "bookmark";
111+
properties: {
112+
link: DecorationType[];
113+
title: DecorationType[];
114+
description: DecorationType[];
115+
};
116+
format: {
117+
block_color?: string;
118+
bookmark_icon: string;
119+
bookmark_cover: string;
120+
};
121+
}
122+
109123
interface TextValueType extends BaseTextValueType {
110124
type: "text";
111125
}
@@ -223,7 +237,8 @@ export type BlockValueType =
223237
| ImageValueType
224238
| VideoValueType
225239
| EmbedValueType
226-
| CalloutValueType;
240+
| CalloutValueType
241+
| BookmarkValueType;
227242

228243
export interface BlockType {
229244
role: string;

src/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DecorationType } from "./types";
2+
3+
export const classNames = (...classes: Array<string | undefined | false>) =>
4+
classes.filter(a => !!a).join(" ");
5+
6+
export const getTextContent = (text: DecorationType[]) => {
7+
return text.reduce((prev, current) => prev + current[0], "");
8+
};

0 commit comments

Comments
 (0)