btcpayserver/BTCPayServer/wwwroot/js/theme-switch.js
d11n fe18e71538
Refactor themes (#2794)
* Remove Bootstrap/Creative CSS file customizability

Customizations should be done using themes

* Remove deprecated Casa and Classic themes

They are still available in the design system repo and should be added as custom theme CSS file

* Use either standard or custom theme

* Remove deprecated themes

* Improve theme select UI

* Finish and refactor theme switching

* updates theme copy

* Update BTCPayServer/Views/Server/Theme.cshtml

Co-authored-by: Zaxounette <51208677+Zaxounette@users.noreply.github.com>

* Combine creative.css and site.css

Co-authored-by: dstrukt <gfxdsign@gmail.com>
Co-authored-by: Zaxounette <51208677+Zaxounette@users.noreply.github.com>
2021-09-03 16:16:36 +09:00

16 lines
733 B
JavaScript

const COLOR_MODES = ["light", "dark"];
const THEME_ATTR = "data-btcpay-theme";
const STORE_ATTR = "btcpay-theme";
const systemColorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? COLOR_MODES[1] : COLOR_MODES[0];
const userColorMode = window.localStorage.getItem(STORE_ATTR);
const initialColorMode = COLOR_MODES.includes(userColorMode) ? userColorMode : systemColorMode;
function setColorMode (mode) {
if (COLOR_MODES.includes(mode)) {
window.localStorage.setItem(STORE_ATTR, mode);
document.documentElement.setAttribute(THEME_ATTR, mode);
document.getElementById("DarkThemeLinkTag").setAttribute("rel", mode === "dark" ? "stylesheet" : null);
}
}
setColorMode(initialColorMode);