first init
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
export type Theme = 'dark' | 'light';
|
||||
|
||||
const THEME_KEY = 'tautkan_theme';
|
||||
const OLD_THEME_KEY = 'retro_kanban_theme';
|
||||
|
||||
export function getTheme(): Theme {
|
||||
try {
|
||||
const saved = (localStorage.getItem(THEME_KEY) || localStorage.getItem(OLD_THEME_KEY)) as Theme;
|
||||
if (saved === 'dark' || saved === 'light') return saved;
|
||||
} catch {}
|
||||
return 'light'; // Default to modern Light mode
|
||||
}
|
||||
|
||||
export function applyTheme(theme: Theme): void {
|
||||
const root = document.documentElement;
|
||||
if (theme === 'dark') {
|
||||
root.classList.add('dark');
|
||||
root.classList.remove('light');
|
||||
} else {
|
||||
root.classList.remove('dark');
|
||||
root.classList.add('light');
|
||||
}
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, theme);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function toggleTheme(): Theme {
|
||||
const current = getTheme();
|
||||
const next = current === 'dark' ? 'light' : 'dark';
|
||||
applyTheme(next);
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user