mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Use layout property for panel view (#21418)
This commit is contained in:
parent
38e7b8c467
commit
6e29b77e94
@ -25,8 +25,6 @@ declare global {
|
|||||||
export class HuiCard extends ReactiveElement {
|
export class HuiCard extends ReactiveElement {
|
||||||
@property({ type: Boolean }) public preview = false;
|
@property({ type: Boolean }) public preview = false;
|
||||||
|
|
||||||
@property({ attribute: false }) public isPanel = false;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public config?: LovelaceCardConfig;
|
@property({ attribute: false }) public config?: LovelaceCardConfig;
|
||||||
|
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
@ -178,11 +176,14 @@ export class HuiCard extends ReactiveElement {
|
|||||||
this._loadElement(createErrorCardConfig(e.message, null));
|
this._loadElement(createErrorCardConfig(e.message, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changedProps.has("isPanel")) {
|
|
||||||
this._element.isPanel = this.isPanel;
|
|
||||||
}
|
|
||||||
if (changedProps.has("layout")) {
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export class HuiEntityFilterCard
|
|||||||
|
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
@property({ type: Boolean }) public isPanel = false;
|
@property({ attribute: false }) public layout?: string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public preview = false;
|
@property({ type: Boolean }) public preview = false;
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ export class HuiEntityFilterCard
|
|||||||
if (this._element) {
|
if (this._element) {
|
||||||
this._element.hass = this.hass;
|
this._element.hass = this.hass;
|
||||||
this._element.preview = this.preview;
|
this._element.preview = this.preview;
|
||||||
this._element.isPanel = this.isPanel;
|
this._element.layout = this.layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProps.has("_config")) {
|
if (changedProps.has("_config")) {
|
||||||
|
@ -29,9 +29,6 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
|
||||||
public isPanel = false;
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public layout?: string;
|
public layout?: string;
|
||||||
|
|
||||||
@ -63,7 +60,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let padding = "";
|
let padding = "";
|
||||||
const ignoreAspectRatio = this.isPanel || this.layout === "grid";
|
const ignoreAspectRatio = this.layout === "panel" || this.layout === "grid";
|
||||||
if (!ignoreAspectRatio) {
|
if (!ignoreAspectRatio) {
|
||||||
if (this._config.aspect_ratio) {
|
if (this._config.aspect_ratio) {
|
||||||
const ratio = parseAspectRatio(this._config.aspect_ratio);
|
const ratio = parseAspectRatio(this._config.aspect_ratio);
|
||||||
|
@ -54,11 +54,7 @@ interface MapEntityConfig extends EntityConfig {
|
|||||||
class HuiMapCard extends LitElement implements LovelaceCard {
|
class HuiMapCard extends LitElement implements LovelaceCard {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ attribute: false }) public layout?: string;
|
||||||
public isPanel = false;
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
|
||||||
public layout?: string;
|
|
||||||
|
|
||||||
@state() private _stateHistory?: HistoryStates;
|
@state() private _stateHistory?: HistoryStates;
|
||||||
|
|
||||||
@ -301,7 +297,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
private _computePadding(): void {
|
private _computePadding(): void {
|
||||||
const root = this.shadowRoot!.getElementById("root");
|
const root = this.shadowRoot!.getElementById("root");
|
||||||
|
|
||||||
const ignoreAspectRatio = this.isPanel || this.layout === "grid";
|
const ignoreAspectRatio = this.layout === "panel" || this.layout === "grid";
|
||||||
if (!this._config || ignoreAspectRatio || !root) {
|
if (!this._config || ignoreAspectRatio || !root) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ export abstract class HuiStackCard<T extends StackCardConfig = StackCardConfig>
|
|||||||
|
|
||||||
@state() protected _config?: T;
|
@state() protected _config?: T;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ attribute: false }) public layout?: string;
|
||||||
public isPanel = false;
|
|
||||||
|
|
||||||
public getCardSize(): number | Promise<number> {
|
public getCardSize(): number | Promise<number> {
|
||||||
return 1;
|
return 1;
|
||||||
@ -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) {
|
private _createCardElement(cardConfig: LovelaceCardConfig) {
|
||||||
|
@ -51,7 +51,6 @@ export type LovelaceLayoutOptions = {
|
|||||||
|
|
||||||
export interface LovelaceCard extends HTMLElement {
|
export interface LovelaceCard extends HTMLElement {
|
||||||
hass?: HomeAssistant;
|
hass?: HomeAssistant;
|
||||||
isPanel?: boolean;
|
|
||||||
preview?: boolean;
|
preview?: boolean;
|
||||||
layout?: string;
|
layout?: string;
|
||||||
getCardSize(): number | Promise<number>;
|
getCardSize(): number | Promise<number>;
|
||||||
|
@ -105,7 +105,7 @@ export class PanelView extends LitElement implements LovelaceViewElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const card: HuiCard = this.cards[0];
|
const card: HuiCard = this.cards[0];
|
||||||
card.isPanel = true;
|
card.layout = "panel";
|
||||||
|
|
||||||
if (this.isStrategy || !this.lovelace?.editMode) {
|
if (this.isStrategy || !this.lovelace?.editMode) {
|
||||||
card.preview = false;
|
card.preview = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user