@udus/notion-renderer
Version:

14 lines (13 loc) • 883 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useBlocks } from "../hooks.js";
export const TableOfContents = ({ block }) => {
const blocks = useBlocks();
const headings = blocks?.filter((block) => block !== null &&
(block.type === "heading_1" ||
block.type === "heading_2" ||
block.type === "heading_3"));
return (_jsx("div", { id: block.id, className: `notion-block notion-table-of-contents notion-color-${block.table_of_contents.color}`, children: headings &&
headings.map((heading) => {
return (_jsx("div", { className: "notion-table-of-contents-item", children: _jsx("div", { className: `notion-table-of-contents-item-${heading.type}`, children: _jsx("a", { href: `#${heading.id}`, children: heading[heading.type].rich_text.map((t) => t.plain_text) }) }) }, heading.id));
}) }));
};