@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
111 lines (110 loc) • 3.3 kB
JavaScript
// packages/global-styles-ui/src/presets/preset-group.tsx
import {
__experimentalItemGroup as ItemGroup,
Button,
FlexItem,
privateApis as componentsPrivateApis
} from "@wordpress/components";
import { isRTL } from "@wordpress/i18n";
import {
plus,
Icon,
chevronLeft,
chevronRight,
moreVertical
} from "@wordpress/icons";
import { useState } from "@wordpress/element";
import { Stack } from "@wordpress/ui";
import { Subtitle } from "../subtitle.mjs";
import { NavigationButtonAsItem } from "../navigation-button.mjs";
import { unlock } from "../lock-unlock.mjs";
import ConfirmResetDialog from "./dialogs/confirm-reset-dialog.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
var { Menu } = unlock(componentsPrivateApis);
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(FlexItem, { children: [
addLabel && onAdd && /* @__PURE__ */ jsx(
Button,
{
size: "small",
icon: plus,
label: addLabel,
onClick: onAdd
}
),
showMenu && /* @__PURE__ */ jsxs(Menu, { children: [
/* @__PURE__ */ jsx(
Menu.TriggerButton,
{
render: /* @__PURE__ */ jsx(
Button,
{
size: "small",
icon: moreVertical,
label: menuAction.optionsLabel
}
)
}
),
/* @__PURE__ */ jsx(Menu.Popover, { children: /* @__PURE__ */ jsx(
Menu.Item,
{
onClick: () => setIsResetOpen(true),
children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: menuAction.label })
}
) })
] })
] })
] }),
items.length > 0 && /* @__PURE__ */ jsx(ItemGroup, { 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