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

Implement show_empty functionality for the markdown card #21379

Merged
merged 14 commits into from
Jul 31, 2024
13 changes: 12 additions & 1 deletion src/panels/lovelace/cards/hui-markdown-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../../common/dom/fire_event";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import "../../../components/ha-card";
import "../../../components/ha-markdown";
Expand Down Expand Up @@ -113,7 +114,17 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
if (changedProps.has("_config")) {
this._tryConnect();
}

if (this._templateResult && this._config.show_empty === false) {
if (this._templateResult.result.length === 0 && !this.hidden) {
this.style.display = "none";
this.toggleAttribute("hidden", true);
fireEvent(this, "card-visibility-changed", { value: false });
illuzn marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.style.display = "block";
this.toggleAttribute("hidden", false);
fireEvent(this, "card-visibility-changed", { value: true });
illuzn marked this conversation as resolved.
Show resolved Hide resolved
}
}
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
const oldConfig = changedProps.get("_config") as
| MarkdownCardConfig
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export interface MarkdownCardConfig extends LovelaceCardConfig {
card_size?: number;
entity_ids?: string | string[];
theme?: string;
show_empty?: boolean;
}

export interface MediaControlCardConfig extends LovelaceCardConfig {
Expand Down