adrema/app/View/Ui/Sprite.php

29 lines
735 B
PHP
Raw Normal View History

2024-09-23 23:49:17 +02:00
<?php
2024-10-13 21:00:47 +02:00
namespace App\View\Ui;
2024-09-23 23:49:17 +02:00
2024-10-26 15:55:22 +02:00
use Illuminate\Support\Facades\Cache;
2024-09-23 23:49:17 +02:00
use Illuminate\View\Component;
class Sprite extends Component
{
2024-10-26 15:55:22 +02:00
public string $spritemapFile;
2024-09-23 23:49:17 +02:00
public function __construct(
public string $src = '',
) {
2024-10-26 15:55:22 +02:00
$this->spritemapFile = Cache::rememberForever('spritemap_file', function () {
$manifest = json_decode(file_get_contents(public_path('build/manifest.json')), true);
return asset('build/' . $manifest['spritemap.svg']['file']);
});
2024-09-23 23:49:17 +02:00
}
public function render()
{
return <<<'HTML'
2024-10-26 15:55:22 +02:00
<svg {{ $attributes->merge(['class' => 'fill-current']) }}><use xlink:href="{{$spritemapFile}}#sprite-{{$src}}" /></svg>
2024-09-23 23:49:17 +02:00
HTML;
}
}