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

If entity has "entity_picture" - allow using a CSS theme var for border-radius #24248

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

ildar170975
Copy link
Contributor

@ildar170975 ildar170975 commented Feb 14, 2025

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 with entity_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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@ildar170975 ildar170975 marked this pull request as ready for review February 14, 2025 20:55
Copy link
Contributor

@MindFreeze MindFreeze left a 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

@@ -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%)";
Copy link
Member

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%;.

Copy link
Contributor Author

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?

Copy link
Contributor Author

@ildar170975 ildar170975 Feb 25, 2025

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.

Copy link
Contributor

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

Copy link
Member

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 👍

Copy link
Contributor Author

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:
image

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

?

@ildar170975 ildar170975 marked this pull request as draft February 25, 2025 06:29
@ildar170975 ildar170975 marked this pull request as ready for review February 25, 2025 07:34
@ildar170975 ildar170975 marked this pull request as draft February 26, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants