-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathrenderer.tsx
64 lines (59 loc) · 1.46 KB
/
renderer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from "react";
import {
BlockMapType,
MapPageUrl,
MapImageUrl,
CustomBlockComponents,
CustomDecoratorComponents
} from "./types";
import { Block } from "./block";
import { defaultMapImageUrl, defaultMapPageUrl } from "./utils";
export interface NotionRendererProps {
blockMap: BlockMapType;
fullPage?: boolean;
hideHeader?: boolean;
mapPageUrl?: MapPageUrl;
mapImageUrl?: MapImageUrl;
currentId?: string;
level?: number;
customBlockComponents?: CustomBlockComponents;
customDecoratorComponents?: CustomDecoratorComponents;
}
export const NotionRenderer: React.FC<NotionRendererProps> = ({
level = 0,
currentId,
mapPageUrl = defaultMapPageUrl,
mapImageUrl = defaultMapImageUrl,
...props
}) => {
const { blockMap } = props;
const id = currentId || Object.keys(blockMap)[0];
const currentBlock = blockMap[id];
if (!currentBlock) {
if (process.env.NODE_ENV !== "production") {
console.warn("error rendering block", currentId);
}
return null;
}
return (
<Block
key={id}
level={level}
block={currentBlock}
mapPageUrl={mapPageUrl}
mapImageUrl={mapImageUrl}
{...props}
>
{currentBlock?.value?.content?.map(contentId => (
<NotionRenderer
key={contentId}
currentId={contentId}
level={level + 1}
mapPageUrl={mapPageUrl}
mapImageUrl={mapImageUrl}
{...props}
/>
))}
</Block>
);
};