Skip to content

Instantly share code, notes, and snippets.

@emarc
Last active November 25, 2019 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emarc/690eb2659c8b51cb895716914d65ec19 to your computer and use it in GitHub Desktop.
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
// 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