-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new custom-ui for icon_color only
Taking out all functionality except adding icon_color only. This enables icon_color in ```customize``` on all entities in HA, but also the use of an icon_color attribute in integrations that allow for customized attributes, like Template. With the later option, one can also use templates to have dynamic icon_color
1 parent
87f41bf
commit f57b71e
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const Name = "Custom-ui"; | ||
const Version = "20231126"; | ||
const Description = "add icon_color to UI"; | ||
const Url = "https://github.com/Mariusthvdb/custom-ui"; | ||
console.info( | ||
`%c ${Name} \n%c Version ${Version} ${Description}`, | ||
"color: gold; font-weight: bold; background: black", | ||
"color: white; font-weight: bold; background: steelblue" | ||
); | ||
window.customUI = { | ||
installStateBadge() { | ||
customElements.whenDefined("state-badge").then(() => { | ||
const stateBadge = customElements.get("state-badge"); | ||
if (!stateBadge) return; | ||
if (stateBadge.prototype?.updated) { | ||
const originalUpdated = stateBadge.prototype.updated; | ||
stateBadge.prototype.updated = function customUpdated(changedProps) { | ||
if (!changedProps.has("stateObj")) return; | ||
const { stateObj } = this; | ||
if ( | ||
stateObj.attributes.icon_color && | ||
!stateObj.attributes.entity_picture | ||
) { | ||
this.style.backgroundImage = ""; | ||
this._showIcon = true; | ||
this._iconStyle = { | ||
color: stateObj.attributes.icon_color | ||
}; | ||
} | ||
originalUpdated.call(this, changedProps); | ||
}; | ||
} | ||
}); | ||
}, | ||
installClassHooks() { | ||
window.customUI.installStateBadge(); | ||
}, | ||
init() { | ||
if (window.customUI.initDone) return; | ||
window.customUI.installClassHooks(); | ||
window.CUSTOM_UI_LIST = window.CUSTOM_UI_LIST || []; | ||
window.CUSTOM_UI_LIST.push({ | ||
name: Name, | ||
version: `${Version} ${Description}`, | ||
url: Url | ||
}); | ||
}, | ||
|
||
}; | ||
window.customUI.init(); |