@prismicio/react
Version:
React components and hooks to fetch and present Prismic content
29 lines (28 loc) • 1.54 kB
JavaScript
import { jsxs, jsx } from "react/jsx-runtime";
import { isFilled } from "@prismicio/client";
import { PrismicRichText } from "./PrismicRichText.js";
const defaultComponents = {
table: ({ children }) => jsx("table", { children }),
thead: ({ children }) => jsx("thead", { children }),
tbody: ({ children }) => jsx("tbody", { children }),
tr: ({ children }) => jsx("tr", { children }),
th: ({ children }) => jsx("th", { children }),
td: ({ children }) => jsx("td", { children })
};
const PrismicTable = (props) => {
const { field, components, fallback = null } = props;
if (!isFilled.table(field)) {
return fallback;
}
const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components };
return jsxs(Table, { table: field, children: [field.head && jsx(Thead, { head: field.head, children: field.head.rows.map((row) => jsx(TableRow, { row, components }, row.key)) }), jsx(Tbody, { body: field.body, children: field.body.rows.map((row) => jsx(TableRow, { row, components }, row.key)) })] });
};
function TableRow(props) {
const { row, components } = props;
const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components };
return jsx(Tr, { row, children: row.cells.map((cell) => cell.type === "header" ? jsx(Th, { cell, children: jsx(PrismicRichText, { field: cell.content, components }) }, cell.key) : jsx(Td, { cell, children: jsx(PrismicRichText, { field: cell.content, components }) }, cell.key)) });
}
export {
PrismicTable
};
//# sourceMappingURL=PrismicTable.js.map