UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

46 lines (45 loc) • 1.88 kB
import { __ } from "@wordpress/i18n"; import { moreVertical } from "@wordpress/icons"; import { IconButton, Menu, Tooltip } from "@wordpress/ui"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/widget-dashboard/src/components/actions-menu/actions-menu.tsx function ActionsMenuEntry({ item }) { const showDisabledTooltip = item.disabled && item.disabledTooltip; const menuItem = /* @__PURE__ */ jsx(Menu.Item, { disabled: item.disabled, onClick: item.onClick, children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: item.label }) }); if (!showDisabledTooltip) return menuItem; return /* @__PURE__ */ jsxs(Tooltip.Root, { children: [/* @__PURE__ */ jsx(Menu.Item, { nativeButton: true, disabled: item.disabled, onClick: item.onClick, render: /* @__PURE__ */ jsx(Tooltip.Trigger, {}), children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: item.label }) }), /* @__PURE__ */ jsx(Tooltip.Popup, { positioner: /* @__PURE__ */ jsx(Tooltip.Positioner, { side: "bottom" }), children: item.disabledTooltip })] }); } /** * Renders the dashboard's overflow menu: a three-dots trigger surfacing * secondary actions. Returns `null` when there are no items. * * @param {ActionsMenuProps} props Component props. */ function ActionsMenu({ items }) { if (items.length === 0) return null; return /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, { render: /* @__PURE__ */ jsx(IconButton, { icon: moreVertical, label: __("More options"), variant: "minimal", tone: "brand", size: "compact" }) }), /* @__PURE__ */ jsx(Menu.Popup, { children: /* @__PURE__ */ jsx(Tooltip.Provider, { delay: 0, children: /* @__PURE__ */ jsx(Menu.Group, { children: items.map((item, index) => /* @__PURE__ */ jsx(ActionsMenuEntry, { item }, index)) }) }) })] }); } export { ActionsMenu }; //# sourceMappingURL=actions-menu.mjs.map