Skip to content

Commit 8cc48cd

Browse files
wendevlinbramkragten
authored andcommitted
Use tilecard button feature editor (#26335)
Use button feature editor
1 parent 524e89a commit 8cc48cd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/panels/lovelace/card-features/hui-button-card-feature.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { html, LitElement, nothing } from "lit";
21
import type { HassEntity } from "home-assistant-js-websocket";
2+
import { html, LitElement, nothing } from "lit";
33
import { customElement, property, state } from "lit/decorators";
44
import { computeDomain } from "../../../common/entity/compute_domain";
55
import "../../../components/ha-control-button";
66
import "../../../components/ha-control-button-group";
77
import type { HomeAssistant } from "../../../types";
8-
import type { LovelaceCardFeature } from "../types";
8+
import type { LovelaceCardFeature, LovelaceCardFeatureEditor } from "../types";
99
import { cardFeatureStyles } from "./common/card-feature-styles";
1010
import type {
11-
LovelaceCardFeatureContext,
1211
ButtonCardFeatureConfig,
12+
LovelaceCardFeatureContext,
1313
} from "./types";
1414

1515
export const supportsButtonCardFeature = (
@@ -89,6 +89,11 @@ class HuiButtonCardFeature extends LitElement implements LovelaceCardFeature {
8989
}
9090

9191
static styles = cardFeatureStyles;
92+
93+
public static async getConfigElement(): Promise<LovelaceCardFeatureEditor> {
94+
await import("../editor/config-elements/hui-button-card-feature-editor");
95+
return document.createElement("hui-button-card-feature-editor");
96+
}
9297
}
9398

9499
declare global {

src/panels/lovelace/editor/config-elements/hui-button-card-feature-editor.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { html, LitElement, nothing } from "lit";
22
import { customElement, property, state } from "lit/decorators";
3+
import memoizeOne from "memoize-one";
4+
import type { LocalizeFunc } from "../../../../common/translations/localize";
5+
import "../../../../components/ha-form/ha-form";
36
import type { HomeAssistant } from "../../../../types";
47
import type { ButtonCardFeatureConfig } from "../../card-features/types";
58
import type { LovelaceCardFeatureEditor } from "../../types";
6-
import "../../../../components/ha-form/ha-form";
7-
import type { HaFormSchema } from "../../../../components/ha-form/types";
89

910
@customElement("hui-button-card-feature-editor")
1011
export class HuiButtonCardFeatureEditor
@@ -19,14 +20,15 @@ export class HuiButtonCardFeatureEditor
1920
this._config = config;
2021
}
2122

22-
private _schema: HaFormSchema[] = [
23+
private _schema = memoizeOne((localize: LocalizeFunc) => [
2324
{
2425
name: "action_name",
26+
default: localize("ui.card.button.press"),
2527
selector: {
2628
text: {},
2729
},
2830
},
29-
];
31+
]);
3032

3133
protected render() {
3234
if (!this.hass || !this._config) {
@@ -37,12 +39,15 @@ export class HuiButtonCardFeatureEditor
3739
<ha-form
3840
.hass=${this.hass}
3941
.data=${this._config}
40-
.schema=${this._schema}
42+
.schema=${this._schema(this.hass.localize)}
43+
.computeLabel=${this._computeLabel}
4144
@value-changed=${this._valueChanged}
4245
></ha-form>
4346
`;
4447
}
4548

49+
private _computeLabel = () => this.hass.localize("ui.common.name");
50+
4651
private _valueChanged(ev: CustomEvent) {
4752
ev.stopPropagation();
4853
this.dispatchEvent(

0 commit comments

Comments
 (0)