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

44 lines
1.3 KiB
JavaScript

const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_litTheme = require('./litTheme.cjs');
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/react-renderer/theme/ThemeContext.tsx
/**
* React context for the A2UI theme.
*/
const ThemeContext = (0, react.createContext)(void 0);
/**
* Provider component that makes the A2UI theme available to descendant components.
*/
function ThemeProvider({ theme, children }) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ThemeContext.Provider, {
value: theme ?? require_litTheme.defaultTheme,
children
});
}
/**
* Hook to access the current A2UI theme.
*
* @returns The current theme
* @throws If used outside of a ThemeProvider
*/
function useTheme() {
const theme = (0, react.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 (0, react.useContext)(ThemeContext);
}
//#endregion
exports.ThemeProvider = ThemeProvider;
exports.useTheme = useTheme;
exports.useThemeOptional = useThemeOptional;
//# sourceMappingURL=ThemeContext.cjs.map