1 line
1.9 KiB
Plaintext
1 line
1.9 KiB
Plaintext
{"version":3,"file":"ThemeContext.cjs","names":["defaultTheme"],"sources":["../../../src/react-renderer/theme/ThemeContext.tsx"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport type { Types } from \"@a2ui/lit/0.8\";\nimport { defaultTheme } from \"./litTheme\";\n\n/**\n * React context for the A2UI theme.\n */\nconst ThemeContext = createContext<Types.Theme | undefined>(undefined);\n\n/**\n * Props for the ThemeProvider component.\n */\nexport interface ThemeProviderProps {\n /** The theme to provide. Falls back to defaultTheme if not specified. */\n theme?: Types.Theme;\n /** Child components that will have access to the theme */\n children: ReactNode;\n}\n\n/**\n * Provider component that makes the A2UI theme available to descendant components.\n */\nexport function ThemeProvider({ theme, children }: ThemeProviderProps) {\n return (\n <ThemeContext.Provider value={theme ?? defaultTheme}>\n {children}\n </ThemeContext.Provider>\n );\n}\n\n/**\n * Hook to access the current A2UI theme.\n *\n * @returns The current theme\n * @throws If used outside of a ThemeProvider\n */\nexport function useTheme(): Types.Theme {\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\n/**\n * Hook to optionally access the current A2UI theme.\n *\n * @returns The current theme, or undefined if not within a provider\n */\nexport function useThemeOptional(): Types.Theme | undefined {\n return useContext(ThemeContext);\n}\n"],"mappings":";;;;;;;;;AAOA,MAAM,wCAAsD,OAAU;;;;AAetE,SAAgB,cAAc,EAAE,OAAO,YAAgC;AACrE,QACE,2CAAC,aAAa;EAAS,OAAO,SAASA;EACpC;GACqB;;;;;;;;AAU5B,SAAgB,WAAwB;CACtC,MAAM,8BAAmB,aAAa;AACtC,KAAI,CAAC,MACH,OAAM,IAAI,MACR,+DACD;AAEH,QAAO;;;;;;;AAQT,SAAgB,mBAA4C;AAC1D,8BAAkB,aAAa"} |