rdesign/frontend/node_modules/@copilotkit/a2ui-renderer/dist/react-renderer/theme/ThemeContext.mjs

41 lines
1.1 KiB
JavaScript

import { defaultTheme } from "./litTheme.mjs";
import { createContext, useContext } from "react";
import { jsx } from "react/jsx-runtime";
//#region src/react-renderer/theme/ThemeContext.tsx
/**
* React context for the A2UI theme.
*/
const ThemeContext = createContext(void 0);
/**
* Provider component that makes the A2UI theme available to descendant components.
*/
function ThemeProvider({ theme, children }) {
return /* @__PURE__ */ jsx(ThemeContext.Provider, {
value: theme ?? defaultTheme,
children
});
}
/**
* Hook to access the current A2UI theme.
*
* @returns The current theme
* @throws If used outside of a ThemeProvider
*/
function useTheme() {
const theme = useContext(ThemeContext);
if (!theme) throw new Error("useTheme must be used within a ThemeProvider or A2UIProvider");
return theme;
}
/**
* Hook to optionally access the current A2UI theme.
*
* @returns The current theme, or undefined if not within a provider
*/
function useThemeOptional() {
return useContext(ThemeContext);
}
//#endregion
export { ThemeProvider, useTheme, useThemeOptional };
//# sourceMappingURL=ThemeContext.mjs.map