Skip to content

Commit 0b6115d

Browse files
committed
fix: handle both dynamic and static icon names
1 parent b3631cf commit 0b6115d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Tempest/View/src/Components/Icon.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,19 @@ public function compile(ViewComponentElement $element): string
3636
$class = $element->getAttribute('class');
3737

3838
return sprintf(
39-
'<?= \Tempest\get(%s::class)->render(%s, \'%s\') ?>',
39+
'<?= \Tempest\get(%s::class)->render(%s, \'%s\' ?: null) ?>',
4040
self::class,
41-
// Having to replace `<?=` is a bit of a hack and should be improved
42-
str_replace(['<?=', '?>'], '', $name),
41+
str_starts_with($name, '<?=')
42+
? str_replace(['<?=', '?>'], '', $name)
43+
: "\"{$name}\"",
4344
$class,
4445
);
4546
}
4647

4748
/**
48-
* Renders an icon
49-
*
50-
* This method is responsible for rendering the icon. If the icon is not
51-
* in the cache, it will download it on the fly and cache it for future
52-
* use. If the icon is already in the cache, it will be served from there.
49+
* Renders the specified icon. If the icon is not in the cache,
50+
* it will be downloaded it on the fly and cached for future use.
51+
* If the icon is already in the cache, it will be served from there.
5352
*/
5453
public function render(string $name, ?string $class): ?string
5554
{

0 commit comments

Comments
 (0)