mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-02 05:57:54 +00:00
parent
eba1f401cc
commit
df86b27af4
@ -1,15 +1,15 @@
|
|||||||
import { html, LitElement, nothing } from "lit";
|
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import "../../../components/ha-control-button";
|
import "../../../components/ha-control-button";
|
||||||
import "../../../components/ha-control-button-group";
|
import "../../../components/ha-control-button-group";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import type { LovelaceCardFeature } from "../types";
|
import type { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types";
|
||||||
import { cardFeatureStyles } from "./common/card-feature-styles";
|
import { cardFeatureStyles } from "./common/card-feature-styles";
|
||||||
import type {
|
import type {
|
||||||
LovelaceCardFeatureContext,
|
|
||||||
ButtonCardFeatureConfig,
|
ButtonCardFeatureConfig,
|
||||||
|
LovelaceCardFeatureContext,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
export const supportsButtonCardFeature = (
|
export const supportsButtonCardFeature = (
|
||||||
@ -89,6 +89,11 @@ class HuiButtonCardFeature extends LitElement implements LovelaceCardFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static styles = cardFeatureStyles;
|
static styles = cardFeatureStyles;
|
||||||
|
|
||||||
|
public static async getConfigElement(): Promise<LovelaceCardFeatureEditor> {
|
||||||
|
await import("../editor/config-elements/hui-button-card-feature-editor");
|
||||||
|
return document.createElement("hui-button-card-feature-editor");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
|
import "../../../../components/ha-form/ha-form";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import type { ButtonCardFeatureConfig } from "../../card-features/types";
|
import type { ButtonCardFeatureConfig } from "../../card-features/types";
|
||||||
import type { LovelaceCardFeatureEditor } from "../../types";
|
import type { LovelaceCardFeatureEditor } from "../../types";
|
||||||
import "../../../../components/ha-form/ha-form";
|
|
||||||
import type { HaFormSchema } from "../../../../components/ha-form/types";
|
|
||||||
|
|
||||||
@customElement("hui-button-card-feature-editor")
|
@customElement("hui-button-card-feature-editor")
|
||||||
export class HuiButtonCardFeatureEditor
|
export class HuiButtonCardFeatureEditor
|
||||||
@ -19,14 +20,15 @@ export class HuiButtonCardFeatureEditor
|
|||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _schema: HaFormSchema[] = [
|
private _schema = memoizeOne((localize: LocalizeFunc) => [
|
||||||
{
|
{
|
||||||
name: "action_name",
|
name: "action_name",
|
||||||
|
default: localize("ui.card.button.press"),
|
||||||
selector: {
|
selector: {
|
||||||
text: {},
|
text: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
]);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.hass || !this._config) {
|
if (!this.hass || !this._config) {
|
||||||
@ -37,12 +39,15 @@ export class HuiButtonCardFeatureEditor
|
|||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.data=${this._config}
|
.data=${this._config}
|
||||||
.schema=${this._schema}
|
.schema=${this._schema(this.hass.localize)}
|
||||||
|
.computeLabel=${this._computeLabel}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _computeLabel = () => this.hass.localize("ui.common.name");
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private _valueChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user