mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Fix theme setting (#11977)
This commit is contained in:
parent
e9003ac35e
commit
d1085b6657
@ -78,6 +78,9 @@ class DemoCards extends LitElement {
|
|||||||
ha-formfield {
|
ha-formfield {
|
||||||
margin-right: 16px;
|
margin-right: 16px;
|
||||||
}
|
}
|
||||||
|
#container {
|
||||||
|
background-color: var(--primary-background-color);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,8 @@ export class HassioMain extends SupervisorBaseElement {
|
|||||||
this.parentElement,
|
this.parentElement,
|
||||||
this.hass.themes,
|
this.hass.themes,
|
||||||
themeName,
|
themeName,
|
||||||
themeSettings
|
themeSettings,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,13 +101,19 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
this._fetchAuthProviders();
|
this._fetchAuthProviders();
|
||||||
|
|
||||||
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
applyThemesOnElement(document.documentElement, {
|
applyThemesOnElement(
|
||||||
default_theme: "default",
|
document.documentElement,
|
||||||
default_dark_theme: null,
|
{
|
||||||
themes: {},
|
default_theme: "default",
|
||||||
darkMode: true,
|
default_dark_theme: null,
|
||||||
theme: "default",
|
themes: {},
|
||||||
});
|
darkMode: true,
|
||||||
|
theme: "default",
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.redirectUri) {
|
if (!this.redirectUri) {
|
||||||
|
@ -31,11 +31,12 @@ export const applyThemesOnElement = (
|
|||||||
element,
|
element,
|
||||||
themes: HomeAssistant["themes"],
|
themes: HomeAssistant["themes"],
|
||||||
selectedTheme?: string,
|
selectedTheme?: string,
|
||||||
themeSettings?: Partial<HomeAssistant["selectedTheme"]>
|
themeSettings?: Partial<HomeAssistant["selectedTheme"]>,
|
||||||
|
main?: boolean
|
||||||
) => {
|
) => {
|
||||||
// If there is no explicitly desired theme provided, we automatically
|
// If there is no explicitly desired theme provided, and the element is the main element we automatically
|
||||||
// use the active one from `themes`.
|
// use the active one from `themes`.
|
||||||
const themeToApply = selectedTheme || themes.theme;
|
const themeToApply = selectedTheme || (main ? themes.theme : undefined);
|
||||||
|
|
||||||
// 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`.
|
||||||
@ -47,7 +48,7 @@ export const applyThemesOnElement = (
|
|||||||
let cacheKey = themeToApply;
|
let cacheKey = themeToApply;
|
||||||
let themeRules: Partial<ThemeVars> = {};
|
let themeRules: Partial<ThemeVars> = {};
|
||||||
|
|
||||||
if (darkMode) {
|
if (themeToApply && darkMode) {
|
||||||
cacheKey = `${cacheKey}__dark`;
|
cacheKey = `${cacheKey}__dark`;
|
||||||
themeRules = { ...darkStyles };
|
themeRules = { ...darkStyles };
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,9 @@ export const provideHass = (
|
|||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
document.documentElement,
|
document.documentElement,
|
||||||
themes,
|
themes,
|
||||||
selectedTheme!.theme
|
selectedTheme!.theme,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -101,7 +101,8 @@ class SupervisorErrorScreen extends LitElement {
|
|||||||
this.parentElement,
|
this.parentElement,
|
||||||
this.hass.themes,
|
this.hass.themes,
|
||||||
themeName,
|
themeName,
|
||||||
themeSettings
|
themeSettings,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +133,19 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) {
|
|||||||
import("./particles");
|
import("./particles");
|
||||||
}
|
}
|
||||||
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
applyThemesOnElement(document.documentElement, {
|
applyThemesOnElement(
|
||||||
default_theme: "default",
|
document.documentElement,
|
||||||
default_dark_theme: null,
|
{
|
||||||
themes: {},
|
default_theme: "default",
|
||||||
darkMode: true,
|
default_dark_theme: null,
|
||||||
theme: "default",
|
themes: {},
|
||||||
});
|
darkMode: true,
|
||||||
|
theme: "default",
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +38,19 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
});
|
});
|
||||||
mql.addListener((ev) => this._applyTheme(ev.matches));
|
mql.addListener((ev) => this._applyTheme(ev.matches));
|
||||||
if (!this._themeApplied && mql.matches) {
|
if (!this._themeApplied && mql.matches) {
|
||||||
applyThemesOnElement(document.documentElement, {
|
applyThemesOnElement(
|
||||||
default_theme: "default",
|
document.documentElement,
|
||||||
default_dark_theme: null,
|
{
|
||||||
themes: {},
|
default_theme: "default",
|
||||||
darkMode: true,
|
default_dark_theme: null,
|
||||||
theme: "default",
|
themes: {},
|
||||||
});
|
darkMode: true,
|
||||||
|
theme: "default",
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +99,8 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
document.documentElement,
|
document.documentElement,
|
||||||
this.hass.themes,
|
this.hass.themes,
|
||||||
themeName,
|
themeName,
|
||||||
themeSettings
|
themeSettings,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
if (darkMode !== this.hass.themes.darkMode) {
|
if (darkMode !== this.hass.themes.darkMode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user