@wordpress/block-library
Version:
Block library for the WordPress editor.
40 lines (39 loc) • 1.86 kB
JavaScript
import { InspectorControls, RichText, useBlockProps } from "@wordpress/block-editor";
import { ToggleControl, __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components";
import { createBlock, getDefaultBlockName } from "@wordpress/blocks";
import { __ } from "@wordpress/i18n";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/read-more/edit.jsx
function ReadMore({ attributes: { content, linkTarget }, setAttributes, insertBlocksAfter }) {
const blockProps = useBlockProps();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(__experimentalToolsPanel, {
label: __("Settings"),
resetAll: () => setAttributes({ linkTarget: "_self" }),
dropdownMenuProps,
children: /* @__PURE__ */ jsx(__experimentalToolsPanelItem, {
label: __("Open in new tab"),
isShownByDefault: true,
hasValue: () => linkTarget !== "_self",
onDeselect: () => setAttributes({ linkTarget: "_self" }),
children: /* @__PURE__ */ jsx(ToggleControl, {
label: __("Open in new tab"),
onChange: (value) => setAttributes({ linkTarget: value ? "_blank" : "_self" }),
checked: linkTarget === "_blank"
})
})
}) }), /* @__PURE__ */ jsx(RichText, {
identifier: "content",
tagName: "a",
"aria-label": __("“Read more” link text"),
placeholder: __("Read more"),
value: content,
onChange: (newValue) => setAttributes({ content: newValue }),
__unstableOnSplitAtEnd: insertBlocksAfter ? () => insertBlocksAfter(createBlock(getDefaultBlockName())) : void 0,
withoutInteractiveFormatting: true,
...blockProps
})] });
}
export { ReadMore as default };
//# sourceMappingURL=edit.mjs.map