UNPKG

@wordpress/widget-dashboard

Version:

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

39 lines (38 loc) • 1.18 kB
// packages/widget-dashboard/src/components/widget-render/widget-render.tsx import { useCallback } from "@wordpress/element"; import { WidgetRender as WidgetRenderPrimitive } from "@wordpress/widget-primitives"; import { useDashboardInternalContext } from "../../context/dashboard-context.mjs"; import { jsx } from "react/jsx-runtime"; function WidgetRender({ widget, widgetType }) { const { layout, onLayoutChange, resolveWidgetModule, canPerform } = useDashboardInternalContext(); const canEdit = canPerform({ operation: "edit", widget, widgetType }); const setAttributes = useCallback( (next) => { onLayoutChange( layout.map( (w) => w.uuid === widget.uuid ? { ...w, attributes: { ...w.attributes, ...next } } : w ) ); }, [widget.uuid, layout, onLayoutChange] ); return /* @__PURE__ */ jsx( WidgetRenderPrimitive, { widgetType, attributes: widget.attributes, setAttributes: canEdit ? setAttributes : void 0, resolveWidgetModule } ); } export { WidgetRender }; //# sourceMappingURL=widget-render.mjs.map