forked from mystiq/hydrogen-web
Move code to ThemeLoader
This commit is contained in:
parent
654e83a5f9
commit
0984aeb570
2 changed files with 4 additions and 15 deletions
|
@ -316,15 +316,6 @@ export class Platform {
|
||||||
return this._themeLoader;
|
return this._themeLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
get preferredColorScheme() {
|
|
||||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
||||||
return COLOR_SCHEME_PREFERENCE.DARK;
|
|
||||||
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
|
||||||
return COLOR_SCHEME_PREFERENCE.LIGHT;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceStylesheet(newPath) {
|
replaceStylesheet(newPath) {
|
||||||
const head = document.querySelector("head");
|
const head = document.querySelector("head");
|
||||||
// remove default theme
|
// remove default theme
|
||||||
|
|
|
@ -64,11 +64,9 @@ export class ThemeLoader {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
// return default theme
|
// return default theme
|
||||||
const preference = this._platform.preferredColorScheme;
|
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
switch (preference) {
|
|
||||||
case COLOR_SCHEME_PREFERENCE.DARK:
|
|
||||||
return this._platform.config["defaultTheme"].dark;
|
return this._platform.config["defaultTheme"].dark;
|
||||||
case COLOR_SCHEME_PREFERENCE.LIGHT:
|
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
||||||
return this._platform.config["defaultTheme"].light;
|
return this._platform.config["defaultTheme"].light;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
Loading…
Reference in a new issue