UNPKG

@wordpress/widget-dashboard

Version:

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

79 lines (77 loc) • 3.38 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/widget-dashboard/src/components/widget-inserter/widget-inserter.tsx var widget_inserter_exports = {}; __export(widget_inserter_exports, { WidgetInserter: () => WidgetInserter }); module.exports = __toCommonJS(widget_inserter_exports); var import_element = require("@wordpress/element"); var import_i18n = require("@wordpress/i18n"); var import_ui = require("@wordpress/ui"); var import_dashboard_context = require("../../context/dashboard-context.cjs"); var import_ui_context = require("../../context/ui-context.cjs"); var import_create_dashboard_widget = require("../../utils/create-dashboard-widget/index.cjs"); var import_widget_picker = require("../widget-picker/index.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function WidgetInserter() { const { layout, onLayoutChange } = (0, import_dashboard_context.useDashboardInternalContext)(); const { inserterOpen, setInserterOpen } = (0, import_ui_context.useDashboardUIContext)(); const insertWidgets = (0, import_element.useCallback)( (widgetTypes) => { if (widgetTypes.length > 0) { const newWidgets = widgetTypes.map( (widgetType) => (0, import_create_dashboard_widget.createDashboardWidget)(widgetType) ); onLayoutChange([...layout, ...newWidgets]); } setInserterOpen(false); }, [layout, onLayoutChange, setInserterOpen] ); if (!inserterOpen) { return null; } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Dialog.Root, { open: inserterOpen, onOpenChange: setInserterOpen, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_ui.Dialog.Popup, { size: "full", portal: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_ui.Dialog.Portal, { style: { "--wp-ui-dialog-z-index": 99999 } } ), children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Dialog.Header, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Dialog.Title, { children: (0, import_i18n.__)("Add widget") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Dialog.CloseIcon, {}) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Dialog.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_widget_picker.WidgetPicker, { onSelect: insertWidgets }) }) ] } ) }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { WidgetInserter }); //# sourceMappingURL=widget-inserter.cjs.map