Skip to content

Instantly share code, notes, and snippets.

@infantiablue
Created January 17, 2021 08:06
Show Gist options
  • Save infantiablue/a212fd672f95368e7e57db8b3368166e to your computer and use it in GitHub Desktop.
Save infantiablue/a212fd672f95368e7e57db8b3368166e to your computer and use it in GitHub Desktop.
Hnews Toggle Darkmode
toggleDarkMode(theme, evt) {
let htmlElm = document.querySelector("html");
const setLight = () => {
htmlElm.classList.remove("dark");
localStorage.theme = "light";
this.$refs.toggleDark.textContent = "☀️";
};
const setDark = () => {
htmlElm.classList.add("dark");
localStorage.theme = "dark";
this.$refs.toggleDark.textContent = "🌙";
};
if (typeof theme === "string") {
if (theme == "dark") setDark();
else setLight();
} else {
if (localStorage.theme === "dark") setLight();
else setDark();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment