Piggyback off click handler from entities card
This commit is contained in:
parent
86d0163ac6
commit
f17ac20fe2
File diff suppressed because one or more lines are too long
25
src/main.js
25
src/main.js
@ -1,5 +1,4 @@
|
|||||||
import { LitElement, html, css } from "/card-tools/lit-element.js";
|
import { LitElement, html, css } from "/card-tools/lit-element.js";
|
||||||
import { moreInfo } from "/card-tools/more-info.js";
|
|
||||||
import { hass } from "/card-tools/hass.js";
|
import { hass } from "/card-tools/hass.js";
|
||||||
import "/card-tools/card-maker.js";
|
import "/card-tools/card-maker.js";
|
||||||
import { DOMAINS_HIDE_MORE_INFO } from "/card-tools/lovelace-element.js";
|
import { DOMAINS_HIDE_MORE_INFO } from "/card-tools/lovelace-element.js";
|
||||||
@ -7,7 +6,7 @@ import { DOMAINS_HIDE_MORE_INFO } from "/card-tools/lovelace-element.js";
|
|||||||
class FoldEntityRow extends LitElement {
|
class FoldEntityRow extends LitElement {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
hass: {},
|
_hass: {},
|
||||||
open: Boolean,
|
open: Boolean,
|
||||||
items: {},
|
items: {},
|
||||||
};
|
};
|
||||||
@ -41,13 +40,13 @@ class FoldEntityRow extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clickRow(ev) {
|
clickRow(ev) {
|
||||||
const config = ev.target.parentElement._config;
|
|
||||||
const entity = config.entity || (typeof config === "string" ? config : null);
|
|
||||||
|
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
if(this.hasMoreInfo(config))
|
|
||||||
moreInfo(entity)
|
const config = ev.target.parentElement._config;
|
||||||
else if(ev.target.parentElement.hasAttribute('head')) {
|
|
||||||
|
if(this.hasMoreInfo(config) || config.tap_action) {
|
||||||
|
customElements.get('hui-entities-card').prototype._handleClick.bind(this)(config);
|
||||||
|
} else if(ev.target.parentElement.hasAttribute('head')) {
|
||||||
this.toggle(ev);
|
this.toggle(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,9 +77,13 @@ class FoldEntityRow extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set hass(hass) {
|
||||||
|
this._hass = hass;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this._entities)
|
if (this._entities)
|
||||||
this._entities.forEach((e) => e.hass = this.hass);
|
this._entities.forEach((e) => e.hass = this._hass);
|
||||||
|
|
||||||
const fix_config = (config) => {
|
const fix_config = (config) => {
|
||||||
if(typeof config === "string")
|
if(typeof config === "string")
|
||||||
@ -92,7 +95,7 @@ class FoldEntityRow extends LitElement {
|
|||||||
<div id="head" ?open=${this.open}>
|
<div id="head" ?open=${this.open}>
|
||||||
<entity-row-maker
|
<entity-row-maker
|
||||||
.config=${this.head}
|
.config=${this.head}
|
||||||
.hass=${this.hass}
|
.hass=${this._hass}
|
||||||
@click=${this.clickRow}
|
@click=${this.clickRow}
|
||||||
head
|
head
|
||||||
></entity-row-maker>
|
></entity-row-maker>
|
||||||
@ -113,7 +116,7 @@ class FoldEntityRow extends LitElement {
|
|||||||
${this.items.map(i => html`
|
${this.items.map(i => html`
|
||||||
<entity-row-maker
|
<entity-row-maker
|
||||||
.config=${fix_config(i)}
|
.config=${fix_config(i)}
|
||||||
.hass=${this.hass}
|
.hass=${this._hass}
|
||||||
@click=${this.clickRow}
|
@click=${this.clickRow}
|
||||||
class=${this.hasMoreInfo(i) ? 'state-card-dialog' : ''}
|
class=${this.hasMoreInfo(i) ? 'state-card-dialog' : ''}
|
||||||
></entity-row-maker>
|
></entity-row-maker>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user