UNPKG

@wordpress/block-library

Version:
55 lines (54 loc) • 2.35 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_i18n = require("@wordpress/i18n"); let __icons_jsx = require("./icons.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/query-total/edit.jsx function QueryTotalEdit({ attributes, setAttributes }) { const { displayType } = attributes; const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const getButtonPositionIcon = () => { switch (displayType) { case "total-results": return __icons_jsx.resultsFound; case "range-display": return __icons_jsx.displayingResults; } }; const buttonPositionControls = [{ role: "menuitemradio", title: (0, _wordpress_i18n.__)("Total results"), isActive: displayType === "total-results", icon: __icons_jsx.resultsFound, onClick: () => { setAttributes({ displayType: "total-results" }); } }, { role: "menuitemradio", title: (0, _wordpress_i18n.__)("Range display"), isActive: displayType === "range-display", icon: __icons_jsx.displayingResults, onClick: () => { setAttributes({ displayType: "range-display" }); } }]; const controls = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarDropdownMenu, { icon: getButtonPositionIcon(), label: (0, _wordpress_i18n.__)("Change display type"), controls: buttonPositionControls }) }) }); const renderDisplay = () => { if (displayType === "total-results") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: (0, _wordpress_i18n.__)("12 results found") }); if (displayType === "range-display") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: (0, _wordpress_i18n.__)("Displaying 1 – 10 of 12") }); return null; }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { ...blockProps, children: [controls, renderDisplay()] }); } exports.default = QueryTotalEdit; //# sourceMappingURL=edit.cjs.map