Untitled

mail@pastecode.io avatar
unknown
typescript
6 months ago
791 B
0
Indexable
Never
// thunders/theme.ts

import { thunder } from "killua";

type TTheme = 'system' | 'light' | 'dark';

const thunderTheme = thunder({
  key: "theme",
  encrypt: false,
  default: 'system' as TTheme, 
  expire: null,
  reducers: {
    system: () => {
      const theme = 'system' as TTheme;
      document.documentElement.dataset['theme'] = (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
      return theme;
    },
    light: () => {
      const theme = 'light' as TTheme;
      document.documentElement.dataset['theme'] = theme;
      return theme;
    },
    dark: () => {
      const theme = 'dark' as TTheme;
      document.documentElement.dataset['theme'] = theme;
      return theme;
    },
  },
});

export { thunderTheme };