Skip to content

Commit

Permalink
Improve get card size
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Mar 5, 2024
1 parent 1f87fce commit e9e45ad
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/utils/base-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export class MushroomBaseCard<
return false;
}

public getCardSize(): number | Promise<number> {
return 1;
}

setConfig(config: T): void {
this._config = {
tap_action: {
Expand Down Expand Up @@ -80,6 +76,23 @@ export class MushroomBaseCard<
return [column, row];
}

public getCardSize(): number | Promise<number> {
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`
<mushroom-shape-avatar
Expand Down

0 comments on commit e9e45ad

Please sign in to comment.