UNPKG

@wordpress/global-styles-ui

Version:
67 lines (66 loc) • 2.63 kB
import { Button, FlexItem, __experimentalItemGroup } from "@wordpress/components"; import { isRTL } from "@wordpress/i18n"; import { Icon, chevronLeft, chevronRight, moreVertical, plus } from "@wordpress/icons"; import { useState } from "@wordpress/element"; import { Menu, Stack } from "@wordpress/ui"; import { Subtitle } from "../subtitle.mjs"; import { NavigationButtonAsItem } from "../navigation-button.mjs"; import ConfirmResetDialog from "./dialogs/confirm-reset-dialog.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/global-styles-ui/src/presets/preset-group.tsx function PresetGroup({ label, items, getEditPath, addLabel, onAdd, menuAction }) { const [isResetOpen, setIsResetOpen] = useState(false); const showMenu = !!menuAction && items.length > 0; return /* @__PURE__ */ jsxs(Stack, { direction: "column", gap: "sm", children: [ menuAction && isResetOpen && /* @__PURE__ */ jsx(ConfirmResetDialog, { text: menuAction.confirmText, confirmButtonText: menuAction.confirmButtonText, isOpen: isResetOpen, toggleOpen: () => setIsResetOpen(false), onConfirm: menuAction.onConfirm }), /* @__PURE__ */ jsxs(Stack, { justify: "space-between", align: "flex-start", children: [/* @__PURE__ */ jsx(Subtitle, { level: 3, children: label }), /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: "xs", children: [addLabel && onAdd && /* @__PURE__ */ jsx(Button, { size: "small", icon: plus, label: addLabel, onClick: onAdd }), showMenu && /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, { render: /* @__PURE__ */ jsx(Button, { size: "small", icon: moreVertical, label: menuAction.optionsLabel }) }), /* @__PURE__ */ jsx(Menu.Popup, { children: /* @__PURE__ */ jsx(Menu.Item, { onClick: () => setIsResetOpen(true), children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: menuAction.label }) }) })] })] })] }), items.length > 0 && /* @__PURE__ */ jsx(__experimentalItemGroup, { isBordered: true, isSeparated: true, children: items.map((item) => /* @__PURE__ */ jsx(NavigationButtonAsItem, { path: getEditPath(item.slug), children: /* @__PURE__ */ jsxs(Stack, { direction: "row", justify: "space-between", align: "center", children: [/* @__PURE__ */ jsx(FlexItem, { children: item.name }), /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? chevronLeft : chevronRight })] }) }, item.slug)) }) ] }); } export { PresetGroup as default }; //# sourceMappingURL=preset-group.mjs.map