remove css vars when switching theme
This commit is contained in:
parent
e083856801
commit
b3510aa2b4
1 changed files with 11 additions and 0 deletions
11
src/theme.js
11
src/theme.js
|
@ -35,6 +35,16 @@ export function enumerateThemes() {
|
||||||
return Object.assign({}, customThemeNames, BUILTIN_THEMES);
|
return Object.assign({}, customThemeNames, BUILTIN_THEMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearCustomTheme() {
|
||||||
|
// remove all css variables, we assume these are there because of the custom theme
|
||||||
|
const inlineStyleProps = Object.values(document.body.style);
|
||||||
|
for (const prop of inlineStyleProps) {
|
||||||
|
if (prop.startsWith("--")) {
|
||||||
|
document.body.style.removeProperty(prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function setCustomThemeVars(customTheme) {
|
function setCustomThemeVars(customTheme) {
|
||||||
const {style} = document.body;
|
const {style} = document.body;
|
||||||
|
@ -97,6 +107,7 @@ export async function setTheme(theme) {
|
||||||
const themeWatcher = new ThemeWatcher();
|
const themeWatcher = new ThemeWatcher();
|
||||||
theme = themeWatcher.getEffectiveTheme();
|
theme = themeWatcher.getEffectiveTheme();
|
||||||
}
|
}
|
||||||
|
clearCustomTheme();
|
||||||
let stylesheetName = theme;
|
let stylesheetName = theme;
|
||||||
if (theme.startsWith("custom-")) {
|
if (theme.startsWith("custom-")) {
|
||||||
const customTheme = getCustomTheme(theme.substr(7));
|
const customTheme = getCustomTheme(theme.substr(7));
|
||||||
|
|
Loading…
Reference in a new issue