@wordpress/block-library
Version:
Block library for the WordPress editor.
82 lines (81 loc) • 2.46 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import clsx from "clsx";
import {
RichText,
useBlockProps,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetElementClassName
} from "@wordpress/block-editor";
function save({ attributes }) {
const { hasFixedLayout, head, body, foot, caption } = attributes;
const isEmpty = !head.length && !body.length && !foot.length;
if (isEmpty) {
return null;
}
const colorProps = getColorClassesAndStyles(attributes);
const borderProps = getBorderClassesAndStyles(attributes);
const classes = clsx(colorProps.className, borderProps.className, {
"has-fixed-layout": hasFixedLayout
});
const hasCaption = !RichText.isEmpty(caption);
const Section = ({ type, rows }) => {
if (!rows.length) {
return null;
}
const Tag = `t${type}`;
return /* @__PURE__ */ jsx(Tag, { children: rows.map(({ cells }, rowIndex) => /* @__PURE__ */ jsx("tr", { children: cells.map(
({
content,
tag,
scope,
align,
colspan,
rowspan
}, cellIndex) => {
const cellClasses = clsx({
[`has-text-align-${align}`]: align
});
return /* @__PURE__ */ jsx(
RichText.Content,
{
className: cellClasses ? cellClasses : void 0,
"data-align": align,
tagName: tag,
value: content,
scope: tag === "th" ? scope : void 0,
colSpan: colspan,
rowSpan: rowspan
},
cellIndex
);
}
) }, rowIndex)) });
};
return /* @__PURE__ */ jsxs("figure", { ...useBlockProps.save(), children: [
/* @__PURE__ */ jsxs(
"table",
{
className: classes === "" ? void 0 : classes,
style: { ...colorProps.style, ...borderProps.style },
children: [
/* @__PURE__ */ jsx(Section, { type: "head", rows: head }),
/* @__PURE__ */ jsx(Section, { type: "body", rows: body }),
/* @__PURE__ */ jsx(Section, { type: "foot", rows: foot })
]
}
),
hasCaption && /* @__PURE__ */ jsx(
RichText.Content,
{
tagName: "figcaption",
value: caption,
className: __experimentalGetElementClassName("caption")
}
)
] });
}
export {
save as default
};
//# sourceMappingURL=save.js.map