mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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-select";
|
||||
import "./ha-form-string";
|
||||
import "./ha-form-constant";
|
||||
|
||||
export type HaFormSchema =
|
||||
| HaFormConstantSchema
|
||||
| HaFormStringSchema
|
||||
| HaFormIntegerSchema
|
||||
| HaFormFloatSchema
|
||||
@ -33,6 +35,11 @@ export interface HaFormBaseSchema {
|
||||
description?: { suffix?: string; suggested_value?: HaFormData };
|
||||
}
|
||||
|
||||
export interface HaFormConstantSchema extends HaFormBaseSchema {
|
||||
type: "constant";
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface HaFormIntegerSchema extends HaFormBaseSchema {
|
||||
type: "integer";
|
||||
default?: HaFormIntegerData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user