Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the possibility to set up icons as entity names - similar to headings #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
yarn-error.log
.nvmrc
.DS_Store
*.iml
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,23 @@ function createElement(tag, config, hass) {
}

function entityName(name, onClick = null) {
if (!Array.isArray(name)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, I can move this part to the function to make it more robust and reusable (the same logic, but a little different) is used in the heading.

name = [name];
}

const nameHtml = name.map((fragment) => {
if (isIcon(fragment)) {
return html`
<ha-icon class="heading-icon" .icon="${fragment}"></ha-icon>
`;
}
return html` <span>${fragment}</span> `;
});

if (onClick) {
return html` <a class="entity-name" @click=${onClick}>${name}</a> `;
return html` <a class="entity-name" @click=${onClick}>${nameHtml}</a> `;
}
return html` <span class="entity-name">${name}</span> `;
return html` <span class="entity-name">${nameHtml}</span> `;
}

class BannerCard extends LitElement {
Expand Down