@wordpress/block-library
Version:
Block library for the WordPress editor.
42 lines (41 loc) • 1.68 kB
JavaScript
import { Dropdown, ToolbarButton, __experimentalDropdownContentWrapper } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { useSelect } from "@wordpress/data";
import { BlockControls, store } from "@wordpress/block-editor";
import PatternSelection, { useBlockPatterns } from "./pattern-selection.mjs";
import { unlock } from "../../lock-unlock.mjs";
import { jsx } from "react/jsx-runtime";
// packages/block-library/src/query/edit/query-toolbar.jsx
function PatternPicker({ clientId, attributes, hasInnerBlocks }) {
if (!useBlockPatterns(clientId, attributes).length) return null;
const buttonLabel = hasInnerBlocks ? __("Change design") : __("Choose pattern");
return /* @__PURE__ */ jsx(BlockControls, {
group: "other",
children: /* @__PURE__ */ jsx(__experimentalDropdownContentWrapper, { children: /* @__PURE__ */ jsx(Dropdown, {
contentClassName: "block-editor-block-settings-menu__popover",
focusOnMount: "firstElement",
expandOnMobile: true,
renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ jsx(ToolbarButton, {
"aria-haspopup": "true",
"aria-expanded": isOpen,
onClick: onToggle,
children: buttonLabel
}),
renderContent: () => /* @__PURE__ */ jsx(PatternSelection, {
clientId,
attributes,
showSearch: false,
showTitlesAsTooltip: true
})
}) })
});
}
function QueryToolbar(props) {
if (useSelect((select) => {
const { isLockedBlock } = unlock(select(store));
return isLockedBlock(props.clientId);
}, [props.clientId])) return null;
return /* @__PURE__ */ jsx(PatternPicker, { ...props });
}
export { QueryToolbar as default };
//# sourceMappingURL=query-toolbar.mjs.map