mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Convert HaFormSchemas to use selectors (#11589)
This commit is contained in:
parent
ca8d31c6bb
commit
e72a4e4a20
@ -50,7 +50,11 @@ const SCHEMAS: {
|
|||||||
action: { name: "Action", selector: { action: {} } },
|
action: { name: "Action", selector: { action: {} } },
|
||||||
text: {
|
text: {
|
||||||
name: "Text",
|
name: "Text",
|
||||||
selector: { text: { multiline: false } },
|
selector: { text: {} },
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
name: "Password",
|
||||||
|
selector: { text: { type: "password" } },
|
||||||
},
|
},
|
||||||
text_multiline: {
|
text_multiline: {
|
||||||
name: "Text multiline",
|
name: "Text multiline",
|
||||||
|
@ -19,22 +19,21 @@ import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
|||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
import { RegistriesDialogParams } from "./show-dialog-registries";
|
import { RegistriesDialogParams } from "./show-dialog-registries";
|
||||||
|
|
||||||
const SCHEMA = [
|
const SCHEMA: HaFormSchema[] = [
|
||||||
{
|
{
|
||||||
type: "string",
|
|
||||||
name: "registry",
|
name: "registry",
|
||||||
required: true,
|
required: true,
|
||||||
|
selector: { text: {} },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "string",
|
|
||||||
name: "username",
|
name: "username",
|
||||||
required: true,
|
required: true,
|
||||||
|
selector: { text: {} },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "string",
|
|
||||||
name: "password",
|
name: "password",
|
||||||
required: true,
|
required: true,
|
||||||
format: "password",
|
selector: { text: { type: "password" } },
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
import "@material/mwc-textarea/mwc-textarea";
|
||||||
|
import "@material/mwc-textfield/mwc-textfield";
|
||||||
|
import { mdiEye, mdiEyeOff } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { StringSelector } from "../../data/selector";
|
import { StringSelector } from "../../data/selector";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "@material/mwc-textfield/mwc-textfield";
|
import "../ha-icon-button";
|
||||||
import "@material/mwc-textarea/mwc-textarea";
|
|
||||||
|
|
||||||
@customElement("ha-selector-text")
|
@customElement("ha-selector-text")
|
||||||
export class HaTextSelector extends LitElement {
|
export class HaTextSelector extends LitElement {
|
||||||
@ -20,6 +22,8 @@ export class HaTextSelector extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
|
@state() private _unmaskedPassword = false;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this.selector.text?.multiline) {
|
if (this.selector.text?.multiline) {
|
||||||
return html`<mwc-textarea
|
return html`<mwc-textarea
|
||||||
@ -38,10 +42,27 @@ export class HaTextSelector extends LitElement {
|
|||||||
.value=${this.value || ""}
|
.value=${this.value || ""}
|
||||||
.placeholder=${this.placeholder || ""}
|
.placeholder=${this.placeholder || ""}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
.type=${this._unmaskedPassword ? "text" : this.selector.text?.type}
|
||||||
@input=${this._handleChange}
|
@input=${this._handleChange}
|
||||||
.label=${this.label || ""}
|
.label=${this.label || ""}
|
||||||
|
.suffix=${this.selector.text?.type === "password"
|
||||||
|
? // reserve some space for the icon.
|
||||||
|
html`<div style="width: 24px"></div>`
|
||||||
|
: this.selector.text?.suffix}
|
||||||
required
|
required
|
||||||
></mwc-textfield>`;
|
></mwc-textfield>
|
||||||
|
${this.selector.text?.type === "password"
|
||||||
|
? html`<ha-icon-button
|
||||||
|
toggles
|
||||||
|
.label=${`${this._unmaskedPassword ? "Hide" : "Show"} password`}
|
||||||
|
@click=${this._toggleUnmaskedPassword}
|
||||||
|
.path=${this._unmaskedPassword ? mdiEyeOff : mdiEye}
|
||||||
|
></ha-icon-button>`
|
||||||
|
: ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _toggleUnmaskedPassword(): void {
|
||||||
|
this._unmaskedPassword = !this._unmaskedPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleChange(ev) {
|
private _handleChange(ev) {
|
||||||
@ -54,10 +75,22 @@ export class HaTextSelector extends LitElement {
|
|||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
mwc-textfield,
|
mwc-textfield,
|
||||||
mwc-textarea {
|
mwc-textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
ha-icon-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 16px;
|
||||||
|
--mdc-icon-button-size: 24px;
|
||||||
|
--mdc-icon-size: 20px;
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,22 @@ export interface ActionSelector {
|
|||||||
|
|
||||||
export interface StringSelector {
|
export interface StringSelector {
|
||||||
text: {
|
text: {
|
||||||
multiline: boolean;
|
multiline?: boolean;
|
||||||
|
type?:
|
||||||
|
| "number"
|
||||||
|
| "text"
|
||||||
|
| "search"
|
||||||
|
| "tel"
|
||||||
|
| "url"
|
||||||
|
| "email"
|
||||||
|
| "password"
|
||||||
|
| "date"
|
||||||
|
| "month"
|
||||||
|
| "week"
|
||||||
|
| "time"
|
||||||
|
| "datetime-local"
|
||||||
|
| "color";
|
||||||
|
suffix?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,18 @@ import { onboardUserStep } from "../data/onboarding";
|
|||||||
import { PolymerChangedEvent } from "../polymer-types";
|
import { PolymerChangedEvent } from "../polymer-types";
|
||||||
|
|
||||||
const CREATE_USER_SCHEMA: HaFormSchema[] = [
|
const CREATE_USER_SCHEMA: HaFormSchema[] = [
|
||||||
{ type: "string", name: "name", required: true },
|
{ name: "name", required: true, selector: { text: {} } },
|
||||||
{ type: "string", name: "username", required: true },
|
{ name: "username", required: true, selector: { text: {} } },
|
||||||
{ type: "string", name: "password", required: true },
|
{
|
||||||
{ type: "string", name: "password_confirm", required: true },
|
name: "password",
|
||||||
|
required: true,
|
||||||
|
selector: { text: { type: "password" } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "password_confirm",
|
||||||
|
required: true,
|
||||||
|
selector: { text: { type: "password" } },
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@customElement("onboarding-create-user")
|
@customElement("onboarding-create-user")
|
||||||
|
@ -106,7 +106,7 @@ class ZHAConfigDashboard extends LitElement {
|
|||||||
</ha-card>
|
</ha-card>
|
||||||
${this._configuration
|
${this._configuration
|
||||||
? Object.entries(this._configuration.schemas).map(
|
? Object.entries(this._configuration.schemas).map(
|
||||||
([section, schema]) => html` <ha-card
|
([section, schema]) => html`<ha-card
|
||||||
header=${this.hass.localize(
|
header=${this.hass.localize(
|
||||||
`component.zha.config_panel.${section}.title`
|
`component.zha.config_panel.${section}.title`
|
||||||
)}
|
)}
|
||||||
|
@ -101,7 +101,7 @@ class HaMfaModuleSetupFlow extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</p>`
|
</p>`
|
||||||
: this._step.type === "form"
|
: this._step.type === "form"
|
||||||
? html` <ha-markdown
|
? html`<ha-markdown
|
||||||
allowsvg
|
allowsvg
|
||||||
breaks
|
breaks
|
||||||
.content=${this.hass.localize(
|
.content=${this.hass.localize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user