gps_system/resources/views/flux/button-or-link.blade.php
sackey 6b878bb0a0
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
Initial commit
2025-09-12 16:19:56 +00:00

51 lines
1.4 KiB
PHP

@php
extract(Flux::forwardedAttributes($attributes, [
'type',
'current',
'href',
'as',
]));
@endphp
@props([
'type' => 'button',
'current' => null,
'href' => null,
'as' => null,
])
@php
$hrefForCurrentDetection = str($href)->startsWith(trim(config('app.url')))
? (string) str($href)->after(trim(config('app.url'), '/'))
: $href;
if ($hrefForCurrentDetection === '') $hrefForCurrentDetection = '/';
$requestIs = function ($pattern) {
// Support current route detection during Livewire update requests as well...
return app('livewire')?->isLivewireRequest()
? str()->is($pattern, app('livewire')->originalPath())
: request()->is($pattern);
};
$current = $current === null ? ($hrefForCurrentDetection
? $requestIs($hrefForCurrentDetection === '/' ? '/' : trim($hrefForCurrentDetection, '/'))
: false) : $current;
@endphp
<?php if ($as === 'div' && ! $href): ?>
<div {{ $attributes }}>
{{ $slot }}
</div>
<?php elseif ($as === 'a' || $href): ?>
{{-- We are using e() here to escape the href attribute value instead of "{{ }}" because the latter will escape the entire attribute value, including the "&" character... --}}
<a href="{!! e($href) !!}" {{ $attributes->merge(['data-current' => $current]) }}>
{{ $slot }}
</a>
<?php else: ?>
<button {{ $attributes->merge(['type' => $type, 'data-current' => $current]) }}>
{{ $slot }}
</button>
<?php endif; ?>