@wordpress/block-library
Version:
Block library for the WordPress editor.
56 lines (55 loc) • 1.95 kB
JavaScript
import { __, sprintf } from "@wordpress/i18n";
import { PanelBody, RangeControl } from "@wordpress/components";
import { BlockAlignmentToolbar, BlockControls, InspectorControls, RichText, useBlockProps } from "@wordpress/block-editor";
import deprecated from "@wordpress/deprecated";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/text-columns/edit.jsx
function TextColumnsEdit({ attributes, setAttributes }) {
const { width, content, columns } = attributes;
deprecated("The Text Columns block", {
since: "5.3",
alternative: "the Columns block"
});
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(BlockAlignmentToolbar, {
value: width,
onChange: (nextWidth) => setAttributes({ width: nextWidth }),
controls: [
"center",
"wide",
"full"
]
}) }),
/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(PanelBody, { children: /* @__PURE__ */ jsx(RangeControl, {
label: __("Columns"),
value: columns,
onChange: (value) => setAttributes({ columns: value }),
min: 2,
max: 4,
required: true
}) }) }),
/* @__PURE__ */ jsx("div", {
...useBlockProps({ className: `align${width} columns-${columns}` }),
children: Array.from({ length: columns }).map((_, index) => {
return /* @__PURE__ */ jsx("div", {
className: "wp-block-column",
children: /* @__PURE__ */ jsx(RichText, {
tagName: "p",
value: content?.[index]?.children,
onChange: (nextContent) => {
setAttributes({ content: [
...content.slice(0, index),
{ children: nextContent },
...content.slice(index + 1)
] });
},
"aria-label": sprintf(__("Column %d text"), index + 1),
placeholder: __("New Column")
})
}, `column-${index}`);
})
})
] });
}
export { TextColumnsEdit as default };
//# sourceMappingURL=edit.mjs.map