@php $requestedElement = $attributes->get('element', 'a'); $href = $attributes->get('href'); $isLink = $requestedElement === 'a' && !empty($href); $element = $isLink ? 'a' : 'button'; $disabled = filter_var($attributes->get('disabled', false), FILTER_VALIDATE_BOOL); $defaultClasses = 'px-8 py-2.5 inline-flex active:bg-black active:text-white !no-underline shadow-md'; $focusClasses = 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2'; $stateClasses = $disabled ? 'opacity-50 cursor-not-allowed pointer-events-none' : 'cursor-pointer active:bg-black active:text-white' ; $variants = [ 'primary' => 'text-carbon font-normal! bg-beige rounded-full hover:bg-neutral transition-colors duration-300', 'secondary' => 'text-pearl bg-carbon font-normal! rounded-full hover:bg-black transition-colors duration-300', 'outline' => 'bg-transparent text-pearl font-normal! border-2 border-pearl rounded-full hover:bg-pearl hover:text-carbon transition-colors duration-300', 'inverse' => 'bg-transparent text-carbon font-normal! border-2 border-carbon rounded-full hover:bg-carbon hover:text-pearl transition-colors duration-300', ]; $sizes = [ '2xs' => 'text-2xs', 'xs' => 'text-xs', 'sm' => 'text-sm', 'md' => 'text-md', 'base' => 'text-base', 'lg' => 'text-lg', 'xl' => 'text-xl', ]; $target = $attributes->get('target'); $rel = $attributes->get('rel'); if ($isLink && $target === '_blank' && empty($rel)) { $rel = 'noopener noreferrer'; } @endphp <{{ $element }} @class([ $defaultClasses, $focusClasses, $stateClasses, $variants[$attributes->get('variant', 'primary')] ?? $variants['primary'], $sizes[$attributes->get('size', 'base')] ?? $sizes['base'], $attributes->get('class'), ]) {{-- button: evita submit involontari --}} @if($element === 'button') type="{{ $attributes->get('type', 'button') }}" @if($disabled) disabled @endif @endif @if($element === 'a') href="{{ $href }}" @if($disabled) aria-disabled="true" tabindex="-1" @endif @if(!empty($target)) target="{{ $target }}" @endif @if(!empty($rel)) rel="{{ $rel }}" @endif @endif @foreach ($attributes->except(['class','variant','size','element','href','type','disabled','target','rel']) as $key => $value) {{ $key }}="{{ $value }}" @endforeach > {{ $slot }}