UNPKG

@wordpress/components

Version:
92 lines (90 loc) 3.29 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/components/src/font-size-picker/font-size-picker-select.tsx var font_size_picker_select_exports = {}; __export(font_size_picker_select_exports, { default: () => font_size_picker_select_default }); module.exports = __toCommonJS(font_size_picker_select_exports); var import_i18n = require("@wordpress/i18n"); var import_element = require("@wordpress/element"); var import_utils = require("./utils"); var import_styles = require("./styles"); var import_jsx_runtime = require("react/jsx-runtime"); var DEFAULT_OPTION = { key: "default", name: (0, import_i18n.__)("Default"), value: void 0 }; var FontSizePickerSelect = (props) => { const { __next40pxDefaultSize, fontSizes, value, size, valueMode = "literal", onChange } = props; const options = [DEFAULT_OPTION, ...fontSizes.map((fontSize) => { const hint = (0, import_utils.generateFontSizeHint)(fontSize); return { key: fontSize.slug, name: fontSize.name || fontSize.slug, value: fontSize.size, hint }; })]; const selectedOption = (0, import_element.useMemo)(() => { var _options$find; if (value === void 0) { return DEFAULT_OPTION; } if (valueMode === "slug") { const optionBySlug = options.find((option) => option.key === value); if (optionBySlug) { return optionBySlug; } } return (_options$find = options.find((option) => option.value === value)) !== null && _options$find !== void 0 ? _options$find : DEFAULT_OPTION; }, [value, valueMode, options]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.StyledCustomSelectControl, { __next40pxDefaultSize, __shouldNotWarnDeprecated36pxSize: true, className: "components-font-size-picker__select", label: (0, import_i18n.__)("Font size"), hideLabelFromVision: true, describedBy: (0, import_i18n.sprintf)( // translators: %s: Currently selected font size. (0, import_i18n.__)("Currently selected font size: %s"), selectedOption.name ), options, value: selectedOption, showSelectedHint: true, onChange: ({ selectedItem }) => { const matchingFontSize = selectedItem.key === "default" ? void 0 : fontSizes.find((fontSize) => fontSize.slug === selectedItem.key); onChange(selectedItem.value, matchingFontSize); }, size }); }; var font_size_picker_select_default = FontSizePickerSelect; //# sourceMappingURL=font-size-picker-select.js.map