91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
{{--
|
|
Button Component - shadcn-inspired
|
|
|
|
Usage:
|
|
<x-proxmox::ui.button>Click me</x-proxmox::ui.button>
|
|
<x-proxmox::ui.button variant="primary" icon="ri-add-line">Add Server</x-proxmox::ui.button>
|
|
<x-proxmox::ui.button variant="danger" size="sm">Delete</x-proxmox::ui.button>
|
|
<x-proxmox::ui.button :loading="true">Processing</x-proxmox::ui.button>
|
|
--}}
|
|
|
|
@props([
|
|
'variant' => 'secondary',
|
|
'size' => 'md',
|
|
'icon' => null,
|
|
'iconRight' => null,
|
|
'loading' => false,
|
|
'loadingText' => null,
|
|
'disabled' => false,
|
|
'href' => null,
|
|
'type' => 'button',
|
|
'full' => false,
|
|
])
|
|
|
|
@php
|
|
$tag = $href ? 'a' : 'button';
|
|
|
|
$baseClasses = 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50';
|
|
|
|
$variantClasses = [
|
|
'primary' => 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
|
|
'secondary' => 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
|
|
'outline' => 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',
|
|
'ghost' => 'hover:bg-accent hover:text-accent-foreground',
|
|
'danger' => 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',
|
|
'success' => 'bg-success text-white shadow-sm hover:bg-success/90',
|
|
'warning' => 'bg-warning text-white shadow-sm hover:bg-warning/90',
|
|
'info' => 'bg-info text-white shadow-sm hover:bg-info/90',
|
|
'link' => 'text-primary underline-offset-4 hover:underline',
|
|
];
|
|
|
|
$sizeClasses = [
|
|
'xs' => 'h-7 px-2 text-xs',
|
|
'sm' => 'h-8 px-3 text-xs',
|
|
'md' => 'h-9 px-4 py-2',
|
|
'lg' => 'h-10 px-8',
|
|
'xl' => 'h-11 px-10 text-base',
|
|
'icon' => 'h-9 w-9',
|
|
];
|
|
|
|
$iconSizes = [
|
|
'xs' => 'size-3',
|
|
'sm' => 'size-3.5',
|
|
'md' => 'size-4',
|
|
'lg' => 'size-4',
|
|
'xl' => 'size-5',
|
|
'icon' => 'size-4',
|
|
];
|
|
|
|
$classes = collect([
|
|
$baseClasses,
|
|
$variantClasses[$variant] ?? $variantClasses['secondary'],
|
|
$sizeClasses[$size] ?? $sizeClasses['md'],
|
|
$full ? 'w-full' : '',
|
|
])->filter()->join(' ');
|
|
|
|
$iconSize = $iconSizes[$size] ?? $iconSizes['md'];
|
|
@endphp
|
|
|
|
<{{ $tag }}
|
|
@if($href) href="{{ $href }}" @endif
|
|
@if($tag === 'button') type="{{ $type }}" @endif
|
|
@if($disabled || $loading) disabled @endif
|
|
{{ $attributes->class([$classes]) }}
|
|
>
|
|
@if($loading)
|
|
<svg class="animate-spin {{ $iconSize }}" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
</svg>
|
|
<span>{{ $loadingText ?? $slot }}</span>
|
|
@else
|
|
@if($icon)
|
|
<x-dynamic-component :component="$icon" class="{{ $iconSize }}" />
|
|
@endif
|
|
{{ $slot }}
|
|
@if($iconRight)
|
|
<x-dynamic-component :component="$iconRight" class="{{ $iconSize }}" />
|
|
@endif
|
|
@endif
|
|
</{{ $tag }}>
|