Moving to new theme
This commit is contained in:
27
src/theme.ts
Normal file
27
src/theme.ts
Normal file
@ -0,0 +1,27 @@
|
||||
const light = require("!!raw-loader!@hibas123/theme/out/light.css").default;
|
||||
const dark = require("!!raw-loader!@hibas123/theme/out/dark.css").default;
|
||||
|
||||
let isDark = localStorage.getItem("theme") === "dark";
|
||||
|
||||
|
||||
let styleElm: HTMLStyleElement;
|
||||
|
||||
function apply() {
|
||||
if (styleElm) styleElm.remove();
|
||||
styleElm = document.createElement("style");
|
||||
document.head.appendChild(styleElm);
|
||||
styleElm.innerHTML = isDark ? dark : light;
|
||||
}
|
||||
apply();
|
||||
|
||||
function toggle() {
|
||||
isDark = !isDark;
|
||||
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||
apply();
|
||||
}
|
||||
|
||||
export default {
|
||||
active: () => isDark,
|
||||
toggle: () => toggle()
|
||||
}
|
||||
|
Reference in New Issue
Block a user