mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 10:56:34 +00:00
Fix stack card getSize (#1856)
This commit is contained in:
parent
5e61065b64
commit
8c7b62509b
@ -12,6 +12,7 @@ interface Config extends LovelaceConfig {
|
|||||||
|
|
||||||
class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
||||||
protected config?: Config;
|
protected config?: Config;
|
||||||
|
private _cards?: LovelaceCard[];
|
||||||
private _hass?: HomeAssistant;
|
private _hass?: HomeAssistant;
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
@ -22,15 +23,24 @@ class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
set hass(hass: HomeAssistant) {
|
set hass(hass: HomeAssistant) {
|
||||||
this._hass = hass;
|
this._hass = hass;
|
||||||
for (const el of this.shadowRoot!.querySelectorAll("#root > *")) {
|
|
||||||
const element = el as LovelaceCard;
|
if (!this._cards) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const element of this._cards) {
|
||||||
element.hass = this._hass;
|
element.hass = this._hass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCardSize() {
|
public getCardSize() {
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
for (const element of this.shadowRoot!.querySelectorAll("#root > *")) {
|
|
||||||
|
if (!this._cards) {
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const element of this._cards) {
|
||||||
totalSize += computeCardSize(element);
|
totalSize += computeCardSize(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +52,11 @@ class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
|||||||
throw new Error("Card config incorrect");
|
throw new Error("Card config incorrect");
|
||||||
}
|
}
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this._cards = config.cards.map((card) => {
|
||||||
|
const element = createCardElement(card) as LovelaceCard;
|
||||||
|
element.hass = this._hass;
|
||||||
|
return element;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -52,7 +67,7 @@ class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
|||||||
return html`
|
return html`
|
||||||
${this.renderStyle()}
|
${this.renderStyle()}
|
||||||
<div id="root">
|
<div id="root">
|
||||||
${this.config.cards.map((card) => this.createCardElement(card))}
|
${this._cards!}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -76,12 +91,6 @@ class HuiVerticalStackCard extends LitElement implements LovelaceCard {
|
|||||||
</style>
|
</style>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createCardElement(card: LovelaceConfig): LovelaceCard {
|
|
||||||
const element = createCardElement(card) as LovelaceCard;
|
|
||||||
element.hass = this._hass;
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user