UNPKG

@wordpress/widget-dashboard

Version:

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

54 lines (53 loc) • 1.89 kB
// packages/widget-dashboard/src/components/widget-inserter/widget-inserter.tsx import { useCallback } from "@wordpress/element"; import { __ } from "@wordpress/i18n"; import { Dialog } from "@wordpress/ui"; import { useDashboardInternalContext } from "../../context/dashboard-context.mjs"; import { useDashboardUIContext } from "../../context/ui-context.mjs"; import { createDashboardWidget } from "../../utils/create-dashboard-widget/index.mjs"; import { WidgetPicker } from "../widget-picker/index.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; function WidgetInserter() { const { layout, onLayoutChange } = useDashboardInternalContext(); const { inserterOpen, setInserterOpen } = useDashboardUIContext(); const insertWidgets = useCallback( (widgetTypes) => { if (widgetTypes.length > 0) { const newWidgets = widgetTypes.map( (widgetType) => createDashboardWidget(widgetType) ); onLayoutChange([...layout, ...newWidgets]); } setInserterOpen(false); }, [layout, onLayoutChange, setInserterOpen] ); if (!inserterOpen) { return null; } return /* @__PURE__ */ jsx(Dialog.Root, { open: inserterOpen, onOpenChange: setInserterOpen, children: /* @__PURE__ */ jsxs( Dialog.Popup, { size: "full", portal: /* @__PURE__ */ jsx( Dialog.Portal, { style: { "--wp-ui-dialog-z-index": 99999 } } ), children: [ /* @__PURE__ */ jsxs(Dialog.Header, { children: [ /* @__PURE__ */ jsx(Dialog.Title, { children: __("Add widget") }), /* @__PURE__ */ jsx(Dialog.CloseIcon, {}) ] }), /* @__PURE__ */ jsx(Dialog.Content, { children: /* @__PURE__ */ jsx(WidgetPicker, { onSelect: insertWidgets }) }) ] } ) }); } export { WidgetInserter }; //# sourceMappingURL=widget-inserter.mjs.map