Skip to content

Commit

Permalink
add TileCard styling (#137)
Browse files Browse the repository at this point in the history
* add TileCard styling

* Update custom-ui-only.js
  • Loading branch information
Mariusthvdb authored Jan 16, 2024
1 parent 5c70828 commit 262cd58
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion custom-ui-only.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Define constants for the custom-ui component
const Name = "Custom-ui only";
const Version = "20240110";
const Version = "20240116";
const Description = "add attributes icon_color and templates";
const Url = "https://github.com/Mariusthvdb/custom-ui";

Expand Down Expand Up @@ -135,6 +135,35 @@ window.customUI = {
});
},

// Install a hook to update the Tile card with custom styling
installTileCardStylingHook() {
customElements.whenDefined("hui-tile-card").then(() => {
const tileCard = customElements.get("hui-tile-card");
if (!tileCard) return;
if (tileCard.prototype?.updated) {
const originalUpdated = tileCard.prototype.updated;
tileCard.prototype.updated = function customUpdated(changedProps) {

if (
!changedProps.has('_config') ||
!changedProps.has('hass')
) {
return;
}
const { _config, hass } = this;
const entityId = _config?.entity;
const states = hass?.states;
const iconColor = states?.[entityId]?.attributes?.icon_color;

if (iconColor) {
this.style?.setProperty('--icon-primary-color', iconColor);
}
originalUpdated.call(this, changedProps);
}
}
});
},

// Install a hook to update the state badge with custom styling
installStateBadgeStylingHook() {
customElements.whenDefined("state-badge").then(() => {
Expand Down Expand Up @@ -166,6 +195,7 @@ window.customUI = {
window.customUI.installTemplateAttributesHook();
window.customUI.installButtonCardStylingHook();
window.customUI.installEntityCardStylingHook();
window.customUI.installTileCardStylingHook();
window.customUI.installStateBadgeStylingHook();
},

Expand Down

0 comments on commit 262cd58

Please sign in to comment.