Spaces:
Running
Running
| 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'; | |
| }; |