34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
|
|
@props([
|
||
|
|
'src', // Stoic filename string e.g. "hero.png"
|
||
|
|
'preset' => 'medium', // which preset sets the src + default sizes hint
|
||
|
|
'alt' => '',
|
||
|
|
'loading' => 'lazy',
|
||
|
|
'fetchpriority' => 'auto',
|
||
|
|
'sizes' => null, // override when you know the render context
|
||
|
|
'width' => null,
|
||
|
|
'height' => null,
|
||
|
|
])
|
||
|
|
|
||
|
|
@php
|
||
|
|
$srcset = \Modules\Core\Stoic\Stoic::srcset($src);
|
||
|
|
$presetW = collect(\Modules\Core\Stoic\Stoic::presets())->firstWhere('code', $preset)['width'] ?? 800;
|
||
|
|
$sizesAttr = $sizes ?? "(min-width: 1024px) {$presetW}px, 100vw";
|
||
|
|
[$width, $height] = $width !== null && $height !== null
|
||
|
|
? [$width, $height]
|
||
|
|
: \Modules\Core\Stoic\Stoic::dimensions($src, $preset);
|
||
|
|
@endphp
|
||
|
|
|
||
|
|
<img
|
||
|
|
src="{{ \Modules\Core\Stoic\Stoic::image($src, $preset) }}"
|
||
|
|
@if($srcset)
|
||
|
|
srcset="{{ $srcset }}"
|
||
|
|
sizes="{{ $sizesAttr }}"
|
||
|
|
@endif
|
||
|
|
@if($width !== null) width="{{ $width }}" @endif
|
||
|
|
@if($height !== null) height="{{ $height }}" @endif
|
||
|
|
alt="{{ $alt }}"
|
||
|
|
loading="{{ $loading }}"
|
||
|
|
fetchpriority="{{ $fetchpriority }}"
|
||
|
|
{{ $attributes }}
|
||
|
|
/>
|