Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gallery/src/demos/demo-util-long-press.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DemoUtilLongPress extends LitElement {
() => html`
<ha-card>
<mwc-button
@ha-click="${this._handleTap}"
@ha-click="${this._handleClick}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
>
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
4 changes: 4 additions & 0 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ export const getLovelaceCollection = (conn: Connection) =>
export interface WindowWithLovelaceProm extends Window {
llConfProm?: Promise<LovelaceConfig>;
}

export interface LongPressOptions {
hasDoubleClick?: boolean;
}
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" },
double_tap_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!.double_tap_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.double_tap_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!.double_tap_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!.double_tap_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 @@ -25,6 +25,7 @@ import { HomeAssistant } from "../../../types";
import { longPress } from "../common/directives/long-press-directive";
import { processConfigEntities } from "../common/process-config-entities";
import { handleClick } from "../common/handle-click";
import { hasDoubleClick } from "../common/has-double-click";
import { PictureGlanceCardConfig, PictureGlanceEntityConfig } from "./types";
import { hasConfigOrEntityChanged } from "../common/has-changed";

Expand Down Expand Up @@ -130,9 +131,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!.double_tap_action),
})}
.config=${this._config}
.hass=${this.hass}
.image=${this._config.image}
Expand Down Expand Up @@ -190,9 +194,12 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
return html`
<div class="wrapper">
<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.double_tap_action),
})}
.config=${entityConf}
class="${classMap({
"state-on": !STATES_OFF.has(stateObj.state),
Expand Down Expand Up @@ -223,14 +230,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;
double_tap_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;
double_tap_action?: ActionConfig;
}

export interface PictureGlanceEntityConfig extends ConfigEntity {
Expand Down Expand Up @@ -141,6 +143,7 @@ export interface PictureCardConfig extends LovelaceCardConfig {
image?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
}

export interface PictureElementsCardConfig extends LovelaceCardConfig {
Expand All @@ -166,6 +169,7 @@ export interface PictureEntityCardConfig extends LovelaceCardConfig {
aspect_ratio?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
show_name?: boolean;
show_state?: boolean;
}
Expand All @@ -182,6 +186,7 @@ export interface PictureGlanceCardConfig extends LovelaceCardConfig {
entity?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
show_state?: boolean;
}

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;
double_tap_action?: ActionConfig;
}

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