File tree 4 files changed +41
-5
lines changed 4 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 5
5
ContentValueType ,
6
6
BlockMapType ,
7
7
MapPageUrl ,
8
- MapImageUrl
8
+ MapImageUrl ,
9
+ BlockValueTypeKeys ,
10
+ CustomComponent
9
11
} from "./types" ;
10
12
import Asset from "./components/asset" ;
11
13
import Code from "./components/code" ;
@@ -62,6 +64,7 @@ interface Block {
62
64
63
65
fullPage ?: boolean ;
64
66
hideHeader ?: boolean ;
67
+ customComponents ?: Record < BlockValueTypeKeys , CustomComponent > ;
65
68
}
66
69
67
70
export const Block : React . FC < Block > = props => {
@@ -73,10 +76,17 @@ export const Block: React.FC<Block> = props => {
73
76
hideHeader,
74
77
blockMap,
75
78
mapPageUrl,
76
- mapImageUrl
79
+ mapImageUrl,
80
+ customComponents
77
81
} = props ;
78
82
const blockValue = block ?. value ;
79
83
84
+ // render a custom component first if passed.
85
+ if ( customComponents && customComponents [ blockValue ?. type ] ) {
86
+ const CustomComponent = customComponents [ blockValue ?. type ] as any ;
87
+ return < CustomComponent blockValue = { blockValue } /> ;
88
+ }
89
+
80
90
switch ( blockValue ?. type ) {
81
91
case "page" :
82
92
if ( level === 0 ) {
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ const Asset: React.FC<{
34
34
>
35
35
< iframe
36
36
className = "notion-image-inset"
37
- src = { type === "figma" ? value . properties . source [ 0 ] [ 0 ] : display_source }
37
+ src = {
38
+ type === "figma" ? value . properties . source [ 0 ] [ 0 ] : display_source
39
+ }
38
40
/>
39
41
</ div >
40
42
) ;
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
- import { BlockMapType , MapPageUrl , MapImageUrl } from "./types" ;
2
+ import {
3
+ BlockMapType ,
4
+ MapPageUrl ,
5
+ MapImageUrl ,
6
+ CustomComponent
7
+ } from "./types" ;
3
8
import { Block } from "./block" ;
4
9
import { defaultMapImageUrl , defaultMapPageUrl } from "./utils" ;
5
10
@@ -12,6 +17,7 @@ export interface NotionRendererProps {
12
17
13
18
currentId ?: string ;
14
19
level ?: number ;
20
+ customComponents ?: Record < string , CustomComponent > ;
15
21
}
16
22
17
23
export const NotionRenderer : React . FC < NotionRendererProps > = ( {
Original file line number Diff line number Diff line change 8
8
*
9
9
*/
10
10
11
+ import { FC } from "react" ;
12
+
11
13
/**
12
14
* Base properties that all blocks share.
13
15
*/
@@ -256,6 +258,13 @@ interface TableCollectionType extends BaseValueType {
256
258
} ;
257
259
}
258
260
261
+ export interface TweetType extends BaseValueType {
262
+ type : "tweet" ;
263
+ properties : {
264
+ source : [ string [ ] ] ;
265
+ } ;
266
+ }
267
+
259
268
export type CollectionViewType = TableGalleryType | TableCollectionType ;
260
269
261
270
/**
@@ -282,7 +291,10 @@ export type BlockValueType =
282
291
| CalloutValueType
283
292
| BookmarkValueType
284
293
| ToggleValueType
285
- | CollectionValueType ;
294
+ | CollectionValueType
295
+ | TweetType ;
296
+
297
+ export type BlockValueTypeKeys = Pick < BlockValueType , "type" > [ "type" ] ;
286
298
287
299
export interface BlockType {
288
300
role : string ;
@@ -329,3 +341,9 @@ export interface LoadPageChunkData {
329
341
330
342
export type MapPageUrl = ( pageId : string ) => string ;
331
343
export type MapImageUrl = ( image : string ) => string ;
344
+
345
+ export interface CustomComponentProps {
346
+ blockValue : BlockValueType ;
347
+ }
348
+
349
+ export type CustomComponent = FC < CustomComponentProps > ;
You can’t perform that action at this time.
0 commit comments