UNPKG

@wordpress/widget-dashboard

Version:

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

29 lines (28 loc) • 1.11 kB
import { createContext, useContext, useMemo } from "@wordpress/element"; import { jsx } from "react/jsx-runtime"; // packages/widget-dashboard/src/components/dashboard-policy/dashboard-policy.tsx const PolicyContext = createContext(null); /** * Governs the dashboards below it. Mount it around one dashboard, a group, * or the whole application. Nested policies compose restrictively: an * operation is allowed only when every enclosing policy allows it. Without * a policy, every operation is allowed. * * @param {WidgetDashboardPolicyProps} props Component props. */ function WidgetDashboardPolicy({ canPerform, children }) { const parent = useContext(PolicyContext); const value = useMemo(() => parent ? (request) => parent(request) && canPerform(request) : canPerform, [parent, canPerform]); return /* @__PURE__ */ jsx(PolicyContext.Provider, { value, children }); } /** * Reads the policy in effect; `null` when none is mounted. */ function useDashboardPolicy() { return useContext(PolicyContext); } export { WidgetDashboardPolicy, useDashboardPolicy }; //# sourceMappingURL=dashboard-policy.mjs.map