UNPKG

@wordpress/widget-dashboard

Version:

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

1 lines • 1.24 kB
{"version":3,"file":"widget-context.mjs","names":[],"sources":["../../src/context/widget-context.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { createContext, useContext } from '@wordpress/element';\nimport type { WidgetContextValue } from '../types';\n\nconst WidgetContext = createContext< WidgetContextValue | null >( null );\n\ninterface ProviderProps {\n\tvalue: WidgetContextValue;\n\tchildren: ReactNode;\n}\n\n/**\n * Provides the current widget's identity to its render subtree.\n *\n * @param {ProviderProps} props Component props.\n */\nexport function WidgetContextProvider( {\n\tvalue,\n\tchildren,\n}: ProviderProps ): React.ReactNode {\n\treturn (\n\t\t<WidgetContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</WidgetContext.Provider>\n\t);\n}\n\n/**\n * Returns the current widget's identity (`uuid`, `name`, `index`). Returns\n * `null` when called outside a widget render subtree.\n */\nexport function useWidgetContext(): WidgetContextValue | null {\n\treturn useContext( WidgetContext );\n}\n"],"mappings":";;;AAIA,MAAM,gBAAgB,cAA4C,IAAK;;;;;;AAYvE,SAAgB,sBAAuB,EACtC,OACA,YACmC;CACnC,OACC,oBAAC,cAAc,UAAf;EAAgC;EAC7B;CACqB,CAAA;AAE1B;;;;;AAMA,SAAgB,mBAA8C;CAC7D,OAAO,WAAY,aAAc;AAClC"}