wip: making themes more dynamic and easy to add
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
type Theme = 'light' | 'dark' | 'system';
|
||||
type ResolvedTheme = 'light' | 'dark';
|
||||
|
||||
class ThemeStore {
|
||||
current = $state<Theme>('system');
|
||||
@@ -35,6 +36,12 @@ class ThemeStore {
|
||||
}
|
||||
}
|
||||
|
||||
getResolvedTheme(): ResolvedTheme {
|
||||
const isDark = this.current === 'dark' ||
|
||||
(this.current === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
return isDark ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
toggle() {
|
||||
// Cycle through: light -> dark -> system -> light
|
||||
if (this.current === 'light') {
|
||||
|
||||
Reference in New Issue
Block a user