UNPKG

@wordpress/global-styles-ui

Version:
213 lines (211 loc) • 8.69 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/global-styles-ui/src/font-sizes/font-size.tsx var font_size_exports = {}; __export(font_size_exports, { default: () => font_size_default }); module.exports = __toCommonJS(font_size_exports); var import_i18n = require("@wordpress/i18n"); var import_components = require("@wordpress/components"); var import_element = require("@wordpress/element"); var import_ui = require("@wordpress/ui"); var import_font_size_preview = __toESM(require("./font-size-preview.cjs")); var import_size_control = require("../size-control/index.cjs"); var import_use_presets = require("../presets/use-presets.cjs"); var import_hooks = require("../hooks.cjs"); var import_preset_edit_header = __toESM(require("../presets/preset-edit-header.cjs")); var import_confirm_delete_dialog = __toESM(require("../presets/dialogs/confirm-delete-dialog.cjs")); var import_rename_dialog = __toESM(require("../presets/dialogs/rename-dialog.cjs")); var import_jsx_runtime = require("react/jsx-runtime"); function FontSize() { const { params, goBack } = (0, import_components.useNavigator)(); const origin = params.origin; const slug = params.slug; const { presets, setPresets } = (0, import_use_presets.usePresets)( "typography.fontSizes", origin ); const [globalFluid] = (0, import_hooks.useSetting)("typography.fluid"); const fontSize = presets.find((s) => s.slug === slug); const [isDeleteOpen, setIsDeleteOpen] = (0, import_element.useState)(false); const [isRenameOpen, setIsRenameOpen] = (0, import_element.useState)(false); (0, import_element.useEffect)(() => { if (!!slug && !fontSize) { goBack(); } }, [slug, fontSize, goBack]); if (!origin || !slug || !fontSize) { return null; } const isFluid = fontSize.fluid !== void 0 ? !!fontSize.fluid : !!globalFluid; const isCustomFluid = typeof fontSize.fluid === "object"; const set = (key, value) => setPresets( presets.map( (p) => p.slug === slug ? { ...fontSize, [key]: value } : p ) ); const handleCustomFluidValues = (value) => { if (value) { set("fluid", { min: fontSize.size, max: fontSize.size }); } else { set("fluid", true); } }; const handleMinChange = (value) => { const fluid = typeof fontSize.fluid === "object" ? fontSize.fluid : {}; set("fluid", { ...fluid, min: value }); }; const handleMaxChange = (value) => { const fluid = typeof fontSize.fluid === "object" ? fontSize.fluid : {}; set("fluid", { ...fluid, max: value }); }; const menuItems = origin === "custom" ? [ { label: (0, import_i18n.__)("Rename"), onClick: () => setIsRenameOpen(true) }, { label: (0, import_i18n.__)("Delete"), onClick: () => setIsDeleteOpen(true) } ] : []; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "md", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_preset_edit_header.default, { title: fontSize.name, description: (0, import_i18n.sprintf)( /* translators: %s: font size preset name. */ (0, import_i18n.__)("Manage the font size %s."), fontSize.name ), menuLabel: (0, import_i18n.__)("Font size options"), menuItems } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalView, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.__experimentalSpacer, { paddingX: 4, marginBottom: 0, paddingBottom: 6, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "md", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexItem, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_font_size_preview.default, { fontSize }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_size_control.SizeControl, { label: (0, import_i18n.__)("Size"), value: !isCustomFluid && fontSize.size ? String(fontSize.size) : "", onChange: (value) => set("size", value), disabled: isCustomFluid } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.ToggleControl, { label: (0, import_i18n.__)("Fluid typography"), help: (0, import_i18n.__)( "Scale the font size dynamically to fit the screen or viewport." ), checked: isFluid, onChange: (value) => set("fluid", value) } ), isFluid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.ToggleControl, { label: (0, import_i18n.__)("Custom fluid values"), help: (0, import_i18n.__)( "Set custom min and max values for the fluid font size." ), checked: isCustomFluid, onChange: handleCustomFluidValues } ), isCustomFluid && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_size_control.SizeControl, { label: (0, import_i18n.__)("Minimum"), value: typeof fontSize.fluid === "object" ? fontSize.fluid?.min : void 0, onChange: handleMinChange } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_size_control.SizeControl, { label: (0, import_i18n.__)("Maximum"), value: typeof fontSize.fluid === "object" ? fontSize.fluid?.max : void 0, onChange: handleMaxChange } ) ] }) ] }) } ) }) ] }), isDeleteOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_confirm_delete_dialog.default, { message: (0, import_i18n.sprintf)( /* translators: %s: Name of the font size preset. */ (0, import_i18n.__)( 'Are you sure you want to delete "%s" font size preset?' ), fontSize.name ), isOpen: isDeleteOpen, toggleOpen: () => setIsDeleteOpen(false), onConfirm: () => { setPresets( presets.filter((p) => p.slug !== slug) ); goBack(); } } ), isRenameOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_rename_dialog.default, { initialName: fontSize.name, placeholder: (0, import_i18n.__)("Font size preset name"), toggleOpen: () => setIsRenameOpen(false), onRename: (name) => setPresets( presets.map( (p) => p.slug === slug ? { ...p, name } : p ) ) } ) ] }); } var font_size_default = FontSize; //# sourceMappingURL=font-size.cjs.map