mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Add select selector for blueprints (#8297)
This commit is contained in:
parent
6b673c7f44
commit
ab74c7f7eb
73
src/components/ha-selector/ha-selector-select.ts
Normal file
73
src/components/ha-selector/ha-selector-select.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import {
|
||||||
|
css,
|
||||||
|
CSSResult,
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
property,
|
||||||
|
} from "lit-element";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { HomeAssistant } from "../../types";
|
||||||
|
import { SelectSelector } from "../../data/selector";
|
||||||
|
import "../ha-paper-dropdown-menu";
|
||||||
|
|
||||||
|
@customElement("ha-selector-select")
|
||||||
|
export class HaSelectSelector extends LitElement {
|
||||||
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public selector!: SelectSelector;
|
||||||
|
|
||||||
|
@property() public value?: string;
|
||||||
|
|
||||||
|
@property() public label?: string;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
return html`<ha-paper-dropdown-menu .label=${this.label}>
|
||||||
|
<paper-listbox
|
||||||
|
slot="dropdown-content"
|
||||||
|
attr-for-selected="item-value"
|
||||||
|
.selected=${this.value}
|
||||||
|
@selected-item-changed=${this._valueChanged}
|
||||||
|
>
|
||||||
|
${this.selector.select.options.map(
|
||||||
|
(item: string) => html`
|
||||||
|
<paper-item .itemValue=${item}>
|
||||||
|
${item}
|
||||||
|
</paper-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</paper-listbox>
|
||||||
|
</ha-paper-dropdown-menu>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev) {
|
||||||
|
if (!ev.detail.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: ev.detail.value.itemValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult {
|
||||||
|
return css`
|
||||||
|
ha-paper-dropdown-menu {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 200px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
paper-listbox {
|
||||||
|
min-width: 200px;
|
||||||
|
}
|
||||||
|
paper-item {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-selector-select": HaSelectSelector;
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import "./ha-selector-target";
|
|||||||
import "./ha-selector-time";
|
import "./ha-selector-time";
|
||||||
import "./ha-selector-object";
|
import "./ha-selector-object";
|
||||||
import "./ha-selector-text";
|
import "./ha-selector-text";
|
||||||
|
import "./ha-selector-select";
|
||||||
|
|
||||||
@customElement("ha-selector")
|
@customElement("ha-selector")
|
||||||
export class HaSelector extends LitElement {
|
export class HaSelector extends LitElement {
|
||||||
|
@ -8,8 +8,8 @@ export type Selector =
|
|||||||
| TimeSelector
|
| TimeSelector
|
||||||
| ActionSelector
|
| ActionSelector
|
||||||
| StringSelector
|
| StringSelector
|
||||||
| ObjectSelector;
|
| ObjectSelector
|
||||||
|
| SelectSelector;
|
||||||
export interface EntitySelector {
|
export interface EntitySelector {
|
||||||
entity: {
|
entity: {
|
||||||
integration?: string;
|
integration?: string;
|
||||||
@ -95,3 +95,9 @@ export interface ObjectSelector {
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
object: {};
|
object: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SelectSelector {
|
||||||
|
select: {
|
||||||
|
options: string[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user