mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 07:46:37 +00:00
Add Template selector (#12348)
This commit is contained in:
parent
511368da13
commit
6fd4cda534
@ -170,6 +170,7 @@ const SCHEMAS: {
|
|||||||
select: { options: ["Option 1", "Option 2"], mode: "list" },
|
select: { options: ["Option 1", "Option 2"], mode: "list" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
template: { name: "Template", selector: { template: {} } },
|
||||||
select: {
|
select: {
|
||||||
name: "Select",
|
name: "Select",
|
||||||
selector: {
|
selector: {
|
||||||
|
56
src/components/ha-selector/ha-selector-template.ts
Normal file
56
src/components/ha-selector/ha-selector-template.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
import "../ha-code-editor";
|
||||||
|
import "../ha-input-helper-text";
|
||||||
|
|
||||||
|
@customElement("ha-selector-template")
|
||||||
|
export class HaTemplateSelector extends LitElement {
|
||||||
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public value?: string;
|
||||||
|
|
||||||
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
return html`
|
||||||
|
${this.label
|
||||||
|
? html`<p>${this.label}${this.required ? " *" : ""}</p>`
|
||||||
|
: ""}
|
||||||
|
<ha-code-editor
|
||||||
|
mode="jinja2"
|
||||||
|
.hass=${this.hass}
|
||||||
|
.value=${this.value}
|
||||||
|
.readOnly=${this.disabled}
|
||||||
|
autofocus
|
||||||
|
autocomplete-entities
|
||||||
|
@value-changed=${this._handleChange}
|
||||||
|
dir="ltr"
|
||||||
|
></ha-code-editor>
|
||||||
|
${this.helper
|
||||||
|
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||||
|
: ""}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleChange(ev) {
|
||||||
|
const value = ev.target.value;
|
||||||
|
if (this.value === value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "value-changed", { value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-selector-template": HaTemplateSelector;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import "./ha-selector-number";
|
|||||||
import "./ha-selector-object";
|
import "./ha-selector-object";
|
||||||
import "./ha-selector-select";
|
import "./ha-selector-select";
|
||||||
import "./ha-selector-target";
|
import "./ha-selector-target";
|
||||||
|
import "./ha-selector-template";
|
||||||
import "./ha-selector-text";
|
import "./ha-selector-text";
|
||||||
import "./ha-selector-time";
|
import "./ha-selector-time";
|
||||||
import "./ha-selector-icon";
|
import "./ha-selector-icon";
|
||||||
|
@ -19,6 +19,7 @@ export type Selector =
|
|||||||
| SelectSelector
|
| SelectSelector
|
||||||
| StringSelector
|
| StringSelector
|
||||||
| TargetSelector
|
| TargetSelector
|
||||||
|
| TemplateSelector
|
||||||
| ThemeSelector
|
| ThemeSelector
|
||||||
| TimeSelector;
|
| TimeSelector;
|
||||||
|
|
||||||
@ -213,6 +214,11 @@ export interface TargetSelector {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TemplateSelector {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
template: {};
|
||||||
|
}
|
||||||
|
|
||||||
export interface ThemeSelector {
|
export interface ThemeSelector {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
theme: {};
|
theme: {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user