mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Improve card features editor (#22023)
* Move expansion panel outside of feature component * Cache main form and feature form
This commit is contained in:
parent
5920efa2b2
commit
7de5c46f14
@ -34,4 +34,21 @@ export const configElementStyle = css`
|
|||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
ha-expansion-panel {
|
||||||
|
display: block;
|
||||||
|
--expansion-panel-content-padding: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
--ha-card-border-radius: 6px;
|
||||||
|
}
|
||||||
|
ha-expansion-panel .content {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
ha-expansion-panel > * {
|
||||||
|
margin: 0;
|
||||||
|
font-size: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
}
|
||||||
|
ha-expansion-panel ha-svg-icon {
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { mdiDelete, mdiDrag, mdiListBox, mdiPencil, mdiPlus } from "@mdi/js";
|
import { mdiDelete, mdiDrag, mdiPencil, mdiPlus } from "@mdi/js";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
|
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||||
import "../../../../components/entity/ha-entity-picker";
|
|
||||||
import "../../../../components/ha-button";
|
import "../../../../components/ha-button";
|
||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
import "../../../../components/ha-list-item";
|
import "../../../../components/ha-list-item";
|
||||||
@ -236,12 +235,6 @@ export class HuiCardFeaturesEditor extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-expansion-panel outlined>
|
|
||||||
<h3 slot="header">
|
|
||||||
<ha-svg-icon .path=${mdiListBox}></ha-svg-icon>
|
|
||||||
${this.hass!.localize("ui.panel.lovelace.editor.features.name")}
|
|
||||||
</h3>
|
|
||||||
<div class="content">
|
|
||||||
${supportedFeaturesType.length === 0 && this.features.length === 0
|
${supportedFeaturesType.length === 0 && this.features.length === 0
|
||||||
? html`
|
? html`
|
||||||
<ha-alert type="info">
|
<ha-alert type="info">
|
||||||
@ -251,10 +244,7 @@ export class HuiCardFeaturesEditor extends LitElement {
|
|||||||
</ha-alert>
|
</ha-alert>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
<ha-sortable
|
<ha-sortable handle-selector=".handle" @item-moved=${this._featureMoved}>
|
||||||
handle-selector=".handle"
|
|
||||||
@item-moved=${this._featureMoved}
|
|
||||||
>
|
|
||||||
<div class="features">
|
<div class="features">
|
||||||
${repeat(
|
${repeat(
|
||||||
this.features,
|
this.features,
|
||||||
@ -347,8 +337,6 @@ export class HuiCardFeaturesEditor extends LitElement {
|
|||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
|
||||||
</ha-expansion-panel>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,23 +397,6 @@ export class HuiCardFeaturesEditor extends LitElement {
|
|||||||
display: flex !important;
|
display: flex !important;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
.content {
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
ha-expansion-panel {
|
|
||||||
display: block;
|
|
||||||
--expansion-panel-content-padding: 0;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
h3 {
|
|
||||||
margin: 0;
|
|
||||||
font-size: inherit;
|
|
||||||
font-weight: inherit;
|
|
||||||
}
|
|
||||||
ha-svg-icon,
|
|
||||||
ha-icon {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
|
||||||
ha-button-menu {
|
ha-button-menu {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { mdiListBox } from "@mdi/js";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { cache } from "lit/directives/cache";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import {
|
import {
|
||||||
any,
|
any,
|
||||||
@ -12,11 +14,13 @@ import {
|
|||||||
string,
|
string,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import "../../../../components/ha-expansion-panel";
|
||||||
import "../../../../components/ha-form/ha-form";
|
import "../../../../components/ha-form/ha-form";
|
||||||
import type {
|
import type {
|
||||||
HaFormSchema,
|
HaFormSchema,
|
||||||
SchemaUnion,
|
SchemaUnion,
|
||||||
} from "../../../../components/ha-form/types";
|
} from "../../../../components/ha-form/types";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import {
|
import {
|
||||||
LovelaceCardFeatureConfig,
|
LovelaceCardFeatureConfig,
|
||||||
@ -27,6 +31,7 @@ import type { LovelaceCardEditor } from "../../types";
|
|||||||
import "../hui-sub-element-editor";
|
import "../hui-sub-element-editor";
|
||||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||||
import { EditSubElementEvent, SubElementEditorConfig } from "../types";
|
import { EditSubElementEvent, SubElementEditorConfig } from "../types";
|
||||||
|
import { configElementStyle } from "./config-elements-style";
|
||||||
import "./hui-card-features-editor";
|
import "./hui-card-features-editor";
|
||||||
import type { FeatureType } from "./hui-card-features-editor";
|
import type { FeatureType } from "./hui-card-features-editor";
|
||||||
|
|
||||||
@ -93,16 +98,20 @@ export class HuiHumidifierCardEditor
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateObj = this._config.entity
|
return cache(
|
||||||
? this.hass.states[this._config.entity]
|
this._subElementEditorConfig
|
||||||
: undefined;
|
? this._renderFeatureForm()
|
||||||
|
: this._renderForm()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this._subElementEditorConfig) {
|
private _renderFeatureForm() {
|
||||||
|
const entityId = this._config!.entity;
|
||||||
return html`
|
return html`
|
||||||
<hui-sub-element-editor
|
<hui-sub-element-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.config=${this._subElementEditorConfig}
|
.config=${this._subElementEditorConfig}
|
||||||
.context=${this._context(this._config.entity)}
|
.context=${this._context(entityId)}
|
||||||
@go-back=${this._goBack}
|
@go-back=${this._goBack}
|
||||||
@config-changed=${this.subElementChanged}
|
@config-changed=${this.subElementChanged}
|
||||||
>
|
>
|
||||||
@ -110,6 +119,10 @@ export class HuiHumidifierCardEditor
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderForm() {
|
||||||
|
const entityId = this._config!.entity;
|
||||||
|
const stateObj = entityId ? this.hass!.states[entityId] : undefined;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -118,6 +131,14 @@ export class HuiHumidifierCardEditor
|
|||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
|
<ha-expansion-panel outlined>
|
||||||
|
<h3 slot="header">
|
||||||
|
<ha-svg-icon .path=${mdiListBox}></ha-svg-icon>
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.card.generic.features"
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<div class="content">
|
||||||
<hui-card-features-editor
|
<hui-card-features-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
@ -126,6 +147,8 @@ export class HuiHumidifierCardEditor
|
|||||||
@features-changed=${this._featuresChanged}
|
@features-changed=${this._featuresChanged}
|
||||||
@edit-detail-element=${this._editDetailElement}
|
@edit-detail-element=${this._editDetailElement}
|
||||||
></hui-card-features-editor>
|
></hui-card-features-editor>
|
||||||
|
</div>
|
||||||
|
</ha-expansion-panel>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,12 +225,15 @@ export class HuiHumidifierCardEditor
|
|||||||
};
|
};
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return css`
|
return [
|
||||||
|
configElementStyle,
|
||||||
|
css`
|
||||||
ha-form {
|
ha-form {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
`;
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { mdiListBox } from "@mdi/js";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { cache } from "lit/directives/cache";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import {
|
import {
|
||||||
any,
|
any,
|
||||||
@ -12,11 +14,13 @@ import {
|
|||||||
string,
|
string,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import "../../../../components/ha-expansion-panel";
|
||||||
import "../../../../components/ha-form/ha-form";
|
import "../../../../components/ha-form/ha-form";
|
||||||
import type {
|
import type {
|
||||||
HaFormSchema,
|
HaFormSchema,
|
||||||
SchemaUnion,
|
SchemaUnion,
|
||||||
} from "../../../../components/ha-form/types";
|
} from "../../../../components/ha-form/types";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import {
|
import {
|
||||||
LovelaceCardFeatureConfig,
|
LovelaceCardFeatureConfig,
|
||||||
@ -27,6 +31,7 @@ import type { LovelaceCardEditor } from "../../types";
|
|||||||
import "../hui-sub-element-editor";
|
import "../hui-sub-element-editor";
|
||||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||||
import { EditSubElementEvent, SubElementEditorConfig } from "../types";
|
import { EditSubElementEvent, SubElementEditorConfig } from "../types";
|
||||||
|
import { configElementStyle } from "./config-elements-style";
|
||||||
import "./hui-card-features-editor";
|
import "./hui-card-features-editor";
|
||||||
import type { FeatureType } from "./hui-card-features-editor";
|
import type { FeatureType } from "./hui-card-features-editor";
|
||||||
|
|
||||||
@ -91,16 +96,19 @@ export class HuiThermostatCardEditor
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateObj = this._config.entity
|
return cache(
|
||||||
? this.hass.states[this._config.entity]
|
this._subElementEditorConfig
|
||||||
: undefined;
|
? this._renderFeatureForm()
|
||||||
|
: this._renderForm()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this._subElementEditorConfig) {
|
private _renderFeatureForm() {
|
||||||
return html`
|
return html`
|
||||||
<hui-sub-element-editor
|
<hui-sub-element-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.config=${this._subElementEditorConfig}
|
.config=${this._subElementEditorConfig}
|
||||||
.context=${this._context(this._config.entity)}
|
.context=${this._context(this._config!.entity)}
|
||||||
@go-back=${this._goBack}
|
@go-back=${this._goBack}
|
||||||
@config-changed=${this.subElementChanged}
|
@config-changed=${this.subElementChanged}
|
||||||
>
|
>
|
||||||
@ -108,6 +116,10 @@ export class HuiThermostatCardEditor
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderForm() {
|
||||||
|
const entityId = this._config!.entity;
|
||||||
|
const stateObj = entityId ? this.hass!.states[entityId] : undefined;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -116,6 +128,14 @@ export class HuiThermostatCardEditor
|
|||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
|
<ha-expansion-panel outlined>
|
||||||
|
<h3 slot="header">
|
||||||
|
<ha-svg-icon .path=${mdiListBox}></ha-svg-icon>
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.card.generic.features"
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<div class="content">
|
||||||
<hui-card-features-editor
|
<hui-card-features-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
@ -124,6 +144,8 @@ export class HuiThermostatCardEditor
|
|||||||
@features-changed=${this._featuresChanged}
|
@features-changed=${this._featuresChanged}
|
||||||
@edit-detail-element=${this._editDetailElement}
|
@edit-detail-element=${this._editDetailElement}
|
||||||
></hui-card-features-editor>
|
></hui-card-features-editor>
|
||||||
|
</div>
|
||||||
|
</ha-expansion-panel>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +222,15 @@ export class HuiThermostatCardEditor
|
|||||||
};
|
};
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return css`
|
return [
|
||||||
|
configElementStyle,
|
||||||
|
css`
|
||||||
ha-form {
|
ha-form {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
`;
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { mdiGestureTap, mdiPalette } from "@mdi/js";
|
import { mdiGestureTap, mdiListBox, mdiPalette } from "@mdi/js";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { cache } from "lit/directives/cache";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import {
|
import {
|
||||||
any,
|
any,
|
||||||
@ -14,11 +15,13 @@ import {
|
|||||||
union,
|
union,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import "../../../../components/ha-expansion-panel";
|
||||||
import "../../../../components/ha-form/ha-form";
|
import "../../../../components/ha-form/ha-form";
|
||||||
import type {
|
import type {
|
||||||
HaFormSchema,
|
HaFormSchema,
|
||||||
SchemaUnion,
|
SchemaUnion,
|
||||||
} from "../../../../components/ha-form/types";
|
} from "../../../../components/ha-form/types";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import {
|
import {
|
||||||
LovelaceCardFeatureConfig,
|
LovelaceCardFeatureConfig,
|
||||||
@ -168,21 +171,19 @@ export class HuiTileCardEditor
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateObj = this._config.entity
|
return cache(
|
||||||
? this.hass.states[this._config.entity]
|
this._subElementEditorConfig
|
||||||
: undefined;
|
? this._renderFeatureForm()
|
||||||
|
: this._renderForm()
|
||||||
const schema = this._schema(
|
|
||||||
this._config.entity,
|
|
||||||
this._config.hide_state ?? false
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this._subElementEditorConfig) {
|
private _renderFeatureForm() {
|
||||||
return html`
|
return html`
|
||||||
<hui-sub-element-editor
|
<hui-sub-element-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.config=${this._subElementEditorConfig}
|
.config=${this._subElementEditorConfig}
|
||||||
.context=${this._context(this._config.entity)}
|
.context=${this._context(this._config!.entity)}
|
||||||
@go-back=${this._goBack}
|
@go-back=${this._goBack}
|
||||||
@config-changed=${this.subElementChanged}
|
@config-changed=${this.subElementChanged}
|
||||||
>
|
>
|
||||||
@ -190,6 +191,12 @@ export class HuiTileCardEditor
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderForm() {
|
||||||
|
const entityId = this._config!.entity;
|
||||||
|
const stateObj = entityId ? this.hass!.states[entityId] : undefined;
|
||||||
|
|
||||||
|
const schema = this._schema(entityId, this._config!.hide_state ?? false);
|
||||||
|
|
||||||
const data = this._config;
|
const data = this._config;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@ -200,6 +207,14 @@ export class HuiTileCardEditor
|
|||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
|
<ha-expansion-panel outlined>
|
||||||
|
<h3 slot="header">
|
||||||
|
<ha-svg-icon .path=${mdiListBox}></ha-svg-icon>
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.card.generic.features"
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<div class="content">
|
||||||
<hui-card-features-editor
|
<hui-card-features-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
@ -207,6 +222,8 @@ export class HuiTileCardEditor
|
|||||||
@features-changed=${this._featuresChanged}
|
@features-changed=${this._featuresChanged}
|
||||||
@edit-detail-element=${this._editDetailElement}
|
@edit-detail-element=${this._editDetailElement}
|
||||||
></hui-card-features-editor>
|
></hui-card-features-editor>
|
||||||
|
</div>
|
||||||
|
</ha-expansion-panel>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5989,7 +5989,8 @@
|
|||||||
"state_color": "Color icons based on state?",
|
"state_color": "Color icons based on state?",
|
||||||
"suggested_cards": "Suggested cards",
|
"suggested_cards": "Suggested cards",
|
||||||
"other_cards": "Other cards",
|
"other_cards": "Other cards",
|
||||||
"custom_cards": "Custom cards"
|
"custom_cards": "Custom cards",
|
||||||
|
"features": "Features"
|
||||||
},
|
},
|
||||||
"map": {
|
"map": {
|
||||||
"name": "Map",
|
"name": "Map",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user