UNPKG

@wordpress/widget-dashboard

Version:

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

8 lines (7 loc) • 1.26 kB
{ "version": 3, "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": ";AACA,SAAS,eAAe,kBAAkB;AAoBxC;AAjBF,IAAM,gBAAgB,cAA4C,IAAK;AAYhE,SAAS,sBAAuB;AAAA,EACtC;AAAA,EACA;AACD,GAAoC;AACnC,SACC,oBAAC,cAAc,UAAd,EAAuB,OACrB,UACH;AAEF;AAMO,SAAS,mBAA8C;AAC7D,SAAO,WAAY,aAAc;AAClC;", "names": [] }