UNPKG

@wordpress/global-styles-ui

Version:
91 lines (90 loc) • 2.98 kB
// packages/global-styles-ui/src/shadows-panel.tsx import { __, sprintf } from "@wordpress/i18n"; import { Stack } from "@wordpress/ui"; import { ScreenHeader } from "./screen-header.mjs"; import { ScreenBody } from "./screen-body.mjs"; import PresetGroup from "./presets/preset-group.mjs"; import { usePresets } from "./presets/use-presets.mjs"; import { useSetting } from "./hooks.mjs"; import { getNewIndexFromPresets } from "./utils.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; var defaultShadow = "6px 6px 9px rgba(0, 0, 0, 0.2)"; function ShadowsPanel() { const [defaultEnabled] = useSetting("shadow.defaultPresets"); const def = usePresets("shadow.presets", "default"); const theme = usePresets("shadow.presets", "theme"); const custom = usePresets("shadow.presets", "custom"); const addCustomShadow = () => { const index = getNewIndexFromPresets(custom.presets, "shadow-"); custom.setPresets([ ...custom.presets, { /* translators: %d: is an index for a preset */ name: sprintf(__("Shadow %d"), index), shadow: defaultShadow, slug: `shadow-${index}` } ]); }; return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx( ScreenHeader, { title: __("Shadows"), description: __( "Manage and create shadow styles for use across the site." ) } ), /* @__PURE__ */ jsx(ScreenBody, { children: /* @__PURE__ */ jsxs( Stack, { direction: "column", className: "global-styles-ui__shadows-panel", gap: "xl", children: [ defaultEnabled && /* @__PURE__ */ jsx( PresetGroup, { label: __("Default"), items: def.presets, getEditPath: (slug) => `/shadows/edit/default/${slug}` } ), theme.presets.length > 0 && /* @__PURE__ */ jsx( PresetGroup, { label: __("Theme"), items: theme.presets, getEditPath: (slug) => `/shadows/edit/theme/${slug}` } ), /* @__PURE__ */ jsx( PresetGroup, { label: __("Custom"), items: custom.presets, getEditPath: (slug) => `/shadows/edit/custom/${slug}`, addLabel: __("Add shadow"), onAdd: addCustomShadow, menuAction: { label: __("Remove all custom shadows"), optionsLabel: __("Shadow options"), confirmText: __( "Are you sure you want to remove all custom shadows?" ), confirmButtonText: __("Remove"), onConfirm: () => custom.setPresets([]) } } ) ] } ) }) ] }); } export { ShadowsPanel as default, defaultShadow }; //# sourceMappingURL=shadows-panel.mjs.map