@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
144 lines (142 loc) • 6.04 kB
JavaScript
;
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-sizes.tsx
var font_sizes_exports = {};
__export(font_sizes_exports, {
default: () => FontSizes
});
module.exports = __toCommonJS(font_sizes_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_ui = require("@wordpress/ui");
var import_screen_header = require("../screen-header.cjs");
var import_preset_group = __toESM(require("../presets/preset-group.cjs"));
var import_use_presets = require("../presets/use-presets.cjs");
var import_hooks = require("../hooks.cjs");
var import_utils = require("../utils.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var hasSameSizeValues = (a, b) => a.map((item) => item.size).join("") === b.map((item) => item.size).join("");
var resetMenu = (onConfirm) => ({
label: (0, import_i18n.__)("Reset font size presets"),
optionsLabel: (0, import_i18n.__)("Font size presets options"),
confirmText: (0, import_i18n.__)(
"Are you sure you want to reset all font size presets to their default values?"
),
confirmButtonText: (0, import_i18n.__)("Reset"),
onConfirm
});
function FontSizes() {
const [defaultEnabled] = (0, import_hooks.useSetting)(
"typography.defaultFontSizes"
);
const theme = (0, import_use_presets.usePresets)("typography.fontSizes", "theme");
const def = (0, import_use_presets.usePresets)("typography.fontSizes", "default");
const custom = (0, import_use_presets.usePresets)("typography.fontSizes", "custom");
const addFontSize = () => {
const index = (0, import_utils.getNewIndexFromPresets)(custom.presets, "custom-");
custom.setPresets([
...custom.presets,
{
/* translators: %d: font size index */
name: (0, import_i18n.sprintf)((0, import_i18n.__)("New Font Size %d"), index),
size: "16px",
slug: `custom-${index}`
}
]);
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "sm", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_screen_header.ScreenHeader,
{
title: (0, import_i18n.__)("Font size presets"),
description: (0, import_i18n.__)(
"Create and edit the presets used for font sizes across the site."
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalView, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalSpacer, { paddingX: 4, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "xl", children: [
!!theme.presets.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_preset_group.default,
{
label: (0, import_i18n.__)("Theme"),
items: theme.presets,
getEditPath: (slug) => `/typography/font-sizes/theme/${slug}`,
menuAction: hasSameSizeValues(
theme.presets,
theme.basePresets
) ? void 0 : resetMenu(
() => theme.setPresets(
theme.basePresets
)
)
}
),
defaultEnabled && !!def.presets.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_preset_group.default,
{
label: (0, import_i18n.__)("Default"),
items: def.presets,
getEditPath: (slug) => `/typography/font-sizes/default/${slug}`,
menuAction: hasSameSizeValues(
def.presets,
def.basePresets
) ? void 0 : resetMenu(
() => def.setPresets(
def.basePresets
)
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_preset_group.default,
{
label: (0, import_i18n.__)("Custom"),
items: custom.presets,
getEditPath: (slug) => `/typography/font-sizes/custom/${slug}`,
addLabel: (0, import_i18n.__)("Add font size"),
onAdd: addFontSize,
menuAction: custom.presets.length > 0 ? {
label: (0, import_i18n.__)(
"Remove font size presets"
),
optionsLabel: (0, import_i18n.__)(
"Font size presets options"
),
confirmText: (0, import_i18n.__)(
"Are you sure you want to remove all custom font size presets?"
),
confirmButtonText: (0, import_i18n.__)("Remove"),
onConfirm: () => custom.setPresets([])
} : void 0
}
)
] }) }) })
] });
}
//# sourceMappingURL=font-sizes.cjs.map