Add selectors for text and arbitrary objects (#8152)

This commit is contained in:
Thomas Lovén
2021-01-27 11:45:51 +01:00
committed by GitHub
parent e69f36047d
commit 5c0e151bc2
4 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
import { customElement, html, LitElement, property } from "lit-element";
import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types";
import "../ha-yaml-editor";
@customElement("ha-selector-object")
export class HaObjectSelector extends LitElement {
@property() public hass!: HomeAssistant;
@property() public value?: any;
@property() public label?: string;
protected render() {
return html`<ha-yaml-editor
.defaultValue=${this.value}
@value-changed=${this._handleChange}
></ha-yaml-editor>`;
}
private _handleChange(ev) {
const value = ev.target.value;
if (!ev.target.isValid) {
return;
}
if (this.value === value) {
return;
}
fireEvent(this, "value-changed", { value });
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-selector-object": HaObjectSelector;
}
}