mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Add color options to area card (#25881)
* Add color options to area card * Color all controls with the same color * Clean area card
This commit is contained in:
parent
b3f5eb256f
commit
dd64fa228c
@ -2,7 +2,6 @@ import { mdiFan, mdiLightbulb, mdiToggleSwitch } from "@mdi/js";
|
|||||||
import { callService, type HassEntity } from "home-assistant-js-websocket";
|
import { callService, type HassEntity } from "home-assistant-js-websocket";
|
||||||
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 { styleMap } from "lit/directives/style-map";
|
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import {
|
import {
|
||||||
generateEntityFilter,
|
generateEntityFilter,
|
||||||
@ -25,7 +24,6 @@ import { AREA_CONTROLS } from "./types";
|
|||||||
|
|
||||||
interface AreaControlsButton {
|
interface AreaControlsButton {
|
||||||
iconPath: string;
|
iconPath: string;
|
||||||
activeColor: string;
|
|
||||||
onService: string;
|
onService: string;
|
||||||
offService: string;
|
offService: string;
|
||||||
filter: EntityFilter;
|
filter: EntityFilter;
|
||||||
@ -37,7 +35,6 @@ export const AREA_CONTROLS_BUTTONS: Record<AreaControl, AreaControlsButton> = {
|
|||||||
filter: {
|
filter: {
|
||||||
domain: "light",
|
domain: "light",
|
||||||
},
|
},
|
||||||
activeColor: "var(--state-light-active-color)",
|
|
||||||
onService: "light.turn_on",
|
onService: "light.turn_on",
|
||||||
offService: "light.turn_off",
|
offService: "light.turn_off",
|
||||||
},
|
},
|
||||||
@ -46,7 +43,6 @@ export const AREA_CONTROLS_BUTTONS: Record<AreaControl, AreaControlsButton> = {
|
|||||||
filter: {
|
filter: {
|
||||||
domain: "fan",
|
domain: "fan",
|
||||||
},
|
},
|
||||||
activeColor: "var(--state-fan-active-color)",
|
|
||||||
onService: "fan.turn_on",
|
onService: "fan.turn_on",
|
||||||
offService: "fan.turn_off",
|
offService: "fan.turn_off",
|
||||||
},
|
},
|
||||||
@ -55,7 +51,6 @@ export const AREA_CONTROLS_BUTTONS: Record<AreaControl, AreaControlsButton> = {
|
|||||||
filter: {
|
filter: {
|
||||||
domain: "switch",
|
domain: "switch",
|
||||||
},
|
},
|
||||||
activeColor: "var(--state-switch-active-color)",
|
|
||||||
onService: "switch.turn_on",
|
onService: "switch.turn_on",
|
||||||
offService: "switch.turn_off",
|
offService: "switch.turn_off",
|
||||||
},
|
},
|
||||||
@ -223,7 +218,6 @@ class HuiAreaControlsCardFeature
|
|||||||
return html`
|
return html`
|
||||||
<ha-control-button
|
<ha-control-button
|
||||||
class=${active ? "active" : ""}
|
class=${active ? "active" : ""}
|
||||||
style=${styleMap({ "--active-color": button.activeColor })}
|
|
||||||
.control=${control}
|
.control=${control}
|
||||||
@click=${this._handleButtonTap}
|
@click=${this._handleButtonTap}
|
||||||
>
|
>
|
||||||
@ -240,7 +234,8 @@ class HuiAreaControlsCardFeature
|
|||||||
cardFeatureStyles,
|
cardFeatureStyles,
|
||||||
css`
|
css`
|
||||||
ha-control-button {
|
ha-control-button {
|
||||||
--active-color: var(--primary-color);
|
--active-color: var(--state-active-color);
|
||||||
|
--control-button-focus-color: var(--state-active-color);
|
||||||
}
|
}
|
||||||
ha-control-button.active {
|
ha-control-button.active {
|
||||||
--control-button-background-color: var(--active-color);
|
--control-button-background-color: var(--active-color);
|
||||||
|
@ -10,7 +10,9 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
|
import { computeCssColor } from "../../../common/color/compute-color";
|
||||||
import { BINARY_STATE_ON } from "../../../common/const";
|
import { BINARY_STATE_ON } from "../../../common/const";
|
||||||
import { computeAreaName } from "../../../common/entity/compute_area_name";
|
import { computeAreaName } from "../../../common/entity/compute_area_name";
|
||||||
import { generateEntityFilter } from "../../../common/entity/entity_filter";
|
import { generateEntityFilter } from "../../../common/entity/entity_filter";
|
||||||
@ -428,8 +430,16 @@ export class HuiAreaCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const ignoreAspectRatio = this.layout === "grid" || this.layout === "panel";
|
const ignoreAspectRatio = this.layout === "grid" || this.layout === "panel";
|
||||||
|
|
||||||
|
const color = this._config.color
|
||||||
|
? computeCssColor(this._config.color)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
"--tile-color": color,
|
||||||
|
};
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card style=${styleMap(style)}>
|
||||||
<div
|
<div
|
||||||
class="background"
|
class="background"
|
||||||
@action=${this._handleAction}
|
@action=${this._handleAction}
|
||||||
|
@ -103,6 +103,7 @@ export interface EntitiesCardConfig extends LovelaceCardConfig {
|
|||||||
export interface AreaCardConfig extends LovelaceCardConfig {
|
export interface AreaCardConfig extends LovelaceCardConfig {
|
||||||
area?: string;
|
area?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
color?: string;
|
||||||
navigation_path?: string;
|
navigation_path?: string;
|
||||||
display_type?: "compact" | "icon" | "picture" | "camera";
|
display_type?: "compact" | "icon" | "picture" | "camera";
|
||||||
/** @deprecated Use `display_type` instead */
|
/** @deprecated Use `display_type` instead */
|
||||||
|
@ -45,6 +45,7 @@ const cardConfigStruct = assign(
|
|||||||
object({
|
object({
|
||||||
area: optional(string()),
|
area: optional(string()),
|
||||||
name: optional(string()),
|
name: optional(string()),
|
||||||
|
color: optional(string()),
|
||||||
navigation_path: optional(string()),
|
navigation_path: optional(string()),
|
||||||
show_camera: optional(boolean()),
|
show_camera: optional(boolean()),
|
||||||
display_type: optional(enums(["compact", "icon", "picture", "camera"])),
|
display_type: optional(enums(["compact", "icon", "picture", "camera"])),
|
||||||
@ -94,6 +95,7 @@ export class HuiAreaCardEditor
|
|||||||
type: "grid",
|
type: "grid",
|
||||||
schema: [
|
schema: [
|
||||||
{ name: "name", selector: { text: {} } },
|
{ name: "name", selector: { text: {} } },
|
||||||
|
{ name: "color", selector: { ui_color: {} } },
|
||||||
{
|
{
|
||||||
name: "display_type",
|
name: "display_type",
|
||||||
required: true,
|
required: true,
|
||||||
@ -111,12 +113,6 @@ export class HuiAreaCardEditor
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
type: "grid",
|
|
||||||
schema: [
|
|
||||||
...(showCamera
|
...(showCamera
|
||||||
? ([
|
? ([
|
||||||
{
|
{
|
||||||
@ -480,7 +476,6 @@ export class HuiAreaCardEditor
|
|||||||
switch (schema.name) {
|
switch (schema.name) {
|
||||||
case "area":
|
case "area":
|
||||||
return this.hass!.localize("ui.panel.lovelace.editor.card.area.name");
|
return this.hass!.localize("ui.panel.lovelace.editor.card.area.name");
|
||||||
|
|
||||||
case "name":
|
case "name":
|
||||||
case "camera_view":
|
case "camera_view":
|
||||||
case "content":
|
case "content":
|
||||||
|
@ -7173,6 +7173,7 @@
|
|||||||
},
|
},
|
||||||
"area": {
|
"area": {
|
||||||
"name": "Area",
|
"name": "Area",
|
||||||
|
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
|
||||||
"alert_classes": "Alert classes",
|
"alert_classes": "Alert classes",
|
||||||
"alert_classes_helper": "In compact style, only the first one will be shown. Order alerts by priority.",
|
"alert_classes_helper": "In compact style, only the first one will be shown. Order alerts by priority.",
|
||||||
"sensor_classes": "Sensor classes",
|
"sensor_classes": "Sensor classes",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user