-
Notifications
You must be signed in to change notification settings - Fork 28
[AdminUi] Add badge field component with enum support #308
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
base: main
Are you sure you want to change the base?
[AdminUi] Add badge field component with enum support #308
Conversation
loic425
left a comment
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.
Thx for your proposal. It's an interesting idea.
1/ You Twig template has too much complexity
2/ test_html_attribute placed on color is strange
3/ magic with getLabel, getColor without any interface is not cool.
|
Thanks for the feedback! I've refactored the badge implementation to address all concerns:
Created proper architecture with value objects and Twig extension. Documentation included. Let me know if you need any changes! |
| * This class normalizes badge data from various sources (BadgeableInterface, arrays, strings) | ||
| * into a consistent format for rendering. | ||
| */ | ||
| final readonly class BadgeData |
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.
Probably a nit-pick but shoudln't it simply be called Badge?
| {% set badgeData = sylius_badge_data(data, options|default({})) %} | ||
|
|
||
| {% if badgeData %} | ||
| <span class="badge rounded-pill text-{{ badgeData.color }}" {{ sylius_test_html_attribute('badge', badgeData.value ?? badgeData.label) }}> |
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 the color should be on the badge itself (background instead of text), so for instance a colour like bg-purple-lt would be rendered via
| <span class="badge rounded-pill text-{{ badgeData.color }}" {{ sylius_test_html_attribute('badge', badgeData.value ?? badgeData.label) }}> | |
| <span class="badge rounded-pill bg-{{ badgeData.color }}" {{ sylius_test_html_attribute('badge', badgeData.value ?? badgeData.label) }}> |

Description
This PR adds a new badge field component for Sylius Grid that supports:
getLabel(),getColor(), andgetIcon()methodsoptions.vars.colors,labels, andiconsrounded-pillUsage Example
With PHP Enum
Files added
templates/shared/grid/field/badge.html.twigtemplates/shared/helper/field/badge.html.twig