WIP: added button component
improve disabled and hover states
This commit is contained in:
43
app/View/Components/Button.php
Normal file
43
app/View/Components/Button.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?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';
|
||||||
|
|
||||||
|
$variants = [
|
||||||
|
'primary' => 'bg-primary text-text-inverted hover:bg-blue-700',
|
||||||
|
'secondary' => 'bg-secondary text-text hover:bg-gray-300',
|
||||||
|
'outline' => 'border border-primary text-primary hover:bg-red-700',
|
||||||
|
];
|
||||||
|
|
||||||
|
$disabled = 'disabled:bg-gray-300 disabled:text-gray-500 disabled:cursor-not-allowed disabled:opacity-60';
|
||||||
|
|
||||||
|
return trim(
|
||||||
|
$base . ' ' .
|
||||||
|
($variants[$this->variant] ?? $variants['primary']) . ' ' .
|
||||||
|
$disabled
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the view / contents that represent the component.
|
||||||
|
*/
|
||||||
|
public function render(): View|Closure|string
|
||||||
|
{
|
||||||
|
return view('components.button');
|
||||||
|
}
|
||||||
|
}
|
||||||
8
resources/views/components/button.blade.php
Normal file
8
resources/views/components/button.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<button
|
||||||
|
{{ $attributes
|
||||||
|
->merge(['class' => $classes()])
|
||||||
|
->merge(['disabled' => $disabled])
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{{ $slot }}
|
||||||
|
</button>
|
||||||
@@ -27,33 +27,29 @@
|
|||||||
<h3 class="text-l font-semibold">Enabled</h3>
|
<h3 class="text-l font-semibold">Enabled</h3>
|
||||||
|
|
||||||
<div class="flex gap-4">
|
<div class="flex gap-4">
|
||||||
<button class="bg-primary text-text-inverted px-4 py-2 rounded">
|
<x-button>Default</x-button>
|
||||||
Primary
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="bg-secondary text-black px-4 py-2 rounded">
|
<x-button variant="primary">Primary</x-button>
|
||||||
Secondary
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="border border-primary text-primary px-4 py-2 rounded">
|
|
||||||
Outline
|
<x-button variant="secondary">Secondary</x-button>
|
||||||
</button>
|
|
||||||
|
|
||||||
|
<x-button variant="outline">Outline</x-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 class="text-l font-semibold">Disabled</h3>
|
<h3 class="text-l font-semibold">Disabled</h3>
|
||||||
|
|
||||||
<div class="flex gap-4">
|
<div class="flex gap-4">
|
||||||
<button class="bg-primary text-text-inverted px-4 py-2 rounded" disabled>
|
<x-button disabled>Default</x-button>
|
||||||
Primary
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="bg-secondary text-black px-4 py-2 rounded" disabled>
|
<x-button variant="primary" disabled>Primary</x-button>
|
||||||
Secondary
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="border border-primary text-primary px-4 py-2 rounded" disabled>
|
|
||||||
Outline
|
<x-button variant="secondary" disabled>Secondary</x-button>
|
||||||
</button>
|
|
||||||
|
|
||||||
|
<x-button variant="outline" disabled>Outline</x-button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user