-
Notifications
You must be signed in to change notification settings - Fork 3k
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
If entity has "entity_picture" - allow using a CSS theme var for border-radius #24248
base: dev
Are you sure you want to change the base?
If entity has "entity_picture" - allow using a CSS theme var for border-radius #24248
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea but we really have to come up with a strategy and docs for theme variables before adding new ones. It's too messy right now
src/components/entity/state-badge.ts
Outdated
@@ -180,6 +180,9 @@ export class StateBadge extends LitElement { | |||
this.style.borderRadius = "0"; | |||
} else if (domain === "media_player" || domain === "camera") { | |||
this.style.borderRadius = "8%"; | |||
} else if (backgroundImage !== "") { | |||
this.style.borderRadius = | |||
"var(--state-badge-with-image-border-radius, 50%)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the normal styles of :host
, where we now have border-radius: 50%;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I moved a default "50%" out of "styles" for :host
, is it better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you mean moving inside styles()?
:host {
...
border-radius: ${some_variable};
...
Did this in e67b1e1.
Update: failed to do this since styles() is a static function. Reverted back to use this.style.borderRadius
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he meant just setting border-radius: var(--state-badge-with-image-border-radius, 50%)
in styles
but then it won't be only for images. We could just add a class has-image
and set it based on that though. Then we could have a general --state-badge-border-radius
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go that route, lets do the same for the other cases so we have less inline styles 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the latest commit added 3 classes:
A class is defined in _getClass()
method.
And now we have 3 theme variables:
--state-badge-border-radius #for any entity (unless overridden)
--state-badge-with-media-image-border-radius #currently - for media_player & camera
--state-badge-with-image-border-radius #for entity with an image
If this is OK - then we need to add a class to :host
itself.
But here I am not sure how it is better to do it.
Will this work?
this.classList.add(_getClass());
Also, I think we should remove a previous class before adding a proper class. But I am not sure how to do it))). Can I use
this.classList.remove(...this.classList); //purge first
this.classList.add(_getClass()); //then set the class
?
Breaking change
Proposed change
Related to #24187
Proposing a new CSS theme variable -
--state-badge-with-image-border-radius
.A name may be changed.
It is used for a
state-badge
element for entities withentity_picture
defined (or overridden by another image somehow).By default a current
50%
value is used.Not related to
update
,camera
&media_player
entities.Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: