File tree Expand file tree Collapse file tree 4 files changed +41
-5
lines changed Expand file tree Collapse file tree 4 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 55 ContentValueType ,
66 BlockMapType ,
77 MapPageUrl ,
8- MapImageUrl
8+ MapImageUrl ,
9+ BlockValueTypeKeys ,
10+ CustomComponent
911} from "./types" ;
1012import Asset from "./components/asset" ;
1113import Code from "./components/code" ;
@@ -62,6 +64,7 @@ interface Block {
6264
6365 fullPage ?: boolean ;
6466 hideHeader ?: boolean ;
67+ customComponents ?: Record < BlockValueTypeKeys , CustomComponent > ;
6568}
6669
6770export const Block : React . FC < Block > = props => {
@@ -73,10 +76,17 @@ export const Block: React.FC<Block> = props => {
7376 hideHeader,
7477 blockMap,
7578 mapPageUrl,
76- mapImageUrl
79+ mapImageUrl,
80+ customComponents
7781 } = props ;
7882 const blockValue = block ?. value ;
7983
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+
8090 switch ( blockValue ?. type ) {
8191 case "page" :
8292 if ( level === 0 ) {
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ const Asset: React.FC<{
3434 >
3535 < iframe
3636 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+ }
3840 />
3941 </ div >
4042 ) ;
Original file line number Diff line number Diff line change 11import React from "react" ;
2- import { BlockMapType , MapPageUrl , MapImageUrl } from "./types" ;
2+ import {
3+ BlockMapType ,
4+ MapPageUrl ,
5+ MapImageUrl ,
6+ CustomComponent
7+ } from "./types" ;
38import { Block } from "./block" ;
49import { defaultMapImageUrl , defaultMapPageUrl } from "./utils" ;
510
@@ -12,6 +17,7 @@ export interface NotionRendererProps {
1217
1318 currentId ?: string ;
1419 level ?: number ;
20+ customComponents ?: Record < string , CustomComponent > ;
1521}
1622
1723export const NotionRenderer : React . FC < NotionRendererProps > = ( {
Original file line number Diff line number Diff line change 88 *
99 */
1010
11+ import { FC } from "react" ;
12+
1113/**
1214 * Base properties that all blocks share.
1315 */
@@ -256,6 +258,13 @@ interface TableCollectionType extends BaseValueType {
256258 } ;
257259}
258260
261+ export interface TweetType extends BaseValueType {
262+ type : "tweet" ;
263+ properties : {
264+ source : [ string [ ] ] ;
265+ } ;
266+ }
267+
259268export type CollectionViewType = TableGalleryType | TableCollectionType ;
260269
261270/**
@@ -282,7 +291,10 @@ export type BlockValueType =
282291 | CalloutValueType
283292 | BookmarkValueType
284293 | ToggleValueType
285- | CollectionValueType ;
294+ | CollectionValueType
295+ | TweetType ;
296+
297+ export type BlockValueTypeKeys = Pick < BlockValueType , "type" > [ "type" ] ;
286298
287299export interface BlockType {
288300 role : string ;
@@ -329,3 +341,9 @@ export interface LoadPageChunkData {
329341
330342export type MapPageUrl = ( pageId : string ) => string ;
331343export 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