UNPKG

@wordpress/block-library

Version:
51 lines (50 loc) • 2.06 kB
import { __ } from "@wordpress/i18n"; import { InspectorControls, store, useBlockProps, useInnerBlocksProps } from "@wordpress/block-editor"; import { useSelect } from "@wordpress/data"; import { ToggleControl, __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components"; import clsx from "clsx"; import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/accordion-item/edit.jsx function Edit({ attributes, clientId, setAttributes, isSelected: isSingleSelected }) { const { openByDefault } = attributes; const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const { isSelected } = useSelect((select) => { if (isSingleSelected || openByDefault) return { isSelected: true }; return { isSelected: select(store).hasSelectedInnerBlock(clientId, true) }; }, [ clientId, isSingleSelected, openByDefault ]); const blockProps = useBlockProps({ className: clsx({ "is-open": openByDefault || isSelected }) }); const innerBlocksProps = useInnerBlocksProps(blockProps, { templateLock: "all", directInsert: true }); return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(__experimentalToolsPanel, { label: __("Settings"), resetAll: () => { setAttributes({ openByDefault: false }); }, dropdownMenuProps, children: /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Open by default"), isShownByDefault: true, hasValue: () => !!openByDefault, onDeselect: () => { setAttributes({ openByDefault: false }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Open by default"), onChange: (value) => { setAttributes({ openByDefault: value }); }, checked: openByDefault, help: __("Accordion content will be displayed by default.") }) }) }) }, "setting"), /* @__PURE__ */ jsx("div", { ...innerBlocksProps })] }); } export { Edit as default }; //# sourceMappingURL=edit.mjs.map