diff --git a/package.json b/package.json index 7f96abab..82b70710 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "home-assistant-js-websocket": "^5.11.1", "lit-element": "^2.5.1", "lit-html": "^1.4.1", + "lit-transition": "^1.3.2", "zod": "^3.7.1" }, "devDependencies": { diff --git a/src/frigate-card.ts b/src/frigate-card.ts index 98a131fe..4ea12ec4 100644 --- a/src/frigate-card.ts +++ b/src/frigate-card.ts @@ -18,7 +18,9 @@ import { unsafeCSS, } from 'lit-element'; +import { NodePart } from "lit-html"; import { until } from 'lit-html/directives/until.js'; +import { transition } from 'lit-transition'; import { HomeAssistant, fireEvent, @@ -71,25 +73,17 @@ type FrigateCardMenuCallback = (name: string) => any; // A menu for the Frigate card. @customElement('frigate-card-menu') export class FrigateCardMenu extends LitElement { - constructor() { - super(); - this.expand = false; - this.motionEntity = null; - this.hass = null; - this.actionCallback = null; - } + @property({ attribute: false }) + protected expand = false; @property({ attribute: false }) - protected expand: boolean; + protected motionEntity: string | null = null; @property({ attribute: false }) - protected motionEntity: string | null; + protected hass: HomeAssistant | null = null; @property({ attribute: false }) - protected hass: HomeAssistant | null; - - @property({ attribute: false }) - protected actionCallback: FrigateCardMenuCallback | null; + protected actionCallback: FrigateCardMenuCallback | null = null; protected shouldUpdate(changedProps: PropertyValues): boolean { if (!this.hass) { @@ -128,12 +122,13 @@ export class FrigateCardMenu extends LitElement { } // Render the menu. - protected render(): TemplateResult | void { + protected render(): TemplateResult | void | ((part: NodePart) => Promise) { if (!this.expand) { - return html` -
- ${this._renderFrigateButton()} -
`; + return transition( + html` +
+ ${this._renderFrigateButton()} +
`); } let motionIcon: string | null = null; @@ -141,8 +136,11 @@ export class FrigateCardMenu extends LitElement { motionIcon = this.hass.states[this.motionEntity]?.state == "on" ? "mdi:motion-sensor" : "mdi:walk"; } - return html` -
+ return transition( + html` +
${this._renderFrigateButton()} ` }
- `; + ` + ); } // Return compiled CSS styles (thus safe to use with unsafeCSS).