UNPKG

@wordpress/block-library

Version:
88 lines (87 loc) • 2.06 kB
// packages/block-library/src/gallery/order-controls.tsx import { __ } from "@wordpress/i18n"; import { SelectControl as WCSelectControl } from "@wordpress/components"; import { ORDER_OPTIONS, RANDOM_OPTION, RANDOM_ORDER, parseOrderValue, toOrderValue } from "./order-options.mjs"; import { jsx } from "react/jsx-runtime"; function getOrderHelp(isRandom) { return isRandom ? __("Images are shown in a random order each time the page loads.") : void 0; } var SOURCE_ORDER_OPTIONS = [...ORDER_OPTIONS, RANDOM_OPTION]; function SourceOrderControl({ order, isRandom, onChange, onSelectRandom }) { return /* @__PURE__ */ jsx( WCSelectControl, { label: __("Order by"), value: isRandom ? RANDOM_ORDER : toOrderValue(order), options: SOURCE_ORDER_OPTIONS, help: getOrderHelp(isRandom), onChange: (value) => { if (value === RANDOM_ORDER) { onSelectRandom(); return; } onChange(parseOrderValue(value)); } } ); } var CUSTOM_ORDER = "custom"; function SortImagesControl({ currentOrder, isRandom, canSort, onSort, onSelectCustom, onSelectRandom }) { const options = [ { label: __("Custom"), value: CUSTOM_ORDER, disabled: !isRandom }, ...ORDER_OPTIONS.map((option) => ({ ...option, disabled: !canSort })), RANDOM_OPTION ]; let value = CUSTOM_ORDER; if (isRandom) { value = RANDOM_ORDER; } else if (currentOrder) { value = toOrderValue(currentOrder); } return /* @__PURE__ */ jsx( WCSelectControl, { label: __("Order by"), value, options, help: getOrderHelp(isRandom), onChange: (nextValue) => { if (nextValue === RANDOM_ORDER) { onSelectRandom(); return; } if (nextValue === CUSTOM_ORDER) { onSelectCustom(); return; } onSort(parseOrderValue(nextValue)); } } ); } export { SortImagesControl, SourceOrderControl }; //# sourceMappingURL=order-controls.mjs.map