light-dark-toggle
v1.0.0
Published
A custom element for toggling dark mode
Downloads
4
Maintainers
Readme
LightDarkToggle
Dark mode using the browser
How to use?
import { LightDarkToggle } from 'light-dark-toggle';
LightDarkToggle.define();How does it work?
When the toggle renders in your HTML, using <light-dark-toggle> it renders a button with the current mode inside of it and a <meta> with the name color-scheme and the content set to the preferred color scheme of the user.
TODO
- [x] Use a
<meta name="color-scheme">in the<head>as the source of truth if it exists. - [x] Detect and handle multiple instances
- [ ] Accept a toggle in the light dom instead of overriding the
innerHTMLof thelight-dark-toggleelement. - [x] Reflect preference in localstorage
- [ ] Tests?
- [ ] Performance?
