UNPKG

@udus/notion-renderer

Version:
32 lines (31 loc) 2 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { RichText } from "../RichText/RichText.js"; export const Table = ({ block }) => { return (_jsx("table", { id: block.id, className: "notion-block notion-table-block", children: _jsx("tbody", { children: block.table.table_rows && block.table.table_rows.map((table_row, index) => { if (block.table.has_row_header && index === 0) { return (_jsx(TableRowRowHeader, { table_row: table_row }, table_row.id)); } if (block.table.has_column_header) { return (_jsx(TableRowColumnHeader, { table_row: table_row }, table_row.id)); } return (_jsx(TableRowNoHeader, { table_row: table_row }, table_row.id)); }) }) })); }; const TableRowRowHeader = ({ table_row }) => { return (_jsx("tr", { id: table_row.id, className: "notion-table-block-row", children: table_row.table_row.cells.map((cell, index) => (_jsx(Th, { cell: cell }, `${index}${cell.map((c) => c.plain_text).join("")}`))) })); }; const TableRowColumnHeader = ({ table_row }) => { return (_jsx("tr", { id: table_row.id, className: "notion-table-block-row", children: table_row.table_row.cells.map((cell, index) => { return index === 0 ? (_jsx(Th, { cell: cell }, `${index}${cell.map((c) => c.plain_text).join("")}`)) : (_jsx(Td, { cell: cell }, `${index}${cell.map((c) => c.plain_text).join("")}`)); }) })); }; const TableRowNoHeader = ({ table_row }) => { return (_jsx("tr", { id: table_row.id, className: "notion_table_row", children: table_row.table_row.cells.map((cell, index) => (_jsx(Td, { cell: cell }, `${index}${cell.map((c) => c.plain_text).join("")}`))) })); }; const Th = ({ cell }) => { return (_jsx("th", { children: _jsx(RichText, { richText: cell }) })); }; const Td = ({ cell }) => { return (_jsx("td", { children: _jsx(RichText, { richText: cell }) })); };