Add hold action to buttons (#7051)

This commit is contained in:
Bram Kragten 2020-09-18 17:20:31 +02:00 committed by GitHub
parent 4bb51b0120
commit 24f3db3e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -85,12 +85,7 @@ export class HuiButtonsBase extends LitElement {
private _handleAction(ev: ActionHandlerEvent) {
const config = (ev.currentTarget as any).config as EntitiesCardEntityConfig;
handleAction(
this,
this._hass!,
{ tap_action: { action: "toggle" }, ...config },
ev.detail.action!
);
handleAction(this, this._hass!, config, ev.detail.action!);
}
static get styles(): CSSResult {

View File

@ -4,6 +4,7 @@ import {
LitElement,
property,
TemplateResult,
internalProperty,
} from "lit-element";
import { HomeAssistant } from "../../../types";
import { processConfigEntities } from "../common/process-config-entities";
@ -21,15 +22,20 @@ export class HuiButtonsHeaderFooter extends LitElement
@property({ attribute: false }) public hass?: HomeAssistant;
private _configEntities?: EntityConfig[];
@internalProperty() private _configEntities?: EntityConfig[];
public getCardSize(): number {
return 1;
}
public setConfig(config: ButtonsHeaderFooterConfig): void {
this._configEntities = processConfigEntities(config.entities);
this.requestUpdate();
this._configEntities = processConfigEntities(config.entities).map(
(entityConfig) => ({
tap_action: { action: "toggle" },
hold_action: { action: "more-info" },
...entityConfig,
})
);
}
protected render(): TemplateResult | void {

View File

@ -4,6 +4,7 @@ import {
LitElement,
property,
TemplateResult,
internalProperty,
} from "lit-element";
import { HomeAssistant } from "../../../types";
import { processConfigEntities } from "../common/process-config-entities";
@ -22,11 +23,16 @@ export class HuiButtonsRow extends LitElement implements LovelaceRow {
@property({ attribute: false }) public hass?: HomeAssistant;
private _configEntities?: EntityConfig[];
@internalProperty() private _configEntities?: EntityConfig[];
public setConfig(config: ButtonsRowConfig): void {
this._configEntities = processConfigEntities(config.entities);
this.requestUpdate();
this._configEntities = processConfigEntities(config.entities).map(
(entityConfig) => ({
tap_action: { action: "toggle" },
hold_action: { action: "more-info" },
...entityConfig,
})
);
}
protected render(): TemplateResult | void {