Persist themes with user default
This commit is contained in:
parent
753863585d
commit
62621e7fe6
@ -9,25 +9,28 @@ const theme_icons = {
|
||||
'dark': IconMoonStars,
|
||||
}
|
||||
|
||||
const currentTheme = ref('light')
|
||||
let storedTheme = localStorage.getItem('theme')
|
||||
if (!storedTheme) {
|
||||
storedTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
}
|
||||
|
||||
const currentTheme = ref(storedTheme)
|
||||
document.documentElement.setAttribute('data-bs-theme', storedTheme)
|
||||
|
||||
async function click(ev) {
|
||||
ev.preventDefault()
|
||||
|
||||
let newTheme = 'light'
|
||||
if (currentTheme.value == 'light') {
|
||||
currentTheme.value = 'dark'
|
||||
} else {
|
||||
currentTheme.value = 'light'
|
||||
}
|
||||
document.documentElement.setAttribute('data-bs-theme', currentTheme.value)
|
||||
newTheme = 'dark'
|
||||
}
|
||||
|
||||
const currentIcon = computed(() => {
|
||||
let icon = theme_icons[currentTheme.value]
|
||||
//console.log(currentTheme.value)
|
||||
//console.log(icon)
|
||||
return icon
|
||||
})
|
||||
currentTheme.value = newTheme
|
||||
document.documentElement.setAttribute('data-bs-theme', newTheme)
|
||||
localStorage.setItem('theme', newTheme)
|
||||
}
|
||||
|
||||
const currentIcon = computed(() => theme_icons[currentTheme.value])
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user