mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 13:07:49 +00:00
Align picture-glance
card tap/hold actions (#2187)
Removed unneccessary `force_dialog` config. Updated `handleClick` to use `entity` or `camera_image` for `more-info` dialog
This commit is contained in:
parent
7e584402ea
commit
5947bd6d74
@ -3,37 +3,37 @@ import { classMap } from "lit-html/directives/classMap";
|
|||||||
import { TemplateResult } from "lit-html";
|
import { TemplateResult } from "lit-html";
|
||||||
|
|
||||||
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
|
||||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||||
import { LovelaceCard } from "../types";
|
import { LovelaceCard } from "../types";
|
||||||
import { LovelaceCardConfig } from "../../../data/lovelace";
|
import { LovelaceCardConfig, ActionConfig } from "../../../data/lovelace";
|
||||||
import { EntityConfig } from "../entity-rows/types";
|
import { EntityConfig } from "../entity-rows/types";
|
||||||
import { navigate } from "../../../common/navigate";
|
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { toggleEntity } from "../common/entity/toggle-entity";
|
import { longPress } from "../common/directives/long-press-directive";
|
||||||
|
import { processConfigEntities } from "../common/process-config-entities";
|
||||||
import computeStateDisplay from "../../../common/entity/compute_state_display";
|
import computeStateDisplay from "../../../common/entity/compute_state_display";
|
||||||
import computeStateName from "../../../common/entity/compute_state_name";
|
import computeStateName from "../../../common/entity/compute_state_name";
|
||||||
import { processConfigEntities } from "../common/process-config-entities";
|
|
||||||
import computeDomain from "../../../common/entity/compute_domain";
|
import computeDomain from "../../../common/entity/compute_domain";
|
||||||
import stateIcon from "../../../common/entity/state_icon";
|
import stateIcon from "../../../common/entity/state_icon";
|
||||||
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-icon";
|
import "../../../components/ha-icon";
|
||||||
import "../components/hui-image";
|
import "../components/hui-image";
|
||||||
|
import { handleClick } from "../common/handle-click";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import { toggleEntity } from "../common/entity/toggle-entity";
|
||||||
|
|
||||||
const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]);
|
const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]);
|
||||||
|
|
||||||
interface Config extends LovelaceCardConfig {
|
interface Config extends LovelaceCardConfig {
|
||||||
entities: EntityConfig[];
|
entities: EntityConfig[];
|
||||||
title?: string;
|
title?: string;
|
||||||
navigation_path?: string;
|
|
||||||
image?: string;
|
image?: string;
|
||||||
camera_image?: string;
|
camera_image?: string;
|
||||||
state_image?: {};
|
state_image?: {};
|
||||||
aspect_ratio?: string;
|
aspect_ratio?: string;
|
||||||
entity?: string;
|
entity?: string;
|
||||||
force_dialog?: boolean;
|
tap_action?: ActionConfig;
|
||||||
|
hold_action?: ActionConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HuiPictureGlanceCard extends hassLocalizeLitMixin(LitElement)
|
class HuiPictureGlanceCard extends hassLocalizeLitMixin(LitElement)
|
||||||
@ -88,19 +88,22 @@ class HuiPictureGlanceCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isClickable =
|
|
||||||
this._config.navigation_path || this._config.camera_image;
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${this.renderStyle()}
|
${this.renderStyle()}
|
||||||
<ha-card>
|
<ha-card>
|
||||||
<hui-image
|
<hui-image
|
||||||
class="${
|
class="${
|
||||||
classMap({
|
classMap({
|
||||||
clickable: Boolean(isClickable),
|
clickable: Boolean(
|
||||||
|
this._config.tap_action ||
|
||||||
|
this._config.hold_action ||
|
||||||
|
this._config.camera_image
|
||||||
|
),
|
||||||
})
|
})
|
||||||
}"
|
}"
|
||||||
@click="${this._handleImageClick}"
|
@ha-click="${this._handleTap}"
|
||||||
|
@ha-hold="${this._handleHold}"
|
||||||
|
.longPress="${longPress()}"
|
||||||
.hass="${this.hass}"
|
.hass="${this.hass}"
|
||||||
.image="${this._config.image}"
|
.image="${this._config.image}"
|
||||||
.stateImage="${this._config.state_image}"
|
.stateImage="${this._config.state_image}"
|
||||||
@ -168,6 +171,14 @@ class HuiPictureGlanceCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleTap() {
|
||||||
|
handleClick(this, this.hass!, this._config!, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleHold() {
|
||||||
|
handleClick(this, this.hass!, this._config!, true);
|
||||||
|
}
|
||||||
|
|
||||||
private _openDialog(ev: MouseEvent): void {
|
private _openDialog(ev: MouseEvent): void {
|
||||||
fireEvent(this, "hass-more-info", { entityId: (ev.target as any).entity });
|
fireEvent(this, "hass-more-info", { entityId: (ev.target as any).entity });
|
||||||
}
|
}
|
||||||
@ -176,16 +187,6 @@ class HuiPictureGlanceCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
toggleEntity(this.hass!, (ev.target as any).entity);
|
toggleEntity(this.hass!, (ev.target as any).entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleImageClick(): void {
|
|
||||||
if (this._config!.navigation_path) {
|
|
||||||
navigate(this, this._config!.navigation_path!);
|
|
||||||
} else if (this._config!.camera_image) {
|
|
||||||
fireEvent(this, "hass-more-info", {
|
|
||||||
entityId: this._config!.camera_image!,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private renderStyle(): TemplateResult {
|
private renderStyle(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<style>
|
<style>
|
||||||
|
@ -9,6 +9,7 @@ export const handleClick = (
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: {
|
config: {
|
||||||
entity?: string;
|
entity?: string;
|
||||||
|
camera_image?: string;
|
||||||
hold_action?: ActionConfig;
|
hold_action?: ActionConfig;
|
||||||
tap_action?: ActionConfig;
|
tap_action?: ActionConfig;
|
||||||
},
|
},
|
||||||
@ -30,8 +31,10 @@ export const handleClick = (
|
|||||||
|
|
||||||
switch (actionConfig.action) {
|
switch (actionConfig.action) {
|
||||||
case "more-info":
|
case "more-info":
|
||||||
if (config.entity) {
|
if (config.entity || config.camera_image) {
|
||||||
fireEvent(node, "hass-more-info", { entityId: config.entity });
|
fireEvent(node, "hass-more-info", {
|
||||||
|
entityId: config.entity ? config.entity! : config.camera_image!,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "navigate":
|
case "navigate":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user