UNPKG

@copilotkit/a2ui-renderer

Version:

A2UI Renderer for CopilotKit - render A2UI surfaces in React applications

1 lines 1.24 kB
{"version":3,"file":"ThemeContext.cjs","names":[],"sources":["../../../src/react-renderer/theme/ThemeContext.tsx"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\n\ntype ThemeType = Record<string, unknown>;\n\n/** React context for the A2UI theme. */\nconst ThemeContext = createContext<ThemeType | undefined>(undefined);\n\nexport interface ThemeProviderProps {\n theme?: ThemeType;\n children: ReactNode;\n}\n\nexport function ThemeProvider({ theme, children }: ThemeProviderProps) {\n return (\n <ThemeContext.Provider value={theme ?? {}}>\n {children}\n </ThemeContext.Provider>\n );\n}\n\nexport function useTheme(): ThemeType {\n const theme = useContext(ThemeContext);\n if (!theme) {\n throw new Error(\n \"useTheme must be used within a ThemeProvider or A2UIProvider\",\n );\n }\n return theme;\n}\n\nexport function useThemeOptional(): ThemeType | undefined {\n return useContext(ThemeContext);\n}\n"],"mappings":";;;;;;AAKA,MAAM,wCAAoD,OAAU;AAOpE,SAAgB,cAAc,EAAE,OAAO,YAAgC;AACrE,QACE,2CAAC,aAAa;EAAS,OAAO,SAAS,EAAE;EACtC;GACqB;;AAI5B,SAAgB,WAAsB;CACpC,MAAM,8BAAmB,aAAa;AACtC,KAAI,CAAC,MACH,OAAM,IAAI,MACR,+DACD;AAEH,QAAO;;AAGT,SAAgB,mBAA0C;AACxD,8BAAkB,aAAa"}