UNPKG

@wordpress/widget-dashboard

Version:

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

90 lines (89 loc) • 3.43 kB
import { WidgetDashboardProvider } from "./context/dashboard-context.mjs"; import { WidgetDashboardUIProvider } from "./context/ui-context.mjs"; import { Actions } from "./components/actions/index.mjs"; import { Commands } from "./components/commands/index.mjs"; import { NoWidgetsState } from "./components/no-widgets-state/index.mjs"; import { ResetConfirmation } from "./components/reset-confirmation/index.mjs"; import { WidgetChrome } from "./components/widget-chrome/index.mjs"; import { WidgetInserter } from "./components/widget-inserter/index.mjs"; import { WidgetDashboardPolicy } from "./components/dashboard-policy/index.mjs"; import { WidgetSettings } from "./components/widget-settings/index.mjs"; import { Widgets } from "./components/widgets/index.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/widget-dashboard/src/widget-dashboard.tsx /** * Stateless rendering engine for widget dashboards. * * The consumer owns `layout` and `editMode` state; every mutation fires * `onLayoutChange` with the fully updated array. The engine never queries a * widget store; types flow in via the `widgetTypes` prop. * * ```tsx * import { WidgetDashboard } from '@wordpress/widget-dashboard'; * * function MyDashboard() { * const [ layout, setLayout ] = useState( defaultLayout ); * const [ editMode, setEditMode ] = useState( false ); * return ( * <WidgetDashboard * layout={ layout } * onLayoutChange={ setLayout } * widgetTypes={ widgetTypes } * editMode={ editMode } * onEditChange={ setEditMode } * > * <WidgetDashboard.NoWidgetsState> * <p>No widgets yet.</p> * </WidgetDashboard.NoWidgetsState> * <WidgetDashboard.Actions /> * <WidgetDashboard.Widgets /> * <WidgetDashboard.Commands /> * </WidgetDashboard> * ); * } * ``` * * Children compose the dashboard's triggers and chrome: `Actions`, * `Widgets`, `Commands`, `NoWidgetsState`. The targets they open (the * widget inserter, the widget settings editor, the reset confirmation) are * mounted by the engine and driven by shared UI state, so a trigger works * wherever it is composed without a matching target in the tree. Omitting * `children` renders the default arrangement. * * `Policy` mounts above one or several dashboards and governs what users * may do on them; every compound asks the resolved policy through the * internal context. */ const WidgetDashboard = Object.assign(function WidgetDashboardRoot({ layout, onLayoutChange, onLayoutReset, widgetTypes, isResolvingWidgetTypes, editMode, onEditChange, resolveWidgetModule, gridSettings, children }) { return /* @__PURE__ */ jsx(WidgetDashboardProvider, { layout, onLayoutChange, onLayoutReset, widgetTypes, isResolvingWidgetTypes, editMode, onEditChange, resolveWidgetModule, gridSettings, children: /* @__PURE__ */ jsxs(WidgetDashboardUIProvider, { children: [ children ?? /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx(NoWidgetsState, {}), /* @__PURE__ */ jsx(Actions, {}), /* @__PURE__ */ jsx(Widgets, {}), /* @__PURE__ */ jsx(Commands, {}) ] }), /* @__PURE__ */ jsx(WidgetInserter, {}), /* @__PURE__ */ jsx(WidgetSettings, {}), /* @__PURE__ */ jsx(ResetConfirmation, {}) ] }) }); }, { Actions, Widgets, WidgetChrome, NoWidgetsState, Commands, Policy: WidgetDashboardPolicy }); export { WidgetDashboard }; //# sourceMappingURL=widget-dashboard.mjs.map