mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Add selectors for text and arbitrary objects (#8152)
This commit is contained in:
parent
e69f36047d
commit
5c0e151bc2
37
src/components/ha-selector/ha-selector-object.ts
Normal file
37
src/components/ha-selector/ha-selector-object.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
50
src/components/ha-selector/ha-selector-text.ts
Normal file
50
src/components/ha-selector/ha-selector-text.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { customElement, html, LitElement, property } from "lit-element";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
import "@polymer/paper-input/paper-textarea";
|
||||||
|
import "@polymer/paper-input/paper-input";
|
||||||
|
import { StringSelector } from "../../data/selector";
|
||||||
|
|
||||||
|
@customElement("ha-selector-text")
|
||||||
|
export class HaTextSelector extends LitElement {
|
||||||
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public value?: any;
|
||||||
|
|
||||||
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property() public selector!: StringSelector;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
if (this.selector.text?.multiline) {
|
||||||
|
return html`<paper-textarea
|
||||||
|
.label=${this.label}
|
||||||
|
.value="${this.value}"
|
||||||
|
@value-changed="${this._handleChange}"
|
||||||
|
autocapitalize="none"
|
||||||
|
autocomplete="off"
|
||||||
|
spellcheck="false"
|
||||||
|
></paper-textarea>`;
|
||||||
|
}
|
||||||
|
return html`<paper-input
|
||||||
|
required
|
||||||
|
.value=${this.value}
|
||||||
|
@value-changed=${this._handleChange}
|
||||||
|
.label=${this.label}
|
||||||
|
></paper-input>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleChange(ev) {
|
||||||
|
const value = ev.target.value;
|
||||||
|
if (this.value === value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "value-changed", { value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-selector-text": HaTextSelector;
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ import "./ha-selector-entity";
|
|||||||
import "./ha-selector-number";
|
import "./ha-selector-number";
|
||||||
import "./ha-selector-target";
|
import "./ha-selector-target";
|
||||||
import "./ha-selector-time";
|
import "./ha-selector-time";
|
||||||
|
import "./ha-selector-object";
|
||||||
|
import "./ha-selector-text";
|
||||||
|
|
||||||
@customElement("ha-selector")
|
@customElement("ha-selector")
|
||||||
export class HaSelector extends LitElement {
|
export class HaSelector extends LitElement {
|
||||||
|
@ -6,7 +6,9 @@ export type Selector =
|
|||||||
| NumberSelector
|
| NumberSelector
|
||||||
| BooleanSelector
|
| BooleanSelector
|
||||||
| TimeSelector
|
| TimeSelector
|
||||||
| ActionSelector;
|
| ActionSelector
|
||||||
|
| StringSelector
|
||||||
|
| ObjectSelector;
|
||||||
|
|
||||||
export interface EntitySelector {
|
export interface EntitySelector {
|
||||||
entity: {
|
entity: {
|
||||||
@ -82,3 +84,14 @@ export interface ActionSelector {
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
action: {};
|
action: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StringSelector {
|
||||||
|
text: {
|
||||||
|
multiline: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ObjectSelector {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
object: {};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user