-
-
Notifications
You must be signed in to change notification settings - Fork 26
[ux-icon] Using ux_icon through tabler_icon
#247
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?
Changes from 11 commits
8db0f47
9ef120d
c43cd33
f24a80e
2489a2a
1764182
9dcf5f2
3ed108b
fe2d660
a0a687b
49f3358
fcb37ce
cabb802
ae7cd31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ vendor | |
| .php-cs-fixer.cache | ||
| .phpunit.result.cache | ||
| yarn.lock | ||
| composer.lock | ||
| composer.lock | ||
| docker-compose.yml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "name": "kevinpapst/tabler-bundle", | ||
| "type": "symfony-bundle", | ||
| "description": "Admin/Backend theme bundle for Symfony based on Tabler.io", | ||
| "description": "Theme bundle for Symfony based on Tabler.io", | ||
| "license": "MIT", | ||
| "authors": [ | ||
| { | ||
|
|
@@ -21,7 +21,8 @@ | |
| "symfony/security-core": "^6.0 || ^7.0 || ^8.0", | ||
| "symfony/translation": "^6.0 || ^7.0 || ^8.0", | ||
| "symfony/twig-bridge": "^6.0 || ^7.0 || ^8.0", | ||
| "twig/twig": "^3.0" | ||
| "twig/twig": "^3.0", | ||
| "symfony/ux-icons": "^2.0" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was doing that at the beginning, but since we allow icon alias references from That said, my idea would be to allow developers to pass an
TBH, I was thinking the same approach could apply to every component that accepts an icon alias. We should only accept an HTML string (still BC-compatible if an alias is provided) and simply render For your example with that f***ing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make it required now, and |
||
| }, | ||
| "require-dev": { | ||
| "symfony/framework-bundle" : "^6.0 || ^7.0 || ^8.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Tabler bundle, created by Kevin Papst (www.kevinpapst.de). | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace KevinPapst\TablerBundle\Twig\Extension; | ||
|
|
||
| use KevinPapst\TablerBundle\Twig\Runtime\IconRuntime; | ||
| use Twig\DeprecatedCallableInfo; | ||
| use Twig\Extension\AbstractExtension; | ||
| use Twig\TwigFilter; | ||
| use Twig\TwigFunction; | ||
|
|
||
| class IconExtension extends AbstractExtension | ||
| { | ||
| public function getFilters(): array | ||
| { | ||
| return [ | ||
| /* @phpstan-ignore-next-line */ | ||
| new TwigFilter('tabler_icon', [IconRuntime::class, 'htmlClassAttributeValue'], [ | ||
| 'deprecation_info' => new DeprecatedCallableInfo('kevinpapst/tabler-bundle', '3.0'), | ||
| ]), | ||
| ]; | ||
| } | ||
|
|
||
| public function getFunctions(): array | ||
| { | ||
| return [ | ||
| /* @phpstan-ignore-next-line */ | ||
| new TwigFunction('tabler_icon', [IconRuntime::class, 'renderIcon'], [ | ||
| 'is_safe' => ['html'], | ||
| 'deprecation_info' => new DeprecatedCallableInfo('kevinpapst/tabler-bundle', '3.0'), | ||
| ]), | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Tabler bundle, created by Kevin Papst (www.kevinpapst.de). | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace KevinPapst\TablerBundle\Twig\Runtime; | ||
|
|
||
| use Symfony\UX\Icons\IconRendererInterface; | ||
| use Twig\Extension\RuntimeExtensionInterface; | ||
|
|
||
| /** | ||
| * @deprecated Use Symfony UX instead | ||
| */ | ||
| class IconRuntime implements RuntimeExtensionInterface | ||
| { | ||
| /** | ||
| * @param array<string, string> $icons | ||
| */ | ||
| public function __construct( | ||
| private readonly IconRendererInterface $iconRenderer, | ||
| private readonly array $icons, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Use Symfony UX instead | ||
| */ | ||
| public function renderIcon(string $name, bool $withIconClass = false, ?string $default = null): string | ||
| { | ||
| $safeName = str_replace('-', '_', $name); | ||
kevinpapst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (isset($this->icons[$safeName])) { | ||
| // Tabler icon shortcut | ||
| $fontawesomeFullName = $this->icons[$safeName]; | ||
| } elseif (str_contains($name, ' ')) { | ||
| // Fontawesome with space | ||
| $fontawesomeFullName = $name; | ||
| } elseif (str_contains($name, ':')) { | ||
| // Ux icon | ||
| return $this->iconRenderer->renderIcon($name, [ | ||
| 'class' => $withIconClass ? 'icon' : '', | ||
| ]); | ||
| } else { | ||
| return $this->htmlClassAttributeValue($name, $withIconClass, $default); | ||
| } | ||
|
|
||
| [$typeNameAbbreviation, $iconFullName] = explode(' ', $fontawesomeFullName); | ||
| $iconName = preg_replace('/^fa-/', '', $iconFullName); | ||
| $sets = match ($typeNameAbbreviation) { | ||
| 'far' => 'fa-regular', | ||
| 'fab' => 'fa-brands', | ||
| default => 'fa-solid', | ||
| }; | ||
|
|
||
| return $this->iconRenderer->renderIcon("$sets:$iconName", [ | ||
| 'class' => $withIconClass ? 'icon' : '', | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Use Symfony UX instead | ||
| */ | ||
| public function htmlClassAttributeValue(string $name, bool $withIconClass = false, ?string $default = null): string | ||
| { | ||
| return ($withIconClass ? 'icon ' : '') . ($this->icons[str_replace('-', '_', $name)] ?? ($default ?? $name)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,12 +75,12 @@ | |
|
|
||
| {% macro item_icon(item) %} | ||
| {% if item.icon %} | ||
| <span class="nav-link-icon d-md-none d-lg-inline-block text-center">{{ tabler_icon(item.icon, false, item.icon) }}</span> | ||
| <span class="nav-link-icon d-md-none d-lg-inline-block text-center">{{ tabler_icon(item.icon, true, item.icon) }}</span> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| {% endif %} | ||
| {% endmacro %} | ||
|
|
||
| {% macro item_badge(item) %} | ||
| {% if item.badge is not null or item.badgeColor is not null %} | ||
| <span class="badge badge-sm bg-{{ item.badgeColor|default('blue') }} text-{{ item.badgeColor|default('blue') }}-fg text-uppercase ms-2">{{ item.badge }}</span> | ||
| {% endif %} | ||
| {% endmacro %} | ||
| {% endmacro %} | ||



Uh oh!
There was an error while loading. Please reload this page.