Skip to content
Merged
6 changes: 3 additions & 3 deletions gallery/src/demos/demo-util-long-press.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class DemoUtilLongPress extends LitElement {
() => html`
<ha-card>
<mwc-button
@ha-click="${this._handleTap}"
@ha-click="${this._handleClick}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
.longPress="${longPress({})}"
Comment thread
iantrich marked this conversation as resolved.
Outdated
>
(long) press me!
</mwc-button>
Expand All @@ -28,7 +28,7 @@ export class DemoUtilLongPress extends LitElement {
`;
}

private _handleTap(ev: Event) {
private _handleClick(ev: Event) {
this._addValue(ev, "tap");
}

Expand Down
21 changes: 15 additions & 6 deletions src/panels/lovelace/cards/hui-entity-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { longPress } from "../common/directives/long-press-directive";
import { handleClick } from "../common/handle-click";
import { DOMAINS_TOGGLE } from "../../../common/const";
import { EntityButtonCardConfig } from "./types";
import { hasDoubleClick } from "../common/has-double-click";

@customElement("hui-entity-button-card")
class HuiEntityButtonCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -61,6 +62,7 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard {
this._config = {
theme: "default",
hold_action: { action: "more-info" },
dbltap_action: { action: "none" },
show_icon: true,
show_name: true,
...config,
Expand Down Expand Up @@ -118,9 +120,12 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard {

return html`
<ha-card
@ha-click="${this._handleTap}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(this._config!.dbltap_action),
})}
>
${this._config.show_icon
? html`
Expand Down Expand Up @@ -212,12 +217,16 @@ class HuiEntityButtonCard extends LitElement implements LovelaceCard {
return `hsl(${hue}, 100%, ${100 - sat / 2}%)`;
}

private _handleTap() {
handleClick(this, this.hass!, this._config!, false);
private _handleClick() {
handleClick(this, this.hass!, this._config!, false, false);
}

private _handleHold() {
handleClick(this, this.hass!, this._config!, true);
handleClick(this, this.hass!, this._config!, true, false);
}

private _handleDblClick() {
handleClick(this, this.hass!, this._config!, false, true);
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/panels/lovelace/cards/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { longPress } from "../common/directives/long-press-directive";
import { processConfigEntities } from "../common/process-config-entities";
import { handleClick } from "../common/handle-click";
import { GlanceCardConfig, GlanceConfigEntity } from "./types";
import { hasDoubleClick } from "../common/has-double-click";

@customElement("hui-glance-card")
export class HuiGlanceCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -183,9 +184,12 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
<div
class="entity"
.entityConf="${entityConf}"
@ha-click="${this._handleTap}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(entityConf.dbltap_action),
})}
>
${this._config!.show_name !== false
? html`
Expand Down Expand Up @@ -226,14 +230,19 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
`;
}

private _handleTap(ev: MouseEvent): void {
private _handleClick(ev: MouseEvent): void {
const config = (ev.currentTarget as any).entityConf as GlanceConfigEntity;
handleClick(this, this.hass!, config, false);
handleClick(this, this.hass!, config, false, false);
}

private _handleHold(ev: MouseEvent): void {
const config = (ev.currentTarget as any).entityConf as GlanceConfigEntity;
handleClick(this, this.hass!, config, true);
handleClick(this, this.hass!, config, true, false);
}

private _handleDblClick(ev: MouseEvent): void {
const config = (ev.currentTarget as any).entityConf as GlanceConfigEntity;
handleClick(this, this.hass!, config, false, true);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/cards/hui-light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
filter: this._computeBrightness(stateObj),
color: this._computeColor(stateObj),
})}"
@click="${this._handleTap}"
@click="${this._handleClick}"
></ha-icon>
</div>

<div id="tooltip">
<div class="brightness" @ha-click="${this._handleTap}">
<div class="brightness" @ha-click="${this._handleClick}">
${brightness} %
</div>
<div class="name">
Expand Down Expand Up @@ -297,7 +297,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
return `hsl(${hue}, 100%, ${100 - sat / 2}%)`;
}

private _handleTap() {
private _handleClick() {
toggleEntity(this.hass!, this._config!.entity!);
}

Expand Down
20 changes: 14 additions & 6 deletions src/panels/lovelace/cards/hui-picture-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { classMap } from "lit-html/directives/class-map";
import { handleClick } from "../common/handle-click";
import { longPress } from "../common/directives/long-press-directive";
import { PictureCardConfig } from "./types";
import { hasDoubleClick } from "../common/has-double-click";

@customElement("hui-picture-card")
export class HuiPictureCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -55,9 +56,12 @@ export class HuiPictureCard extends LitElement implements LovelaceCard {

return html`
<ha-card
@ha-click="${this._handleTap}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(this._config!.dbltap_action),
})}
class="${classMap({
clickable: Boolean(
this._config.tap_action || this._config.hold_action
Expand Down Expand Up @@ -86,12 +90,16 @@ export class HuiPictureCard extends LitElement implements LovelaceCard {
`;
}

private _handleTap() {
handleClick(this, this.hass!, this._config!, false);
private _handleClick() {
handleClick(this, this.hass!, this._config!, false, false);
}

private _handleHold() {
handleClick(this, this.hass!, this._config!, true);
handleClick(this, this.hass!, this._config!, true, false);
}

private _handleDblClick() {
handleClick(this, this.hass!, this._config!, false, true);
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/panels/lovelace/cards/hui-picture-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { handleClick } from "../common/handle-click";
import { UNAVAILABLE } from "../../../data/entity";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { PictureEntityCardConfig } from "./types";
import { hasDoubleClick } from "../common/has-double-click";

@customElement("hui-picture-entity-card")
class HuiPictureEntityCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -124,9 +125,12 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
.cameraView=${this._config.camera_view}
.entity=${this._config.entity}
.aspectRatio=${this._config.aspect_ratio}
@ha-click=${this._handleTap}
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
.longPress=${longPress()}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(this._config!.dbltap_action),
})}
class=${classMap({
clickable: stateObj.state !== UNAVAILABLE,
})}
Expand Down Expand Up @@ -177,12 +181,16 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
`;
}

private _handleTap() {
handleClick(this, this.hass!, this._config!, false);
private _handleClick() {
handleClick(this, this.hass!, this._config!, false, false);
}

private _handleHold() {
handleClick(this, this.hass!, this._config!, true);
handleClick(this, this.hass!, this._config!, true, false);
}

private _handleDblClick() {
handleClick(this, this.hass!, this._config!, false, true);
}
}

Expand Down
26 changes: 19 additions & 7 deletions src/panels/lovelace/cards/hui-picture-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { longPress } from "../common/directives/long-press-directive";
import { processConfigEntities } from "../common/process-config-entities";
import { handleClick } from "../common/handle-click";
import { PictureGlanceCardConfig, ConfigEntity } from "./types";
import { hasDoubleClick } from "../common/has-double-click";

const STATES_OFF = new Set(["closed", "locked", "not_home", "off"]);

Expand Down Expand Up @@ -133,9 +134,12 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
this._config.camera_image
),
})}
@ha-click=${this._handleTap}
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
.longPress=${longPress()}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(this._config!.dbltap_action),
})}
.config=${this._config}
.hass=${this.hass}
.image=${this._config.image}
Expand Down Expand Up @@ -192,9 +196,12 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {

return html`
<ha-icon
@ha-click=${this._handleTap}
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
.longPress=${longPress()}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(entityConf.dbltap_action),
})}
.config=${entityConf}
class="${classMap({
"state-on": !STATES_OFF.has(stateObj.state),
Expand All @@ -211,14 +218,19 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
`;
}

private _handleTap(ev: MouseEvent): void {
private _handleClick(ev: MouseEvent): void {
const config = (ev.currentTarget as any).config as any;
handleClick(this, this.hass!, config, false);
handleClick(this, this.hass!, config, false, false);
}

private _handleHold(ev: MouseEvent): void {
const config = (ev.currentTarget as any).config as any;
handleClick(this, this.hass!, config, true);
handleClick(this, this.hass!, config, true, false);
}

private _handleDblClick(ev: MouseEvent): void {
const config = (ev.currentTarget as any).entityConf as any;
handleClick(this, this.hass!, config, false, true);
}

static get styles(): CSSResult {
Expand Down
5 changes: 5 additions & 0 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface EntityButtonCardConfig extends LovelaceCardConfig {
theme?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
}

export interface EntityFilterCardConfig extends LovelaceCardConfig {
Expand Down Expand Up @@ -80,6 +81,7 @@ export interface GaugeCardConfig extends LovelaceCardConfig {
export interface ConfigEntity extends EntityConfig {
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
}

export interface GlanceConfigEntity extends ConfigEntity {
Expand Down Expand Up @@ -136,6 +138,7 @@ export interface PictureCardConfig extends LovelaceCardConfig {
image?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
}

export interface PictureElementsCardConfig extends LovelaceCardConfig {
Expand All @@ -161,6 +164,7 @@ export interface PictureEntityCardConfig extends LovelaceCardConfig {
aspect_ratio?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
show_name?: boolean;
show_state?: boolean;
}
Expand All @@ -177,6 +181,7 @@ export interface PictureGlanceCardConfig extends LovelaceCardConfig {
entity?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
}

export interface PlantAttributeTarget extends EventTarget {
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/common/compute-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Config extends LovelaceElementConfig {
title?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
dbltap_action?: ActionConfig;
}

export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
Expand Down
Loading