diff --git a/src/panels/lovelace/editor/config-elements/hui-calendar-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-calendar-card-editor.ts index 2142f325f4..30c81af52c 100644 --- a/src/panels/lovelace/editor/config-elements/hui-calendar-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-calendar-card-editor.ts @@ -1,7 +1,8 @@ -import "@material/mwc-list/mwc-list-item"; -import "@material/mwc-select/mwc-select"; -import { CSSResultGroup, html, LitElement, TemplateResult } from "lit"; +import "../../../../components/entity/ha-entities-picker"; +import "../../../../components/ha-form/ha-form"; +import { css, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; +import memoizeOne from "memoize-one"; import { array, assert, @@ -13,16 +14,12 @@ import { union, } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import { stopPropagation } from "../../../../common/dom/stop_propagation"; -import "../../../../components/entity/ha-entities-picker"; +import { LocalizeFunc } from "../../../../common/translations/localize"; +import type { HaFormSchema } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { CalendarCardConfig } from "../../cards/types"; -import "../../components/hui-entity-editor"; -import "../../components/hui-theme-select-editor"; import type { LovelaceCardEditor } from "../../types"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; -import type { EditorTarget, EntitiesEditorEvent } from "../types"; -import { configElementStyle } from "./config-elements-style"; const cardConfigStruct = assign( baseLovelaceCardConfig, @@ -43,75 +40,54 @@ export class HuiCalendarCardEditor { @property({ attribute: false }) public hass?: HomeAssistant; - @property({ attribute: false }) private _config?: CalendarCardConfig; - - @state() private _configEntities?: string[]; + @state() private _config?: CalendarCardConfig; public setConfig(config: CalendarCardConfig): void { assert(config, cardConfigStruct); this._config = config; - this._configEntities = config.entities; } - get _title(): string { - return this._config!.title || ""; - } - - get _initial_view(): string { - return this._config!.initial_view || "dayGridMonth"; - } - - get _theme(): string { - return this._config!.theme || ""; - } + private _schema = memoizeOne((localize: LocalizeFunc) => [ + { + name: "", + type: "grid", + schema: [ + { name: "title", required: false, selector: { text: {} } }, + { + name: "initial_view", + required: false, + selector: { + select: { + options: views.map((view) => [ + view, + localize( + `ui.panel.lovelace.editor.card.calendar.views.${view}` + ), + ]), + }, + }, + }, + ], + }, + { name: "theme", required: false, selector: { theme: {} } }, + ]); protected render(): TemplateResult { if (!this.hass || !this._config) { return html``; } + const schema = this._schema(this.hass.localize); + const data = { initial_view: "dayGridMonth", ...this._config }; + return html` -