From e9e45ad1934bdc1787521edc736aaccd5c498a95 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 5 Mar 2024 22:18:22 +0100 Subject: [PATCH] Improve get card size --- src/utils/base-card.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/utils/base-card.ts b/src/utils/base-card.ts index 806d82f1..982a8534 100644 --- a/src/utils/base-card.ts +++ b/src/utils/base-card.ts @@ -42,10 +42,6 @@ export class MushroomBaseCard< return false; } - public getCardSize(): number | Promise { - return 1; - } - setConfig(config: T): void { this._config = { tap_action: { @@ -80,6 +76,23 @@ export class MushroomBaseCard< return [column, row]; } + public getCardSize(): number | Promise { + let height = 1; + if (!this._config) return height; + const appearance = computeAppearance(this._config); + if (appearance.layout === "vertical") { + height += 1; + } + if ( + appearance?.layout !== "horizontal" && + this.hasControls && + !("collapsible_controls" in this._config && this._config?.collapsible_controls) + ) { + height += 1; + } + return height; + } + protected renderPicture(picture: string): TemplateResult { return html`