whois/template/static/js/components/themeSwitcher.js
Elizabeth Hunt d25ec27fb1
Some checks failed
continuous-integration/drone/push Build is failing
initial commit by simponic-infra
2025-01-05 16:39:13 -08:00

28 lines
676 B
JavaScript

const THEMES = {
DARK: "DARK",
LIGHT: "LIGHT",
};
const flipFlopTheme = (theme) =>
THEMES[theme] === THEMES.DARK ? THEMES.LIGHT : THEMES.DARK;
const themePickerText = {
DARK: "light mode.",
LIGHT: "dark mode.",
};
const themeSwitcher = document.getElementById("theme-switcher");
const setTheme = (theme) => {
themeSwitcher.textContent = `${themePickerText[theme]}`;
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("theme", theme);
};
themeSwitcher.addEventListener("click", () =>
setTheme(flipFlopTheme(document.documentElement.getAttribute("data-theme"))),
);
setTheme(localStorage.getItem("theme") || THEMES.LIGHT);