fix: theming bug
This commit is contained in:
parent
1c01154395
commit
119f3ce524
4 changed files with 13 additions and 12 deletions
|
@ -90,15 +90,16 @@
|
|||
(() => {
|
||||
const currentTheme = sessionStorage?.getItem('theme');
|
||||
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const root = document.getElementsByTagName('html')[0];
|
||||
if (!currentTheme) sessionStorage?.setItem('theme', (prefersDarkScheme ? 'dark' : 'light'))
|
||||
if (currentTheme === 'dark') {
|
||||
document.body.classList.add('theme__dark')
|
||||
root.classList.add('theme__dark')
|
||||
} else if (currentTheme === 'light') {
|
||||
document.body.classList.add('theme__light')
|
||||
root.classList.add('theme__light')
|
||||
} else if (prefersDarkScheme) {
|
||||
document.body.classList.add('theme__dark')
|
||||
root.classList.add('theme__dark')
|
||||
} else if (!prefersDarkScheme) {
|
||||
document.body.classList.add('theme__light')
|
||||
root.classList.add('theme__light')
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
|
Reference in a new issue