@rbnd/react-dark-mode
Version:
React hook for switching between light, dark and system color mode.
1 lines • 368 B
JavaScript
!function(){var b,a,c="dark-mode",d="light-mode",e="(prefers-color-scheme: dark)",f=window.matchMedia(e),h=f.media===e;try{var g=localStorage.getItem("scheme-mode");g&&(a=JSON.parse(g))}catch{}b=h&&"system"===a?f.matches:("light"===a||"dark"===a)&&"dark"===a,document.querySelector("html").classList.add(b?c:d),document.querySelector("html").classList.remove(b?d:c)}()