mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 22:37:21 +00:00
Allow rendering helper text from strings.json (#12119)
* Allow rendering helper text from strings.json * Persistent helpers * Update src/components/ha-base-time-input.ts Co-authored-by: Zack Barett <zackbarett@hey.com> * Update src/components/ha-base-time-input.ts Co-authored-by: Zack Barett <zackbarett@hey.com>
This commit is contained in:
parent
a58b4fb262
commit
224df896a1
@ -21,6 +21,11 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
*/
|
*/
|
||||||
@property() label?: string;
|
@property() label?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for the input
|
||||||
|
*/
|
||||||
|
@property() helper?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* auto validate time inputs
|
* auto validate time inputs
|
||||||
*/
|
*/
|
||||||
@ -207,6 +212,7 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
<mwc-list-item value="PM">PM</mwc-list-item>
|
<mwc-list-item value="PM">PM</mwc-list-item>
|
||||||
</ha-select>`}
|
</ha-select>`}
|
||||||
</div>
|
</div>
|
||||||
|
${this.helper ? html`<div class="helper">${this.helper}</div>` : ""}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +309,13 @@ export class HaBaseTimeInput extends LitElement {
|
|||||||
color: var(--mdc-theme-text-primary-on-background, rgba(0, 0, 0, 0.87));
|
color: var(--mdc-theme-text-primary-on-background, rgba(0, 0, 0, 0.87));
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.helper {
|
||||||
|
color: var(--mdc-text-field-label-ink-color, rgba(0, 0, 0, 0.6));
|
||||||
|
font-size: 0.75rem;
|
||||||
|
padding-left: 16px;
|
||||||
|
padding-right: 16px;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ class HaDurationInput extends LitElement {
|
|||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required?: boolean;
|
@property({ type: Boolean }) public required?: boolean;
|
||||||
|
|
||||||
@property({ type: Boolean }) public enableMillisecond?: boolean;
|
@property({ type: Boolean }) public enableMillisecond?: boolean;
|
||||||
@ -35,6 +37,7 @@ class HaDurationInput extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-base-time-input
|
<ha-base-time-input
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
|
.helper=${this.helper}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.autoValidate=${this.required}
|
.autoValidate=${this.required}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
@ -28,6 +28,8 @@ export class HaFormString extends LitElement implements HaFormElement {
|
|||||||
|
|
||||||
@property() public label!: string;
|
@property() public label!: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@state() private _unmaskedPassword = false;
|
@state() private _unmaskedPassword = false;
|
||||||
@ -53,6 +55,8 @@ export class HaFormString extends LitElement implements HaFormElement {
|
|||||||
: "password"}
|
: "password"}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.value=${this.data || ""}
|
.value=${this.data || ""}
|
||||||
|
.helper=${this.helper}
|
||||||
|
helperPersistent
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.schema.required}
|
.required=${this.schema.required}
|
||||||
.autoValidate=${this.schema.required}
|
.autoValidate=${this.schema.required}
|
||||||
|
@ -14,6 +14,8 @@ export class HaTimeDuration extends LitElement {
|
|||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
@ -22,6 +24,7 @@ export class HaTimeDuration extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-duration-input
|
<ha-duration-input
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
|
.helper=${this.helper}
|
||||||
.data=${this.value}
|
.data=${this.value}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
|
@ -19,6 +19,8 @@ export class HaNumberSelector extends LitElement {
|
|||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
@ -48,6 +50,8 @@ export class HaNumberSelector extends LitElement {
|
|||||||
.max=${this.selector.number.max}
|
.max=${this.selector.number.max}
|
||||||
.value=${this.value ?? ""}
|
.value=${this.value ?? ""}
|
||||||
.step=${this.selector.number.step ?? 1}
|
.step=${this.selector.number.step ?? 1}
|
||||||
|
helperPersistent
|
||||||
|
.helper=${this.helper}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.suffix=${this.selector.number.unit_of_measurement}
|
.suffix=${this.selector.number.unit_of_measurement}
|
||||||
|
@ -18,6 +18,8 @@ export class HaTextSelector extends LitElement {
|
|||||||
|
|
||||||
@property() public placeholder?: string;
|
@property() public placeholder?: string;
|
||||||
|
|
||||||
|
@property() public helper?: string;
|
||||||
|
|
||||||
@property() public selector!: StringSelector;
|
@property() public selector!: StringSelector;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
@ -32,6 +34,8 @@ export class HaTextSelector extends LitElement {
|
|||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.placeholder=${this.placeholder}
|
.placeholder=${this.placeholder}
|
||||||
.value=${this.value || ""}
|
.value=${this.value || ""}
|
||||||
|
.helper=${this.helper}
|
||||||
|
helperPersistent
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@input=${this._handleChange}
|
@input=${this._handleChange}
|
||||||
autocapitalize="none"
|
autocapitalize="none"
|
||||||
@ -44,6 +48,8 @@ export class HaTextSelector extends LitElement {
|
|||||||
return html`<ha-textfield
|
return html`<ha-textfield
|
||||||
.value=${this.value || ""}
|
.value=${this.value || ""}
|
||||||
.placeholder=${this.placeholder || ""}
|
.placeholder=${this.placeholder || ""}
|
||||||
|
.helper=${this.helper}
|
||||||
|
helperPersistent
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.type=${this._unmaskedPassword ? "text" : this.selector.text?.type}
|
.type=${this._unmaskedPassword ? "text" : this.selector.text?.type}
|
||||||
@input=${this._handleChange}
|
@input=${this._handleChange}
|
||||||
|
@ -14,9 +14,7 @@ import { fireEvent, HASSDomEvent } from "../../common/dom/fire_event";
|
|||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
import "../../components/ha-circular-progress";
|
import "../../components/ha-circular-progress";
|
||||||
import "../../components/ha-dialog";
|
import "../../components/ha-dialog";
|
||||||
import "../../components/ha-form/ha-form";
|
|
||||||
import "../../components/ha-icon-button";
|
import "../../components/ha-icon-button";
|
||||||
import "../../components/ha-markdown";
|
|
||||||
import {
|
import {
|
||||||
AreaRegistryEntry,
|
AreaRegistryEntry,
|
||||||
subscribeAreaRegistry,
|
subscribeAreaRegistry,
|
||||||
|
@ -91,6 +91,12 @@ export const showConfigFlowDialog = (
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderShowFormStepFieldHelper(hass, step, field) {
|
||||||
|
return hass.localize(
|
||||||
|
`component.${step.handler}.config.step.${step.step_id}.data_description.${field.name}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
renderShowFormStepFieldError(hass, step, error) {
|
renderShowFormStepFieldError(hass, step, error) {
|
||||||
return hass.localize(
|
return hass.localize(
|
||||||
`component.${step.handler}.config.error.${error}`,
|
`component.${step.handler}.config.error.${error}`,
|
||||||
|
@ -50,6 +50,12 @@ export interface FlowConfig {
|
|||||||
field: HaFormSchema
|
field: HaFormSchema
|
||||||
): string;
|
): string;
|
||||||
|
|
||||||
|
renderShowFormStepFieldHelper(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
step: DataEntryFlowStepForm,
|
||||||
|
field: HaFormSchema
|
||||||
|
): string;
|
||||||
|
|
||||||
renderShowFormStepFieldError(
|
renderShowFormStepFieldError(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
step: DataEntryFlowStepForm,
|
step: DataEntryFlowStepForm,
|
||||||
|
@ -89,6 +89,12 @@ export const showOptionsFlowDialog = (
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderShowFormStepFieldHelper(hass, step, field) {
|
||||||
|
return hass.localize(
|
||||||
|
`component.${configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
renderShowFormStepFieldError(hass, step, error) {
|
renderShowFormStepFieldError(hass, step, error) {
|
||||||
return hass.localize(
|
return hass.localize(
|
||||||
`component.${configEntry.domain}.options.error.${error}`,
|
`component.${configEntry.domain}.options.error.${error}`,
|
||||||
|
@ -54,6 +54,7 @@ class StepFlowForm extends LitElement {
|
|||||||
.schema=${step.data_schema}
|
.schema=${step.data_schema}
|
||||||
.error=${step.errors}
|
.error=${step.errors}
|
||||||
.computeLabel=${this._labelCallback}
|
.computeLabel=${this._labelCallback}
|
||||||
|
.computeHelper=${this._helperCallback}
|
||||||
.computeError=${this._errorCallback}
|
.computeError=${this._errorCallback}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
</div>
|
</div>
|
||||||
@ -166,6 +167,9 @@ class StepFlowForm extends LitElement {
|
|||||||
private _labelCallback = (field: HaFormSchema): string =>
|
private _labelCallback = (field: HaFormSchema): string =>
|
||||||
this.flowConfig.renderShowFormStepFieldLabel(this.hass, this.step, field);
|
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) =>
|
private _errorCallback = (error: string) =>
|
||||||
this.flowConfig.renderShowFormStepFieldError(this.hass, this.step, error);
|
this.flowConfig.renderShowFormStepFieldError(this.hass, this.step, error);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user