UNPKG

@wordpress/widget-dashboard

Version:

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

68 lines (67 loc) • 2.2 kB
// packages/widget-dashboard/src/components/actions-menu/actions-menu.tsx import { privateApis as componentsPrivateApis } from "@wordpress/components"; import { __ } from "@wordpress/i18n"; import { moreVertical } from "@wordpress/icons"; import { Button, IconButton, Tooltip } from "@wordpress/ui"; import { unlock } from "../../lock-unlock.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; var { Menu } = unlock(componentsPrivateApis); function ActionsMenuEntry({ item }) { const showDisabledTooltip = item.disabled && item.disabledTooltip; const menuItem = /* @__PURE__ */ jsx( Menu.Item, { disabled: item.disabled, onClick: item.onClick, render: /* @__PURE__ */ jsx(Button, { variant: "minimal", tone: "neutral" }), children: item.label } ); if (!showDisabledTooltip) { return menuItem; } return /* @__PURE__ */ jsxs(Tooltip.Root, { children: [ /* @__PURE__ */ jsx( Tooltip.Trigger, { render: /* @__PURE__ */ jsx( Menu.Item, { disabled: item.disabled, onClick: item.onClick, render: /* @__PURE__ */ jsx(Button, { variant: "minimal", tone: "neutral" }) } ), children: item.label } ), /* @__PURE__ */ jsx(Tooltip.Popup, { positioner: /* @__PURE__ */ jsx(Tooltip.Positioner, { side: "bottom" }), children: item.disabledTooltip }) ] }); } function ActionsMenu({ items }) { if (items.length === 0) { return null; } return /* @__PURE__ */ jsxs(Menu, { children: [ /* @__PURE__ */ jsx( Menu.TriggerButton, { render: /* @__PURE__ */ jsx( IconButton, { icon: moreVertical, label: __("More options"), variant: "minimal", tone: "brand", size: "compact" } ) } ), /* @__PURE__ */ jsx(Menu.Popover, { 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