Pass narrow to masonry view to calc columns (#7454)

This commit is contained in:
Bram Kragten 2020-10-22 23:29:26 +02:00 committed by GitHub
parent 6aff35196d
commit 9fbc94e8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

View File

@ -89,6 +89,7 @@ export interface LovelaceViewConfig {
export interface LovelaceViewElement extends HTMLElement {
hass?: HomeAssistant;
lovelace?: Lovelace;
narrow?: boolean;
index?: number;
cards?: Array<LovelaceCard | HuiErrorCard>;
badges?: LovelaceBadge[];

View File

@ -490,6 +490,10 @@ class HUIRoot extends LitElement {
huiView.hass = this.hass;
}
if (changedProperties.has("narrow") && huiView) {
huiView.narrow = this.narrow;
}
let newSelectView;
let force = false;
@ -753,6 +757,7 @@ class HUIRoot extends LitElement {
view.lovelace = this.lovelace;
view.hass = this.hass;
view.narrow = this.narrow;
const configBackground = viewConfig.background || this.config.background;

View File

@ -49,6 +49,8 @@ export class MasonryView extends LitElement implements LovelaceViewElement {
@property({ attribute: false }) public lovelace?: Lovelace;
@property({ type: Boolean }) public narrow!: boolean;
@property({ type: Number }) public index?: number;
@property({ attribute: false }) public cards: Array<
@ -128,6 +130,10 @@ export class MasonryView extends LitElement implements LovelaceViewElement {
}
}
if (changedProperties.has("narrow")) {
this._updateColumns();
}
const oldLovelace = changedProperties.get("lovelace") as
| Lovelace
| undefined;
@ -252,7 +258,8 @@ export class MasonryView extends LitElement implements LovelaceViewElement {
// Do -1 column if the menu is docked and open
this._columns = Math.max(
1,
matchColumns - Number(this.hass!.dockedSidebar === "docked")
matchColumns -
Number(!this.narrow && this.hass!.dockedSidebar === "docked")
);
}

View File

@ -31,6 +31,8 @@ export class HUIView extends UpdatingElement {
@property({ attribute: false }) public lovelace?: Lovelace;
@property({ type: Boolean }) public narrow!: boolean;
@property({ type: Number }) public index?: number;
@internalProperty() private _cards: Array<LovelaceCard | HuiErrorCard> = [];
@ -111,6 +113,7 @@ export class HUIView extends UpdatingElement {
this._createCards(viewConfig!);
this._layoutElement!.hass = this.hass;
this._layoutElement!.narrow = this.narrow;
this._layoutElement!.lovelace = lovelace;
this._layoutElement!.index = this.index;
}
@ -127,6 +130,10 @@ export class HUIView extends UpdatingElement {
this._layoutElement!.hass = this.hass;
}
if (changedProperties.has("narrow")) {
this._layoutElement!.narrow = this.narrow;
}
if (editModeChanged) {
this._layoutElement!.lovelace = lovelace;
}