Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use layout property for panel view #21418

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/panels/lovelace/cards/hui-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ declare global {
export class HuiCard extends ReactiveElement {
@property({ type: Boolean }) public preview = false;

@property({ attribute: false }) public isPanel = false;

@property({ attribute: false }) public config?: LovelaceCardConfig;

@property({ attribute: false }) public hass?: HomeAssistant;
Expand Down Expand Up @@ -178,11 +176,14 @@ export class HuiCard extends ReactiveElement {
this._loadElement(createErrorCardConfig(e.message, null));
}
}
if (changedProps.has("isPanel")) {
this._element.isPanel = this.isPanel;
}
if (changedProps.has("layout")) {
this._element.layout = this.layout;
try {
this._element.layout = this.layout;
// For backwards compatibility
(this._element as any).isPanel = this.layout === "panel";
} catch (e: any) {
this._loadElement(createErrorCardConfig(e.message, null));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/cards/hui-entity-filter-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class HuiEntityFilterCard

@property({ attribute: false }) public hass?: HomeAssistant;

@property({ type: Boolean }) public isPanel = false;
@property({ attribute: false }) public layout?: string;

@property({ type: Boolean }) public preview = false;

Expand Down Expand Up @@ -118,7 +118,7 @@ export class HuiEntityFilterCard
if (this._element) {
this._element.hass = this.hass;
this._element.preview = this.preview;
this._element.isPanel = this.isPanel;
this._element.layout = this.layout;
}

if (changedProps.has("_config")) {
Expand Down
5 changes: 1 addition & 4 deletions src/panels/lovelace/cards/hui-iframe-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
};
}

@property({ type: Boolean, reflect: true })
public isPanel = false;

@property({ attribute: false })
public layout?: string;

Expand Down Expand Up @@ -63,7 +60,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
}

let padding = "";
const ignoreAspectRatio = this.isPanel || this.layout === "grid";
const ignoreAspectRatio = this.layout === "panel" || this.layout === "grid";
if (!ignoreAspectRatio) {
if (this._config.aspect_ratio) {
const ratio = parseAspectRatio(this._config.aspect_ratio);
Expand Down
8 changes: 2 additions & 6 deletions src/panels/lovelace/cards/hui-map-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ interface MapEntityConfig extends EntityConfig {
class HuiMapCard extends LitElement implements LovelaceCard {
@property({ attribute: false }) public hass!: HomeAssistant;

@property({ type: Boolean, reflect: true })
public isPanel = false;

@property({ attribute: false })
public layout?: string;
@property({ attribute: false }) public layout?: string;

@state() private _stateHistory?: HistoryStates;

Expand Down Expand Up @@ -301,7 +297,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
private _computePadding(): void {
const root = this.shadowRoot!.getElementById("root");

const ignoreAspectRatio = this.isPanel || this.layout === "grid";
const ignoreAspectRatio = this.layout === "panel" || this.layout === "grid";
piitaya marked this conversation as resolved.
Show resolved Hide resolved
if (!this._config || ignoreAspectRatio || !root) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/panels/lovelace/cards/hui-stack-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export abstract class HuiStackCard<T extends StackCardConfig = StackCardConfig>

@state() protected _config?: T;

@property({ type: Boolean, reflect: true })
public isPanel = false;
@property({ attribute: false }) public layout?: string;

public getCardSize(): number | Promise<number> {
return 1;
Expand Down Expand Up @@ -62,6 +61,10 @@ export abstract class HuiStackCard<T extends StackCardConfig = StackCardConfig>
});
}
}

if (changedProperties.has("layout")) {
this.toggleAttribute("ispanel", this.layout === "panel");
}
}

private _createCardElement(cardConfig: LovelaceCardConfig) {
Expand Down
1 change: 0 additions & 1 deletion src/panels/lovelace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export type LovelaceLayoutOptions = {

export interface LovelaceCard extends HTMLElement {
hass?: HomeAssistant;
isPanel?: boolean;
preview?: boolean;
layout?: string;
getCardSize(): number | Promise<number>;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/views/hui-panel-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class PanelView extends LitElement implements LovelaceViewElement {
}

const card: HuiCard = this.cards[0];
card.isPanel = true;
card.layout = "panel";

if (this.isStrategy || !this.lovelace?.editMode) {
card.preview = false;
Expand Down
Loading