mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Implement show_empty functionality for the markdown card (#21379)
* Implement show_empty functionality * Implement show_empty functionality * import fireEvent * Order imports correctly * Lint with prettier * Unhide card when appropriate * only run show code if card is hidden * Commit coderabbit code cleanup Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * linting --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
0aa25dbed9
commit
dbd84901f8
@ -9,6 +9,7 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
@ -113,7 +114,15 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
|
|||||||
if (changedProps.has("_config")) {
|
if (changedProps.has("_config")) {
|
||||||
this._tryConnect();
|
this._tryConnect();
|
||||||
}
|
}
|
||||||
|
const shouldBeHidden =
|
||||||
|
this._templateResult &&
|
||||||
|
this._config.show_empty === false &&
|
||||||
|
this._templateResult.result.length === 0;
|
||||||
|
if (shouldBeHidden !== this.hidden) {
|
||||||
|
this.style.display = shouldBeHidden ? "none" : "block";
|
||||||
|
this.toggleAttribute("hidden", shouldBeHidden);
|
||||||
|
fireEvent(this, "card-visibility-changed", { value: !shouldBeHidden });
|
||||||
|
}
|
||||||
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
||||||
const oldConfig = changedProps.get("_config") as
|
const oldConfig = changedProps.get("_config") as
|
||||||
| MarkdownCardConfig
|
| MarkdownCardConfig
|
||||||
|
@ -316,6 +316,7 @@ export interface MarkdownCardConfig extends LovelaceCardConfig {
|
|||||||
card_size?: number;
|
card_size?: number;
|
||||||
entity_ids?: string | string[];
|
entity_ids?: string | string[];
|
||||||
theme?: string;
|
theme?: string;
|
||||||
|
show_empty?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MediaControlCardConfig extends LovelaceCardConfig {
|
export interface MediaControlCardConfig extends LovelaceCardConfig {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user