@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
50 lines (49 loc) • 2.62 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_element = require("@wordpress/element");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_ui = require("@wordpress/ui");
let ______context_dashboard_context_tsx = require("../../context/dashboard-context.cjs");
let ______context_ui_context_tsx = require("../../context/ui-context.cjs");
let ______utils_create_dashboard_widget_index_ts = require("../../utils/create-dashboard-widget/index.cjs");
let ___widget_picker_index_ts = require("../widget-picker/index.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/widget-dashboard/src/components/widget-inserter/widget-inserter.tsx
/**
* Modal widget inserter, mounted by the engine and shown while `inserterOpen`
* is set in the shared UI context. Selecting widgets appends them to the
* layout and closes the dialog.
*/
function WidgetInserter() {
const { layout, onLayoutChange } = (0, ______context_dashboard_context_tsx.useDashboardInternalContext)();
const { inserterOpen, setInserterOpen } = (0, ______context_ui_context_tsx.useDashboardUIContext)();
const insertWidgets = (0, _wordpress_element.useCallback)((widgetTypes) => {
if (widgetTypes.length > 0) {
const newWidgets = widgetTypes.map((widgetType) => (0, ______utils_create_dashboard_widget_index_ts.createDashboardWidget)(widgetType));
onLayoutChange([...layout, ...newWidgets]);
}
setInserterOpen(false);
}, [
layout,
onLayoutChange,
setInserterOpen
]);
if (!inserterOpen) return null;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Dialog.Root, {
open: inserterOpen,
onOpenChange: setInserterOpen,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Dialog.Popup, {
size: "full",
portal: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Dialog.Portal, {
container: document.body,
style: { "--wp-ui-dialog-z-index": 99999 }
}),
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Dialog.Header, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Dialog.Title, { children: (0, _wordpress_i18n.__)("Add widget") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Dialog.CloseIconButton, {})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Dialog.Content, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___widget_picker_index_ts.WidgetPicker, { onSelect: insertWidgets }) })]
})
});
}
exports.WidgetInserter = WidgetInserter;
//# sourceMappingURL=widget-inserter.cjs.map