Move lovelace background settings to theme (#3561)

* Move lovelace background settings to theme

While being backwards compatible

* Also update cast
This commit is contained in:
Bram Kragten 2019-09-03 13:13:29 +02:00 committed by GitHub
parent b37a0e2d43
commit 753e069323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 6 deletions

View File

@ -57,10 +57,16 @@ class HcLovelace extends LitElement {
const index = this._viewIndex; const index = this._viewIndex;
if (index !== undefined) { if (index !== undefined) {
this.shadowRoot!.querySelector("hui-view")!.style.background = const configBackground =
this.lovelaceConfig.views[index].background || this.lovelaceConfig.views[index].background ||
this.lovelaceConfig.background || this.lovelaceConfig.background;
"";
if (configBackground) {
this.shadowRoot!.querySelector("hui-view")!.style.setProperty(
"--lovelace-background",
configBackground
);
}
} }
} }
} }

View File

@ -568,7 +568,12 @@ class HUIRoot extends LitElement {
unusedEntities.hass = this.hass!; unusedEntities.hass = this.hass!;
} }
); );
root.style.background = this.config.background || ""; if (this.config.background) {
unusedEntities.style.setProperty(
"--lovelace-background",
this.config.background
);
}
root.append(unusedEntities); root.append(unusedEntities);
return; return;
} }
@ -597,8 +602,13 @@ class HUIRoot extends LitElement {
} }
view.hass = this.hass; view.hass = this.hass;
root.style.background =
viewConfig.background || this.config.background || ""; const configBackground = viewConfig.background || this.config.background;
if (configBackground) {
view.style.setProperty("--lovelace-background", configBackground);
}
root.append(view); root.append(view);
} }
} }

View File

@ -56,6 +56,9 @@ export class HuiUnusedEntities extends LitElement {
private renderStyle(): TemplateResult { private renderStyle(): TemplateResult {
return html` return html`
<style> <style>
:host {
background: var(--lovelace-background);
}
#root { #root {
padding: 4px; padding: 4px;
display: flex; display: flex;

View File

@ -121,6 +121,7 @@ export class HUIView extends LitElement {
padding: 4px 4px 0; padding: 4px 4px 0;
transform: translateZ(0); transform: translateZ(0);
position: relative; position: relative;
background: var(--lovelace-background);
} }
#badges { #badges {