mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 18:56:39 +00:00
Fix initial theming (#18296)
This commit is contained in:
parent
16766f8878
commit
ce11301516
@ -41,9 +41,7 @@ export const applyThemesOnElement = (
|
|||||||
// If there is no explicitly desired dark mode provided, we automatically
|
// If there is no explicitly desired dark mode provided, we automatically
|
||||||
// use the active one from `themes`.
|
// use the active one from `themes`.
|
||||||
const darkMode =
|
const darkMode =
|
||||||
themeSettings && themeSettings?.dark !== undefined
|
themeSettings?.dark !== undefined ? themeSettings.dark : themes.darkMode;
|
||||||
? themeSettings?.dark
|
|
||||||
: themes.darkMode;
|
|
||||||
|
|
||||||
let cacheKey = themeToApply;
|
let cacheKey = themeToApply;
|
||||||
let themeRules: Partial<ThemeVars> = {};
|
let themeRules: Partial<ThemeVars> = {};
|
||||||
@ -135,10 +133,19 @@ export const applyThemesOnElement = (
|
|||||||
|
|
||||||
// Set and/or reset styles
|
// Set and/or reset styles
|
||||||
if (element.updateStyles) {
|
if (element.updateStyles) {
|
||||||
|
// Use updateStyles() method of Polymer elements
|
||||||
element.updateStyles(styles);
|
element.updateStyles(styles);
|
||||||
} else if (window.ShadyCSS) {
|
} else if (window.ShadyCSS) {
|
||||||
// Implement updateStyles() method of Polymer elements
|
// Use ShadyCSS if available
|
||||||
window.ShadyCSS.styleSubtree(/** @type {!HTMLElement} */ element, styles);
|
window.ShadyCSS.styleSubtree(/** @type {!HTMLElement} */ element, styles);
|
||||||
|
} else {
|
||||||
|
for (const s in styles) {
|
||||||
|
if (s === null) {
|
||||||
|
element.style.removeProperty(s);
|
||||||
|
} else {
|
||||||
|
element.style.setProperty(s, styles[s]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
let themeSettings: Partial<HomeAssistant["selectedTheme"]> =
|
let themeSettings: Partial<HomeAssistant["selectedTheme"]> =
|
||||||
this.hass!.selectedTheme;
|
this.hass.selectedTheme;
|
||||||
|
|
||||||
const themeName =
|
const themeName =
|
||||||
themeSettings?.theme ||
|
themeSettings?.theme ||
|
||||||
@ -80,7 +80,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
: this.hass.themes.default_theme);
|
: this.hass.themes.default_theme);
|
||||||
|
|
||||||
let darkMode =
|
let darkMode =
|
||||||
themeSettings?.dark === undefined ? darkPreferred : themeSettings?.dark;
|
themeSettings?.dark === undefined ? darkPreferred : themeSettings.dark;
|
||||||
|
|
||||||
const selectedTheme = themeName
|
const selectedTheme = themeName
|
||||||
? this.hass.themes.themes[themeName]
|
? this.hass.themes.themes[themeName]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user