-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Script Editor to Ha Form #11601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script Editor to Ha Form #11601
Changes from all commits
7af77e5
77ec465
bf6c945
48fa23a
440f83a
f57eb4e
16014b3
fd077fe
d489162
1a4cd69
3f3c32e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import "../ha-icon-picker"; | ||
| import { html, LitElement } from "lit"; | ||
| import { customElement, property } from "lit/decorators"; | ||
| import { HomeAssistant } from "../../types"; | ||
| import { IconSelector } from "../../data/selector"; | ||
| import { fireEvent } from "../../common/dom/fire_event"; | ||
|
|
||
| @customElement("ha-selector-icon") | ||
| export class HaIconSelector extends LitElement { | ||
| @property() public hass!: HomeAssistant; | ||
|
|
||
| @property() public selector!: IconSelector; | ||
|
|
||
| @property() public value?: string; | ||
|
|
||
| @property() public label?: string; | ||
|
|
||
| @property({ type: Boolean, reflect: true }) public disabled = false; | ||
|
|
||
| protected render() { | ||
| return html` | ||
| <ha-icon-picker | ||
| .label=${this.label} | ||
| .value=${this.value} | ||
| @value-changed=${this._valueChanged} | ||
| ></ha-icon-picker> | ||
| `; | ||
| } | ||
|
|
||
| private _valueChanged(ev: CustomEvent) { | ||
| fireEvent(this, "value-changed", { value: ev.detail.value }); | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "ha-selector-icon": HaIconSelector; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { css, CSSResultGroup, html, LitElement } from "lit"; | |
| import { customElement, property } from "lit/decorators"; | ||
| import { fireEvent } from "../../common/dom/fire_event"; | ||
| import { stopPropagation } from "../../common/dom/stop_propagation"; | ||
| import { SelectSelector } from "../../data/selector"; | ||
| import { SelectOption, SelectSelector } from "../../data/selector"; | ||
| import { HomeAssistant } from "../../types"; | ||
| import "@material/mwc-select/mwc-select"; | ||
| import "@material/mwc-list/mwc-list-item"; | ||
|
|
@@ -17,6 +17,8 @@ export class HaSelectSelector extends LitElement { | |
|
|
||
| @property() public label?: string; | ||
|
|
||
| @property() public helper?: string; | ||
|
|
||
| @property({ type: Boolean }) public disabled = false; | ||
|
|
||
| protected render() { | ||
|
|
@@ -25,15 +27,17 @@ export class HaSelectSelector extends LitElement { | |
| naturalMenuWidth | ||
| .label=${this.label} | ||
| .value=${this.value} | ||
| .helper=${this.helper} | ||
| .disabled=${this.disabled} | ||
| @closed=${stopPropagation} | ||
| @selected=${this._valueChanged} | ||
| > | ||
| ${this.selector.select.options.map( | ||
| (item: string) => html` | ||
| <mwc-list-item .value=${item}>${item}</mwc-list-item> | ||
| ` | ||
| )} | ||
| ${this.selector.select.options.map((item: string | SelectOption) => { | ||
| const value = typeof item === "object" ? item.value : item; | ||
| const label = typeof item === "object" ? item.label : item; | ||
|
Comment on lines
+36
to
+37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or should we do it like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the object better, but not sure how well it translates to the backend
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can switch it but I also like object better... the other is very ambiguous it seems |
||
|
|
||
| return html`<mwc-list-item .value=${value}>${label}</mwc-list-item>`; | ||
| })} | ||
| </mwc-select>`; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.