@wordpress/block-library
Version:
Block library for the WordPress editor.
52 lines (51 loc) • 2.41 kB
JavaScript
import { __ } from "@wordpress/i18n";
import { InspectorControls, useBlockProps } from "@wordpress/block-editor";
import { RangeControl, __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/query-pagination-numbers/edit.jsx
const createPaginationItem = (content, Tag = "a", extraClass = "") => /* @__PURE__ */ jsx(Tag, {
className: `page-numbers ${extraClass}`,
children: content
}, content);
const previewPaginationNumbers = (midSize) => {
const paginationItems = [];
for (let i = 1; i <= midSize; i++) paginationItems.push(createPaginationItem(i));
paginationItems.push(createPaginationItem(midSize + 1, "span", "current"));
for (let i = 1; i <= midSize; i++) paginationItems.push(createPaginationItem(midSize + 1 + i));
paginationItems.push(createPaginationItem("...", "span", "dots"));
paginationItems.push(createPaginationItem(midSize * 2 + 3));
return /* @__PURE__ */ jsx(Fragment, { children: paginationItems });
};
function QueryPaginationNumbersEdit({ attributes, setAttributes }) {
const { midSize } = attributes;
const paginationNumbers = previewPaginationNumbers(parseInt(midSize, 10));
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(__experimentalToolsPanel, {
label: __("Settings"),
resetAll: () => setAttributes({ midSize: 2 }),
dropdownMenuProps,
children: /* @__PURE__ */ jsx(__experimentalToolsPanelItem, {
label: __("Number of links"),
hasValue: () => midSize !== 2,
onDeselect: () => setAttributes({ midSize: 2 }),
isShownByDefault: true,
children: /* @__PURE__ */ jsx(RangeControl, {
label: __("Number of links"),
help: __("Specify how many links can appear before and after the current page number. Links to the first, current and last page are always visible."),
value: midSize,
onChange: (value) => {
setAttributes({ midSize: parseInt(value, 10) });
},
min: 0,
max: 5,
withInputField: false
})
})
}) }), /* @__PURE__ */ jsx("div", {
...useBlockProps(),
children: paginationNumbers
})] });
}
export { QueryPaginationNumbersEdit as default };
//# sourceMappingURL=edit.mjs.map