UNPKG

@wordpress/widget-dashboard

Version:

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

44 lines (43 loc) • 1.46 kB
import { createContext, useContext, useMemo, useState } from "@wordpress/element"; import { jsx } from "react/jsx-runtime"; // packages/widget-dashboard/src/context/ui-context.tsx const Context = createContext(null); /** * Accesses the shared UI state: overlay open flags and the active settings * instance with its placement. Throws when called outside `WidgetDashboard`. */ function useDashboardUIContext() { const ctx = useContext(Context); if (!ctx) throw new Error("Dashboard compound used outside a WidgetDashboard subtree."); return ctx; } /** * Holds transient UI state shared across compounds (the inserter modal and * the per-instance settings drawer). Kept separate from the data context so * that data mutations don't churn the UI state and vice-versa. * * @param {ProviderProps} props Component props. */ function WidgetDashboardUIProvider({ children }) { const [inserterOpen, setInserterOpen] = useState(false); const [resetDialogOpen, setResetDialogOpen] = useState(false); const [settingsWidgetUuid, setSettingsWidgetUuid] = useState(null); const value = useMemo(() => ({ inserterOpen, setInserterOpen, resetDialogOpen, setResetDialogOpen, settingsWidgetUuid, setSettingsWidgetUuid }), [ inserterOpen, resetDialogOpen, settingsWidgetUuid ]); return /* @__PURE__ */ jsx(Context.Provider, { value, children }); } export { WidgetDashboardUIProvider, useDashboardUIContext }; //# sourceMappingURL=ui-context.mjs.map