Last active
November 25, 2019 07:38
-
-
Save emarc/690eb2659c8b51cb895716914d65ec19 to your computer and use it in GitHub Desktop.
Automatically switch Vaadin application between Light and Dark mode depending on OS settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. @JsModule("prefers-color-scheme.js") on your main view | |
// 2. Put this in /frontend/prefers-color-scheme.js | |
let mm = window.matchMedia('(prefers-color-scheme: dark)'); | |
function apply() { | |
document.documentElement.setAttribute("theme",mm.matches?"dark":""); | |
} | |
mm.addListener(apply); | |
apply(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment