-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathx-icon.view.php
More file actions
63 lines (58 loc) · 1.7 KB
/
x-icon.view.php
File metadata and controls
63 lines (58 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* SEE: docs/1-essentials/02-views.md for usage instructions
* @var string|null $name
* @var string|null $class
* @var string|null $style
* @var string|null $width
* @var string|null $height
*/
use Tempest\Core\Environment;
use Tempest\Icon\Icon;
use Tempest\Support\Str\ImmutableString;
use function Tempest\Container\get;
use function Tempest\Support\str;
$name ??= null;
$environment = get(Environment::class);
$svg = str(is_string($name) ? get(Icon::class)->render($name) : null)
->when(
fn (ImmutableString $s): bool => $s->toString() === '' && $environment->isLocal(),
fn (ImmutableString $s): ImmutableString => str("<!-- unknown-icon: {$name} -->"),
)
->replace(
search: " width=\"1em\" height=\"1em\"",
replace: '',
)
->when(
$style ?? null,
fn (ImmutableString $s): ImmutableString => $s->replace(
search: '<svg',
replace: "<svg style=\"{$style}\"",
),
)
->when(
$class ?? null,
fn (ImmutableString $s): ImmutableString => $s->replace(
search: '<svg',
replace: "<svg class=\"{$class}\"",
),
)
->when(
isset($width, $height),
fn (ImmutableString $s): ImmutableString => $s
->replace(
search: '<svg',
replace: "<svg width=\"{$width}\" height=\"{$height}\"",
),
)
->when(
! isset($width, $height) && ! isset($style) && ! isset($class),
fn (ImmutableString $s): ImmutableString => $s
->replace(
search: '<svg',
replace: "<svg width=\"1em\" height=\"1em\"",
),
)
->toString();
?>
{!! $svg !!}