Skip to content

Commit

Permalink
Support setting the heading color as part of the config, fallback wil…
Browse files Browse the repository at this point in the history
…l be automatic color discovery
  • Loading branch information
nervetattoo committed Aug 19, 2019
1 parent 14b140e commit 5866f29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ resources:
| -------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| heading | _string_ | The heading to display. Remember to escape | `heading: "\U0001F6CB Living room"` |
| background | _string_ | A valid CSS color to use as the background | `background: "#EDE7B0"`, `background: red` |
| color | _string_ | A valid CSS color to use as the text color | `color: "#EDE7B0"`, `color: red` |
| link | _string_ | A link, to a different view in HA for example | `link: /lovelace/living_room` |
| entities | _array_ | An array of entities to display for glances. Either as strings or as objects | `entities: [binary_sensor.remote_ui]` |
| row_size | _number_ | Configure number of "entity cells" in the grid before it wraps to a new line. 3 is the default and what looks best _in most cases_ | `row_size: 4` |
Expand Down
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BannerCard extends LitElement {
static get properties() {
return {
config: Object,
oclor: String,

This comment has been minimized.

Copy link
@WhistleMaster

WhistleMaster Aug 19, 2019

A little typo I guess, should be 'color'

This comment has been minimized.

Copy link
@nervetattoo

nervetattoo Aug 19, 2019

Author Owner

Amazing how much crap I can pull off when doing something hastily

gridSizes: Array,
entities: Array,
entityValues: Array,
Expand Down Expand Up @@ -46,6 +47,14 @@ class BannerCard extends LitElement {
this.entities = (config.entities || []).map(parseEntity);
this.config = config;

this.color =
config.color ||
readableColor(
config.background,
"var(--bc-heading-color-light)",
"var(--bc-heading-color-dark)"
);

if (typeof config.row_size !== "undefined") {
if (config.row_size < 1) {
throw new Error("row_size must be at least 1");
Expand Down Expand Up @@ -140,15 +149,9 @@ class BannerCard extends LitElement {
return null;
}

const color = readableColor(
this.config.background,
"var(--bc-heading-color-light)",
"var(--bc-heading-color-dark)"
);

const onClick = () => this.config.link && this.navigate(this.config.link);
return html`
<h2 class="heading" style="color: ${color};" @click=${onClick}>
<h2 class="heading" @click=${onClick} style="color: ${this.color};">
${this.config.heading}
</h2>
`;
Expand Down

0 comments on commit 5866f29

Please sign in to comment.