@@ -13,18 +13,22 @@ class Heroicon extends Tags
13
13
{
14
14
protected static $ handle = 'heroicon ' ;
15
15
16
- private function renderBladeToHtml (string $ variant , string $ icon , Collection $ attrs ): string
16
+ private function renderBladeToHtml (string $ variant , string $ icon , Collection $ attrs ): string | null
17
17
{
18
18
$ attrsString = $ attrs ->map (function ($ value , $ key ) {
19
19
$ parsedValue = gettype ($ value ) === 'string ' ? $ value : var_export ($ value , true );
20
20
21
21
return $ key .'= ' .'" ' .$ parsedValue .'" ' ;
22
22
})->join (' ' );
23
23
24
- return Blade::render ('<x-heroicon- ' .$ variant [0 ].'- ' .$ icon .' ' .$ attrsString .' /> ' );
24
+ try {
25
+ return Blade::render ('<x-heroicon- ' .$ variant [0 ].'- ' .$ icon .' ' .$ attrsString .' /> ' );
26
+ } catch (\Throwable $ e ) {
27
+ return null ;
28
+ }
25
29
}
26
30
27
- private function render (string $ variant = null , string |null $ icon = null ): string
31
+ private function render (string $ variant = null , string |null $ icon = null ): string | null
28
32
{
29
33
$ variant = $ variant ?? Str::lower ($ this ->params ->get ('variant ' ));
30
34
$ icon = $ icon ?? Str::lower ($ this ->params ->get ('icon ' ));
@@ -37,39 +41,39 @@ private function render(string $variant = null, string|null $icon = null): strin
37
41
/**
38
42
* The {{ heroicon }} tag.
39
43
*/
40
- public function index (): string
44
+ public function index (): string | null
41
45
{
42
46
return $ this ->render ();
43
47
}
44
48
45
49
/**
46
50
* The {{ heroicon:mini }} tag.
47
51
*/
48
- public function mini (): string
52
+ public function mini (): string | null
49
53
{
50
54
return $ this ->render ('mini ' );
51
55
}
52
56
53
57
/**
54
58
* The {{ heroicon:outline }} tag.
55
59
*/
56
- public function outline (): string
60
+ public function outline (): string | null
57
61
{
58
62
return $ this ->render ('outline ' );
59
63
}
60
64
61
65
/**
62
66
* The {{ heroicon:solid }} tag.
63
67
*/
64
- public function solid (): string
68
+ public function solid (): string | null
65
69
{
66
70
return $ this ->render ('solid ' );
67
71
}
68
72
69
73
/**
70
74
* The {{ heroicon:{variant}:{icon} }} tag.
71
75
*/
72
- public function wildcard (string $ tag ): string
76
+ public function wildcard (string $ tag ): string | null
73
77
{
74
78
[$ variant , $ icon ] = Str::of ($ tag )->split ('/:/ ' )->toArray ();
75
79
$ icon = Str::kebab ($ icon );
0 commit comments