UNPKG

@wordpress/block-library

Version:
74 lines (73 loc) • 2.52 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let __icons_jsx = require("./icons.cjs"); let __use_term_count_js = require("./use-term-count.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/term-count/edit.jsx const BRACKET_TYPES = { none: { label: (0, _wordpress_i18n.__)("No brackets"), icon: __icons_jsx.bareNumber }, round: { label: (0, _wordpress_i18n.__)("Round brackets"), icon: __icons_jsx.numberInParenthesis, before: "(", after: ")" }, square: { label: (0, _wordpress_i18n.__)("Square brackets"), icon: __icons_jsx.numberInSquareBrackets, before: "[", after: "]" }, curly: { label: (0, _wordpress_i18n.__)("Curly brackets"), icon: __icons_jsx.numberInCurlyBrackets, before: "{", after: "}" }, angle: { label: (0, _wordpress_i18n.__)("Angle brackets"), icon: __icons_jsx.numberInAngleBrackets, before: "<", after: ">" } }; function TermCountEdit({ attributes, setAttributes, context: { termId, taxonomy } }) { const { bracketType } = attributes; const termCount = (0, __use_term_count_js.useTermCount)(termId, taxonomy)?.termCount || 0; const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const bracketTypeControls = Object.entries(BRACKET_TYPES).map(([type, { label, icon }]) => ({ role: "menuitemradio", title: label, isActive: bracketType === type, icon, onClick: () => { setAttributes({ bracketType: type }); } })); const formatTermCount = (count, type) => { const { before = "", after = "" } = BRACKET_TYPES[type] || {}; return `${before}${count}${after}`; }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, { group: "block", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarDropdownMenu, { icon: BRACKET_TYPES[bracketType]?.icon ?? __icons_jsx.bareNumber, label: (0, _wordpress_i18n.__)("Change bracket type"), controls: bracketTypeControls }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...blockProps, children: formatTermCount(termCount, bracketType) })] }); } exports.default = TermCountEdit; //# sourceMappingURL=edit.cjs.map