Add class=dark to document root when using dark theme #50
Closed
pleasantone
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
You can retrieve the current theme from const theme = localStorage.getItem('hb-theme')
if (theme === 'dark' || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
// handle dark theme
}
document.addEventListener('hb:theme', (e) => {
console.log(e.detail.theme === 'dark' ? 'dark' : 'light')
})
I don't think it is generic/good solution, such as Mermaid theme, Giscus comments theme, they don't reply on those attributes, so I'd leave it as a duty of specified module. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This does nothing for bootstrap, which is already using data-bs-theme, but it is a nice signal to third-party code that we may want to integrate such as the add to calendar button lightMode which looks for generic theme hints.
thoughts?
Beta Was this translation helpful? Give feedback.
All reactions