Files
shakespeare/src/hooks/useTheme.ts
T
2025-10-04 15:18:03 -05:00

31 lines
794 B
TypeScript

import { type Theme } from "@/contexts/AppContext";
import { useAppContext } from "@/hooks/useAppContext";
import { useSystemTheme } from "./useSystemTheme";
/**
* Hook to get and set the active theme
* @returns Theme context with theme and setTheme
*/
export function useTheme(): {
theme: Theme;
systemTheme: "light" | "dark";
displayTheme: "light" | "dark";
setTheme: (theme: Theme) => void;
} {
const { config, updateConfig } = useAppContext();
const systemTheme = useSystemTheme();
const displayTheme = config.theme === 'system' ? systemTheme : config.theme;
return {
theme: config.theme,
systemTheme,
displayTheme,
setTheme: (theme: Theme) => {
updateConfig((currentConfig) => ({
...currentConfig,
theme,
}));
}
}
}