From 44b399dfb3bf6567ae2a3ea1e925038346809cc4 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 23 Mar 2022 22:54:04 -0700 Subject: [PATCH 1/4] Allow rendering helper text from strings.json --- src/components/ha-base-time-input.ts | 25 ++++++++++++++++++- src/components/ha-duration-input.ts | 3 +++ src/components/ha-form/ha-form-string.ts | 3 +++ .../ha-selector/ha-selector-duration.ts | 3 +++ .../ha-selector/ha-selector-number.ts | 3 +++ .../ha-selector/ha-selector-text.ts | 4 +++ .../config-flow/dialog-data-entry-flow.ts | 2 -- .../config-flow/show-dialog-config-flow.ts | 6 +++++ .../show-dialog-data-entry-flow.ts | 6 +++++ .../config-flow/show-dialog-options-flow.ts | 6 +++++ src/dialogs/config-flow/step-flow-form.ts | 4 +++ 11 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index 64b12f18e2df..b5751387fe92 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -1,4 +1,4 @@ -import { LitElement, html, TemplateResult, css } from "lit"; +import { LitElement, html, TemplateResult, css, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; import "./ha-select"; import "@material/mwc-list/mwc-list-item"; @@ -21,6 +21,11 @@ export class HaBaseTimeInput extends LitElement { */ @property() label?: string; + /** + * Helper for the input + */ + @property() helper?: string; + /** * auto validate time inputs */ @@ -207,9 +212,16 @@ export class HaBaseTimeInput extends LitElement { PM `} + ${this.helper ? html`
${this.helper}
` : ""} `; } + protected firstUpdated(changedProps: PropertyValues) { + super.firstUpdated(changedProps); + this.addEventListener("focus", () => this.toggleAttribute("focused", true)); + this.addEventListener("blur", () => this.toggleAttribute("focused", false)); + } + private _valueChanged(ev) { this[ev.target.name] = ev.target.name === "amPm" ? ev.target.value : Number(ev.target.value); @@ -303,6 +315,17 @@ export class HaBaseTimeInput extends LitElement { color: var(--mdc-theme-text-primary-on-background, rgba(0, 0, 0, 0.87)); padding-left: 4px; } + + .helper { + color: var(--mdc-text-field-label-ink-color, rgba(0, 0, 0, 0.6)); + opacity: 0; + font-size: 0.75rem; + will-change: opacity; + transition: opacity 150ms 0ms cubic-bezier(0.4, 0, 0.2, 1); + } + :host([focused]) .helper { + opacity: 1; + } `; } diff --git a/src/components/ha-duration-input.ts b/src/components/ha-duration-input.ts index 9ac4e72e2ff0..b862059b355b 100644 --- a/src/components/ha-duration-input.ts +++ b/src/components/ha-duration-input.ts @@ -17,6 +17,8 @@ class HaDurationInput extends LitElement { @property() public label?: string; + @property() public helper?: string; + @property({ type: Boolean }) public required?: boolean; @property({ type: Boolean }) public enableMillisecond?: boolean; @@ -35,6 +37,7 @@ class HaDurationInput extends LitElement { return html` @@ -166,6 +167,9 @@ class StepFlowForm extends LitElement { private _labelCallback = (field: HaFormSchema): string => this.flowConfig.renderShowFormStepFieldLabel(this.hass, this.step, field); + private _helperCallback = (field: HaFormSchema): string => + this.flowConfig.renderShowFormStepFieldHelper(this.hass, this.step, field); + private _errorCallback = (error: string) => this.flowConfig.renderShowFormStepFieldError(this.hass, this.step, error); From ccc5c72111df09f1b6d3a4508428752ba629d298 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 24 Mar 2022 11:53:24 -0700 Subject: [PATCH 2/4] Persistent helpers --- src/components/ha-base-time-input.ts | 8 ++------ src/components/ha-form/ha-form-string.ts | 1 + src/components/ha-selector/ha-selector-number.ts | 1 + src/components/ha-selector/ha-selector-text.ts | 2 ++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index b5751387fe92..cf206e6f5115 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -318,13 +318,9 @@ export class HaBaseTimeInput extends LitElement { .helper { color: var(--mdc-text-field-label-ink-color, rgba(0, 0, 0, 0.6)); - opacity: 0; font-size: 0.75rem; - will-change: opacity; - transition: opacity 150ms 0ms cubic-bezier(0.4, 0, 0.2, 1); - } - :host([focused]) .helper { - opacity: 1; + padding-left: 16px; + padding-right: 16px; } `; } diff --git a/src/components/ha-form/ha-form-string.ts b/src/components/ha-form/ha-form-string.ts index f7bf716c1934..f527676aafd7 100644 --- a/src/components/ha-form/ha-form-string.ts +++ b/src/components/ha-form/ha-form-string.ts @@ -56,6 +56,7 @@ export class HaFormString extends LitElement implements HaFormElement { .label=${this.label} .value=${this.data || ""} .helper=${this.helper} + helperPersistent .disabled=${this.disabled} .required=${this.schema.required} .autoValidate=${this.schema.required} diff --git a/src/components/ha-selector/ha-selector-number.ts b/src/components/ha-selector/ha-selector-number.ts index 89b0deb14e6c..ef3bc63fc023 100644 --- a/src/components/ha-selector/ha-selector-number.ts +++ b/src/components/ha-selector/ha-selector-number.ts @@ -50,6 +50,7 @@ export class HaNumberSelector extends LitElement { .max=${this.selector.number.max} .value=${this.value ?? ""} .step=${this.selector.number.step ?? 1} + helperPersistent .helper=${this.helper} .disabled=${this.disabled} .required=${this.required} diff --git a/src/components/ha-selector/ha-selector-text.ts b/src/components/ha-selector/ha-selector-text.ts index c40496313d2d..b91e0edc3342 100644 --- a/src/components/ha-selector/ha-selector-text.ts +++ b/src/components/ha-selector/ha-selector-text.ts @@ -35,6 +35,7 @@ export class HaTextSelector extends LitElement { .placeholder=${this.placeholder} .value=${this.value || ""} .helper=${this.helper} + helperPersistent .disabled=${this.disabled} @input=${this._handleChange} autocapitalize="none" @@ -48,6 +49,7 @@ export class HaTextSelector extends LitElement { .value=${this.value || ""} .placeholder=${this.placeholder || ""} .helper=${this.helper} + helperPersistent .disabled=${this.disabled} .type=${this._unmaskedPassword ? "text" : this.selector.text?.type} @input=${this._handleChange} From dcec9564093c5c7da1a569c4f43a75bc07f23563 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 24 Mar 2022 17:24:55 -0700 Subject: [PATCH 3/4] Update src/components/ha-base-time-input.ts Co-authored-by: Zack Barett --- src/components/ha-base-time-input.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index cf206e6f5115..b19ae6b8bf5d 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -216,12 +216,6 @@ export class HaBaseTimeInput extends LitElement { `; } - protected firstUpdated(changedProps: PropertyValues) { - super.firstUpdated(changedProps); - this.addEventListener("focus", () => this.toggleAttribute("focused", true)); - this.addEventListener("blur", () => this.toggleAttribute("focused", false)); - } - private _valueChanged(ev) { this[ev.target.name] = ev.target.name === "amPm" ? ev.target.value : Number(ev.target.value); From e76e747e2ced23c751857aa966464e71f1ea0c9b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 24 Mar 2022 17:39:58 -0700 Subject: [PATCH 4/4] Update src/components/ha-base-time-input.ts --- src/components/ha-base-time-input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index b19ae6b8bf5d..4c1f1d7ff45c 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -1,4 +1,4 @@ -import { LitElement, html, TemplateResult, css, PropertyValues } from "lit"; +import { LitElement, html, TemplateResult, css } from "lit"; import { customElement, property } from "lit/decorators"; import "./ha-select"; import "@material/mwc-list/mwc-list-item";