mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-03 10:09:48 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fd1ed38fa |
No files matched your search
@@ -49,6 +49,25 @@ export const contentLayoutSchema = (localize: LocalizeFunc) =>
|
||||
},
|
||||
}) as const satisfies HaFormSchema;
|
||||
|
||||
const tileContentLayoutSchema = {
|
||||
name: "content_layout",
|
||||
required: true,
|
||||
selector: {
|
||||
select: {
|
||||
mode: "box",
|
||||
translation_key: "content_layout",
|
||||
options: ["horizontal", "vertical"].map((value) => ({
|
||||
value,
|
||||
image: {
|
||||
src: `/static/images/form/tile_content_layout_${value}.svg`,
|
||||
src_dark: `/static/images/form/tile_content_layout_${value}_dark.svg`,
|
||||
flip_rtl: true,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
} as const satisfies HaFormSchema;
|
||||
|
||||
export const displayedElementsSchema = (localize: LocalizeFunc) =>
|
||||
({
|
||||
name: "displayed_elements",
|
||||
@@ -66,10 +85,7 @@ export const displayedElementsSchema = (localize: LocalizeFunc) =>
|
||||
},
|
||||
}) as const satisfies HaFormSchema;
|
||||
|
||||
export const tileContentSchema = (
|
||||
localize: LocalizeFunc,
|
||||
showTimeFormat: boolean
|
||||
) =>
|
||||
export const tileContentSchema = (showTimeFormat: boolean) =>
|
||||
({
|
||||
name: "content",
|
||||
flatten: true,
|
||||
@@ -128,7 +144,7 @@ export const tileContentSchema = (
|
||||
ui_time_format: {},
|
||||
},
|
||||
},
|
||||
contentLayoutSchema(localize),
|
||||
tileContentLayoutSchema,
|
||||
],
|
||||
}) as const satisfies HaFormSchema;
|
||||
|
||||
|
||||
@@ -20,10 +20,7 @@ import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import { orderProperties } from "../../../../common/util/order-properties";
|
||||
import "../../../../components/ha-expansion-panel";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type {
|
||||
HaFormSchema,
|
||||
SchemaUnion,
|
||||
} from "../../../../components/ha-form/types";
|
||||
import type { HaFormSchema } from "../../../../components/ha-form/types";
|
||||
import "../../../../components/ha-svg-icon";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type {
|
||||
@@ -35,6 +32,7 @@ import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
import { editorTranslations } from "../editor-translations";
|
||||
import type { EditDetailElementEvent, EditSubElementEvent } from "../types";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
import {
|
||||
@@ -93,20 +91,16 @@ export class HuiTileCardEditor
|
||||
);
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(
|
||||
localize: LocalizeFunc,
|
||||
entityId: string | undefined,
|
||||
showTimeFormat: boolean
|
||||
) =>
|
||||
(entityId: string | undefined, showTimeFormat: boolean) =>
|
||||
[
|
||||
{ name: "entity", selector: { entity: {} } },
|
||||
tileContentSchema(localize, showTimeFormat),
|
||||
tileContentSchema(showTimeFormat),
|
||||
tileInteractionsSchema(entityId),
|
||||
] as const satisfies readonly HaFormSchema[]
|
||||
);
|
||||
|
||||
private _featuresSchema = memoizeOne(
|
||||
(localize: LocalizeFunc, vertical: boolean) =>
|
||||
(vertical: boolean) =>
|
||||
[
|
||||
{
|
||||
name: "features_position",
|
||||
@@ -114,13 +108,8 @@ export class HuiTileCardEditor
|
||||
selector: {
|
||||
select: {
|
||||
mode: "box",
|
||||
translation_key: "features_position",
|
||||
options: ["bottom", "inline"].map((value) => ({
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.features_position_options.${value}`
|
||||
),
|
||||
description: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.features_position_options.${value}_description`
|
||||
),
|
||||
value,
|
||||
image: {
|
||||
src: `/static/images/form/tile_features_position_${value}.svg`,
|
||||
@@ -135,6 +124,10 @@ export class HuiTileCardEditor
|
||||
] as const satisfies readonly HaFormSchema[]
|
||||
);
|
||||
|
||||
private _translations = memoizeOne((localize: LocalizeFunc) =>
|
||||
editorTranslations(localize, "ui.panel.lovelace.editor.card.tile.editor")
|
||||
);
|
||||
|
||||
private _hasCompatibleFeatures = memoizeOne(
|
||||
(context: LovelaceCardFeatureContext) =>
|
||||
getSupportedFeaturesType(this.hass!, context).length > 0
|
||||
@@ -155,11 +148,13 @@ export class HuiTileCardEditor
|
||||
this._config.state_content
|
||||
);
|
||||
|
||||
const schema = this._schema(this.hass.localize, entityId, showTimeFormat);
|
||||
const schema = this._schema(entityId, showTimeFormat);
|
||||
|
||||
const vertical = this._config.vertical ?? false;
|
||||
|
||||
const featuresSchema = this._featuresSchema(this.hass.localize, vertical);
|
||||
const featuresSchema = this._featuresSchema(vertical);
|
||||
|
||||
const translations = this._translations(this.hass.localize);
|
||||
|
||||
const data = tileContentFormData(this._config);
|
||||
|
||||
@@ -177,8 +172,9 @@ export class HuiTileCardEditor
|
||||
.hass=${this.hass}
|
||||
.data=${data}
|
||||
.schema=${schema}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
<ha-expansion-panel outlined>
|
||||
@@ -204,8 +200,9 @@ export class HuiTileCardEditor
|
||||
.hass=${this.hass}
|
||||
.data=${data}
|
||||
.schema=${featuresSchema}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`
|
||||
@@ -279,53 +276,6 @@ export class HuiTileCardEditor
|
||||
fireEvent(this, "config-changed", { config });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (
|
||||
schema:
|
||||
| SchemaUnion<ReturnType<typeof this._schema>>
|
||||
| SchemaUnion<ReturnType<typeof this._featuresSchema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "color":
|
||||
case "icon_tap_action":
|
||||
case "icon_hold_action":
|
||||
case "icon_double_tap_action":
|
||||
case "show_entity_picture":
|
||||
case "hide_state":
|
||||
case "state_content":
|
||||
case "content_layout":
|
||||
case "features_position":
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}`
|
||||
);
|
||||
default:
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private _computeHelperCallback = (
|
||||
schema:
|
||||
| SchemaUnion<ReturnType<typeof this._schema>>
|
||||
| SchemaUnion<ReturnType<typeof this._featuresSchema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "color":
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}_helper`
|
||||
);
|
||||
case "features_position":
|
||||
if (this._config?.vertical) {
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}_helper_vertical`
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
static get styles() {
|
||||
return [
|
||||
configElementStyle,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||
import type { HaFormSchema } from "../../../components/ha-form/types";
|
||||
|
||||
type EditorTranslationBase = `ui.panel.lovelace.editor.${string}`;
|
||||
|
||||
export interface EditorTranslations {
|
||||
computeLabel: (schema: HaFormSchema) => string;
|
||||
computeHelper: (schema: HaFormSchema) => string | undefined;
|
||||
localizeValue: (key: string) => string;
|
||||
}
|
||||
|
||||
export const editorTranslations = (
|
||||
localize: LocalizeFunc,
|
||||
base: EditorTranslationBase
|
||||
): EditorTranslations => ({
|
||||
computeLabel: (schema) => {
|
||||
if (schema.type === "expandable") {
|
||||
return localize(`${base}.sections.${schema.name}.name`);
|
||||
}
|
||||
return localize(`${base}.data.${schema.name}`);
|
||||
},
|
||||
computeHelper: (schema) => {
|
||||
if (schema.type === "expandable") {
|
||||
return localize(`${base}.sections.${schema.name}.description`);
|
||||
}
|
||||
return localize(`${base}.data_description.${schema.name}`);
|
||||
},
|
||||
localizeValue: (key) => localize(`${base}.selector.${key}`),
|
||||
});
|
||||
@@ -12231,6 +12231,56 @@
|
||||
"content_layout_options": {
|
||||
"horizontal": "Horizontal",
|
||||
"vertical": "Vertical"
|
||||
},
|
||||
"editor": {
|
||||
"sections": {
|
||||
"content": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::content%]"
|
||||
},
|
||||
"interactions": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::interactions%]"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"entity": "[%key:ui::panel::lovelace::editor::card::generic::entity%]",
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::name%]",
|
||||
"icon": "[%key:ui::panel::lovelace::editor::card::generic::icon%]",
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
|
||||
"show_entity_picture": "[%key:ui::panel::lovelace::editor::card::tile::show_entity_picture%]",
|
||||
"hide_state": "[%key:ui::panel::lovelace::editor::card::tile::hide_state%]",
|
||||
"state_content": "[%key:ui::panel::lovelace::editor::card::tile::state_content%]",
|
||||
"time_format": "[%key:ui::panel::lovelace::editor::card::generic::time_format%]",
|
||||
"content_layout": "[%key:ui::panel::lovelace::editor::card::tile::content_layout%]",
|
||||
"tap_action": "[%key:ui::panel::lovelace::editor::card::generic::tap_action%]",
|
||||
"icon_tap_action": "[%key:ui::panel::lovelace::editor::card::tile::icon_tap_action%]",
|
||||
"hold_action": "[%key:ui::panel::lovelace::editor::card::generic::hold_action%]",
|
||||
"icon_hold_action": "[%key:ui::panel::lovelace::editor::card::tile::icon_hold_action%]",
|
||||
"double_tap_action": "[%key:ui::panel::lovelace::editor::card::generic::double_tap_action%]",
|
||||
"icon_double_tap_action": "[%key:ui::panel::lovelace::editor::card::tile::icon_double_tap_action%]",
|
||||
"features_position": "[%key:ui::panel::lovelace::editor::card::tile::features_position%]"
|
||||
},
|
||||
"data_description": {
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color_helper%]",
|
||||
"features_position": "[%key:ui::panel::lovelace::editor::card::tile::features_position_helper_vertical%]"
|
||||
},
|
||||
"selector": {
|
||||
"content_layout": {
|
||||
"options": {
|
||||
"horizontal": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::horizontal%]",
|
||||
"vertical": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::vertical%]"
|
||||
}
|
||||
},
|
||||
"features_position": {
|
||||
"options": {
|
||||
"bottom": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::bottom%]",
|
||||
"inline": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::inline%]"
|
||||
},
|
||||
"options_description": {
|
||||
"bottom": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::bottom_description%]",
|
||||
"inline": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::inline_description%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"vertical-stack": {
|
||||
|
||||
Reference in new issue
Block a user