Skip to content

Commit b4f00f9

Browse files
authored
fix(color): inactive card background no longer inactive color when colour_type: card and color set. (#987)
BREAKING CHANGE: Card background color will always be `var (--card-background-color)` when state is inactive and `color_type: card`. You can set card background with state. Fixes #754
1 parent d01ef37 commit b4f00f9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Lovelace Button card for your entities.
106106
| `group_expand` | boolean | false | `true` \| `false` | When `true`, if any of the entities triggering a card update is a group, it will auto-expand the group and the card will update on any child entity state change. This works with nested groups too. See [triggers_update](#triggers_update) |
107107
| `icon` | string | optional | `mdi:air-conditioner` | Icon to display. Will be overridden by the icon defined in a state (if present). Defaults to the entity icon. Hide with `show_icon: false`. Supports templates, see [templates](#javascript-templates) |
108108
| `color_type` | string | `icon` | `icon` \| `card` \| `blank-card` \| `label-card` | Color either the background of the card or the icon inside the card. Setting this to `card` enable automatic `font` and `icon` color. This allows the text/icon to be readable even if the background color is bright/dark. Additional color-type options `blank-card` and `label-card` can be used for organisation (see examples). |
109-
| `color` | string | optional | `auto` \| `auto-no-temperature` \| `rgb(28, 128, 199)` | Color of the icon/card. `auto` sets the color based on the color of a light including the temperature of the light. Setting this to `auto-no-temperature` will behave like home-assistant's default, ignoring the temperature of the light. By default, if the entity state is `off`, the color will be `var(--paper-item-icon-color)`, for `on` it will be `var(--paper-item-icon-active-color)` and for any other state it will be `var(--primary-text-color)`. You can redefine each colors using `state` |
109+
| `color` | string | optional | `auto` \| `auto-no-temperature` \| `rgb(28, 128, 199)` | Color of the icon/card. `auto` sets the color based on the color of a light including the temperature of the light. Setting this to `auto-no-temperature` will behave like home-assistant's default, ignoring the temperature of the light. By default, if the entity state is `off`, the color will be `var(--state-inactive-color)` for icon and `var (--card-background-color)` for card, for `on` it will be `var(--state-active-color)` and for any other state it will be `var(--primary-text-color)`. You can redefine each colors using `state` |
110110
| `size` | string | `40%` | `20px` | Size of the icon. Can be percentage or pixel |
111111
| `aspect_ratio` | string | optional | `1/1`, `2/1`, `1/1.5`, ... | See [here](#aspect-ratio) for an example. Aspect ratio of the card. `1/1` being a square. This will auto adapt to your screen size |
112112
| `tap_action` | object | optional | See [Action](#Action) | Define the type of action on click, if undefined, toggle will be used for domains that support toggle, or button press for input_button. |

src/button-card.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,8 @@ class ButtonCard extends LitElement {
983983
if (this._stateObj) {
984984
if (stateActive(this._stateObj)) {
985985
color = this._config?.color || color;
986+
} else {
987+
color = stateColorCss(this._stateObj, this._stateObj.state, this._config?.color_type) || DEFAULT_COLOR;
986988
}
987989
} else {
988990
color = this._config.color;

test/ui-lovelace.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,28 @@ views:
853853
card:
854854
- height: 200px
855855

856+
- type: vertical-stack
857+
cards:
858+
- type: 'custom:button-card'
859+
color_type: label-card
860+
styles:
861+
card:
862+
- font-weight: bold
863+
- text-transform: uppercase
864+
name: Color custom
865+
- type: horizontal-stack
866+
cards:
867+
- type: 'custom:button-card'
868+
entity: switch.skylight
869+
color_type: icon
870+
color: lightpink
871+
name: 'color_type: icon'
872+
- type: 'custom:button-card'
873+
color_type: card
874+
color: lightpink
875+
entity: switch.skylight
876+
name: 'color_type: card'
877+
856878
- type: vertical-stack
857879
cards:
858880
- type: 'custom:button-card'

0 commit comments

Comments
 (0)