Transparent unavailable state in history (#14710)

* Use transparent color for unavailable state for history

* Remove inactive color

* Only color active state for badge icon

* Simplify condition

* Update src/components/chart/timeline-chart/textbar-element.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Paul Bottein 2022-12-12 15:52:33 +01:00 committed by GitHub
parent 544272b4df
commit 0fb35fd0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 35 deletions

View File

@ -4,7 +4,6 @@ export const THEME_COLORS = new Set([
"primary",
"accent",
"disabled",
"inactive",
"red",
"pink",
"purple",

View File

@ -37,8 +37,11 @@ export class TextBarElement extends BarElement {
}
const textColor =
options.textColor ||
(options.backgroundColor &&
(luminosity(hex2rgb(options.backgroundColor)) > 0.5 ? "#000" : "#fff"));
(options?.backgroundColor === "transparent"
? "transparent"
: luminosity(hex2rgb(options.backgroundColor)) > 0.5
? "#000"
: "#fff");
// ctx.font = "12px arial";
ctx.fillStyle = textColor;

View File

@ -51,9 +51,7 @@ function computeTimelineStateColor(
stateObj?: HassEntity
): string | undefined {
if (!stateObj || state === UNAVAILABLE) {
const rgb = cssToRgb("--rgb-state-unavailable-color", computedStyles);
if (!rgb) return undefined;
return rgb2hex(rgb);
return "transparent";
}
const color = stateColor(stateObj, state);

View File

@ -107,12 +107,11 @@ export class StateBadge extends LitElement {
}
hostStyle.backgroundImage = `url(${imageUrl})`;
this._showIcon = false;
} else if (this._stateColor) {
} else if (this._stateColor && stateActive(stateObj)) {
const color = stateColorCss(stateObj);
if (color) {
iconStyle.color = `rgb(${color})`;
}
if (stateActive(stateObj)) {
if (stateObj.attributes.rgb_color) {
iconStyle.color = `rgb(${stateObj.attributes.rgb_color.join(",")})`;
}
@ -129,7 +128,6 @@ export class StateBadge extends LitElement {
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
}
}
}
} else if (this.overrideImage) {
let imageUrl = this.overrideImage;
if (this.hass) {

View File

@ -156,8 +156,8 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
? this._config.name || (stateObj ? computeStateName(stateObj) : "")
: "";
const colored = stateObj && this.getStateColor(stateObj, this._config);
const active = stateObj && colored && stateActive(stateObj);
const active = stateObj && stateActive(stateObj);
const colored = active && this.getStateColor(stateObj, this._config);
return html`
<ha-card
@ -316,7 +316,9 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
return "";
}
private _computeColor(stateObj: HassEntity | LightEntity): string {
private _computeColor(
stateObj: HassEntity | LightEntity
): string | undefined {
if (stateObj.attributes.rgb_color && stateActive(stateObj)) {
return `rgb(${stateObj.attributes.rgb_color.join(",")})`;
}
@ -324,7 +326,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
if (iconColor) {
return `rgb(${iconColor})`;
}
return "";
return undefined;
}
private _handleAction(ev: ActionHandlerEvent) {

View File

@ -133,8 +133,8 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
const name = this._config.name || computeStateName(stateObj);
const colored = stateObj && this.getStateColor(stateObj, this._config);
const active = stateObj && colored && stateActive(stateObj);
const active = stateObj && stateActive(stateObj);
const colored = active && this.getStateColor(stateObj, this._config);
return html`
<ha-card @click=${this._handleClick} tabindex="0">
@ -193,12 +193,14 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
`;
}
private _computeColor(stateObj: HassEntity | LightEntity): string {
private _computeColor(
stateObj: HassEntity | LightEntity
): string | undefined {
const iconColor = stateColorCss(stateObj);
if (iconColor) {
return `rgb(${iconColor})`;
}
return "";
return undefined;
}
protected shouldUpdate(changedProps: PropertyValues): boolean {

View File

@ -107,7 +107,6 @@ documentContainer.innerHTML = `<custom-style>
--rgb-primary-color: 3, 169, 244;
--rgb-accent-color: 255, 152, 0;
--rgb-disabled-color: 189, 189, 189;
--rgb-inactive-color: 114, 114, 114;
--rgb-primary-text-color: 33, 33, 33;
--rgb-secondary-text-color: 114, 114, 114;
--rgb-text-primary-color: 255, 255, 255;
@ -136,13 +135,13 @@ documentContainer.innerHTML = `<custom-style>
/* rgb state color */
--rgb-state-default-color: var(--rgb-dark-primary-color, 68, 115, 158);
--rgb-state-inactive-color: var(--rgb-inactive-color);
--rgb-state-inactive-color: var(--rgb-grey-color);
--rgb-state-unavailable-color: var(--rgb-disabled-color);
/* rgb state domain colors */
--rgb-state-alarm-armed-color: var(--rgb-green-color);
--rgb-state-alarm-arming-color: var(--rgb-orange-color);
--rgb-state-alarm-disarmed-color: var(--rgb-inactive-color);
--rgb-state-alarm-disarmed-color: var(--rgb-grey-color);
--rgb-state-alarm-pending-color: var(--rgb-orange-color);
--rgb-state-alarm-triggered-color: var(--rgb-red-color);
--rgb-state-alert-color: var(--rgb-red-color);
@ -170,7 +169,7 @@ documentContainer.innerHTML = `<custom-style>
--rgb-state-lock-unlocked-color: var(--rgb-red-color);
--rgb-state-media-player-color: var(--rgb-light-blue-color);
--rgb-state-person-home-color: var(--rgb-green-color);
--rgb-state-person-not-home-color: var(--rgb-inactive-color);
--rgb-state-person-not-home-color: var(--rgb-grey-color);
--rgb-state-person-zone-color: var(--rgb-blue-color);
--rgb-state-remote-color: var(--rgb-amber-color);
--rgb-state-script-color: var(--rgb-amber-color);

View File

@ -49,7 +49,6 @@ export const darkStyles = {
"map-filter":
"invert(.9) hue-rotate(170deg) brightness(1.5) contrast(1.2) saturate(.3)",
"rgb-disabled-color": "70, 70, 70",
"rgb-inactive-color": "141, 141, 141",
};
export const derivedStyles = {