Fix missing useDarkMode update

This commit is contained in:
ekzyis 2024-11-18 23:00:07 +01:00
parent 79ada2ab58
commit 120dd4122f
1 changed files with 9 additions and 0 deletions

View File

@ -48,6 +48,15 @@ const listenForThemeChange = (onChange) => {
onChange({ user: true, dark })
}
}
const root = window.document.documentElement
const observer = new window.MutationObserver(() => {
const theme = root.getAttribute('data-bs-theme')
onChange(dark => ({ ...dark, dark: theme === 'dark' }))
})
observer.observe(root, { attributes: true, attributeFilter: ['data-bs-theme'] })
return () => observer.disconnect()
}
export default function useDarkMode () {