Files
kazi/app/View/Components/Button.php
Pedro Cabral 9e9f05abdf WIP: added button component
add tests
2026-04-27 23:30:33 +02:00

59 lines
1.6 KiB
PHP

<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Button extends Component
{
public function __construct(public string $variant = 'primary', public bool $disabled = false)
{
//
}
public function classes(): string
{
$base = 'inline-flex items-center justify-center px-4 py-2 rounded-md text-sm font-medium transition ' .
'duration-150 ease-in-out';
$classes = match ($this->variant) {
'secondary' => [
'base' => 'bg-secondary text-text',
'hover' => 'hover:bg-secondary-dark',
'disabled' => 'disabled:bg-secondary',
],
'outline' => [
'base' => 'bg-outline border border-primary text-primary',
'hover' => 'hover:bg-primary hover:text-text-inverted',
'disabled' => 'disabled:bg-outline disabled:text-primary',
],
default => [
'base' => 'bg-primary text-text-inverted',
'hover' => 'hover:bg-primary-dark',
'disabled' => 'disabled:bg-primary'
]
};
$baseDisabled = 'disabled:cursor-not-allowed disabled:opacity-60';
return trim(
$base . ' ' .
$classes['base'] . ' ' .
$classes['hover'] . ' ' .
$baseDisabled . ' ' .
$classes['disabled']
);
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.button');
}
}