@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
64 lines (63 loc) • 2.7 kB
JavaScript
import { ColorIndicator, __experimentalItemGroup } from "@wordpress/components";
import { __, isRTL } from "@wordpress/i18n";
import { Icon, chevronLeft, chevronRight } from "@wordpress/icons";
import { useMemo } from "@wordpress/element";
import { Stack } from "@wordpress/ui";
import { Subtitle } from "./subtitle.mjs";
import { NavigationButtonAsItem } from "./navigation-button.mjs";
import ColorIndicatorWrapper from "./color-indicator-wrapper.mjs";
import { useSetting } from "./hooks.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/global-styles-ui/src/palette.tsx
const EMPTY_COLORS = [];
function Palette({ name }) {
const [customColors] = useSetting("color.palette.custom");
const [themeColors] = useSetting("color.palette.theme");
const [defaultColors] = useSetting("color.palette.default");
const [defaultPaletteEnabled] = useSetting("color.defaultPalette", name);
const safeCustomColors = customColors || EMPTY_COLORS;
const safeThemeColors = themeColors || EMPTY_COLORS;
const safeDefaultColors = defaultColors || EMPTY_COLORS;
const safeDefaultPaletteEnabled = defaultPaletteEnabled ?? true;
const colors = useMemo(() => [
...safeCustomColors,
...safeThemeColors,
...safeDefaultColors && safeDefaultPaletteEnabled ? safeDefaultColors : EMPTY_COLORS
], [
safeCustomColors,
safeThemeColors,
safeDefaultColors,
safeDefaultPaletteEnabled
]);
const screenPath = !name ? "/colors/palette" : "/blocks/" + encodeURIComponent(name) + "/colors/palette";
return /* @__PURE__ */ jsxs(Stack, {
direction: "column",
gap: "md",
children: [/* @__PURE__ */ jsx(Subtitle, {
level: 3,
children: __("Palette")
}), /* @__PURE__ */ jsx(__experimentalItemGroup, {
isBordered: true,
isSeparated: true,
children: /* @__PURE__ */ jsx(NavigationButtonAsItem, {
path: screenPath,
children: /* @__PURE__ */ jsxs(Stack, {
direction: "row",
justify: "space-between",
align: "center",
children: [colors.length > 0 ? /* @__PURE__ */ jsxs(Stack, {
direction: "row",
align: "center",
gap: "sm",
children: [/* @__PURE__ */ jsx("div", {
className: "global-styles-ui__palette-preview",
children: colors.slice(0, 5).map(({ color }, index) => /* @__PURE__ */ jsx(ColorIndicatorWrapper, { children: /* @__PURE__ */ jsx(ColorIndicator, { colorValue: color }) }, `${color}-${index}`))
}), /* @__PURE__ */ jsx("span", { children: __("Edit palette") })]
}) : /* @__PURE__ */ jsx("span", { children: __("Add colors") }), /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? chevronLeft : chevronRight })]
})
})
})]
});
}
export { Palette as default };
//# sourceMappingURL=palette.mjs.map