@wordpress/block-library
Version:
Block library for the WordPress editor.
55 lines (54 loc) • 2.35 kB
JavaScript
import clsx from "clsx";
import { InspectorControls, __experimentalUseColorProps, getColorClassName, useBlockProps } from "@wordpress/block-editor";
import { HorizontalRule } from "@wordpress/components";
import { SelectControl } from "@wordpress/ui";
import { __ } from "@wordpress/i18n";
import useDeprecatedOpacity from "./use-deprecated-opacity.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/separator/edit.jsx
const HTML_ELEMENT_ITEMS = [{
label: __("Default (<hr>)"),
value: "hr"
}, {
label: "<div>",
value: "div"
}];
const HtmlElementControl = ({ tagName = "hr", setAttributes }) => {
const selectedItem = HTML_ELEMENT_ITEMS.find((item) => item.value === tagName) ?? HTML_ELEMENT_ITEMS[0];
return /* @__PURE__ */ jsx(SelectControl, {
label: __("HTML element"),
value: selectedItem,
onValueChange: (item) => setAttributes({ tagName: item?.value ?? "hr" }),
items: HTML_ELEMENT_ITEMS,
description: tagName === "hr" ? __("Only select <hr> if the separator conveys important information and should be announced by screen readers.") : __("The <div> element should only be used if the block is a design element with no semantic meaning.")
});
};
function SeparatorEdit({ attributes, setAttributes }) {
const { backgroundColor, opacity, style, tagName } = attributes;
const colorProps = __experimentalUseColorProps(attributes);
const currentColor = colorProps?.style?.backgroundColor;
const hasCustomColor = !!style?.color?.background;
useDeprecatedOpacity(opacity, currentColor, setAttributes);
const colorClass = getColorClassName("color", backgroundColor);
const className = clsx({
"has-text-color": backgroundColor || currentColor,
[colorClass]: colorClass,
"has-css-opacity": opacity === "css",
"has-alpha-channel-opacity": opacity === "alpha-channel"
}, colorProps.className);
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InspectorControls, {
group: "advanced",
children: /* @__PURE__ */ jsx(HtmlElementControl, {
tagName,
setAttributes
})
}), /* @__PURE__ */ jsx(tagName === "hr" ? HorizontalRule : tagName, { ...useBlockProps({
className,
style: hasCustomColor ? {
color: currentColor,
backgroundColor: currentColor
} : void 0
}) })] });
}
export { SeparatorEdit as default };
//# sourceMappingURL=edit.mjs.map