mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Add support for constant in ha-form (#6324)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
26ae5fd728
commit
0c58c3572a
47
src/components/ha-form/ha-form-constant.ts
Normal file
47
src/components/ha-form/ha-form-constant.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import {
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
property,
|
||||||
|
TemplateResult,
|
||||||
|
CSSResult,
|
||||||
|
css,
|
||||||
|
PropertyValues,
|
||||||
|
} from "lit-element";
|
||||||
|
import { HaFormElement, HaFormConstantSchema } from "./ha-form";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
|
||||||
|
@customElement("ha-form-constant")
|
||||||
|
export class HaFormConstant extends LitElement implements HaFormElement {
|
||||||
|
@property({ attribute: false }) public schema!: HaFormConstantSchema;
|
||||||
|
|
||||||
|
@property() public label!: string;
|
||||||
|
|
||||||
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: this.schema.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`<span class="label">${this.label}</span>: ${this.schema.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult {
|
||||||
|
return css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.label {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-form-constant": HaFormConstant;
|
||||||
|
}
|
||||||
|
}
|
@ -15,8 +15,10 @@ import "./ha-form-multi_select";
|
|||||||
import "./ha-form-positive_time_period_dict";
|
import "./ha-form-positive_time_period_dict";
|
||||||
import "./ha-form-select";
|
import "./ha-form-select";
|
||||||
import "./ha-form-string";
|
import "./ha-form-string";
|
||||||
|
import "./ha-form-constant";
|
||||||
|
|
||||||
export type HaFormSchema =
|
export type HaFormSchema =
|
||||||
|
| HaFormConstantSchema
|
||||||
| HaFormStringSchema
|
| HaFormStringSchema
|
||||||
| HaFormIntegerSchema
|
| HaFormIntegerSchema
|
||||||
| HaFormFloatSchema
|
| HaFormFloatSchema
|
||||||
@ -33,6 +35,11 @@ export interface HaFormBaseSchema {
|
|||||||
description?: { suffix?: string; suggested_value?: HaFormData };
|
description?: { suffix?: string; suggested_value?: HaFormData };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface HaFormConstantSchema extends HaFormBaseSchema {
|
||||||
|
type: "constant";
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface HaFormIntegerSchema extends HaFormBaseSchema {
|
export interface HaFormIntegerSchema extends HaFormBaseSchema {
|
||||||
type: "integer";
|
type: "integer";
|
||||||
default?: HaFormIntegerData;
|
default?: HaFormIntegerData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user