Spaces:
Running
Running
File size: 558 Bytes
ad08f08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
export const applyTheme = (theme) => {
const root = document.documentElement;
if (theme === 'dark') {
root.classList.add('dark');
} else {
root.classList.remove('dark');
}
// Save to localStorage
localStorage.setItem('theme', theme);
};
export const getInitialTheme = () => {
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme) {
return savedTheme;
}
return prefersDark ? 'dark' : 'light';
}; |