- Added Nix theme - Defaults to dark mode Signed-off-by: Noa Virellia <noa@requiem.garden>
25 lines
551 B
TypeScript
25 lines
551 B
TypeScript
import { createContext, use } from 'react';
|
|
|
|
export type Theme = 'dark' | 'light' | 'system';
|
|
|
|
interface ThemeProviderState {
|
|
theme: Theme;
|
|
setTheme: (theme: Theme) => void;
|
|
}
|
|
|
|
const initialState: ThemeProviderState = {
|
|
theme: 'system',
|
|
setTheme: () => null,
|
|
};
|
|
|
|
export const ThemeProviderContext = createContext<ThemeProviderState>(initialState);
|
|
|
|
export function useTheme() {
|
|
const context = use(ThemeProviderContext);
|
|
|
|
if (context === undefined)
|
|
throw new Error('useTheme must be used within a ThemeProvider');
|
|
|
|
return context;
|
|
}
|