SmartCane/laravel_app/app/Livewire/Components/Badge.php
2024-05-28 16:59:35 +02:00

34 lines
899 B
PHP

<?php
namespace App\Livewire\Components;
use App\Enums\Status;
use Livewire\Component;
class Badge extends Component
{
public array $colorClasses;
public $status;
public $type;
public int $id;
public $listeners = [
'Badge:refresh' => '$refresh',
];
public function mount(string $status = null, $id = 0,$type = null)
{
$this->type = $type;
$this->id ??= $id ;
$this->status = Status::tryFrom($status) ?? Status::Success;
$this->colorClasses = match($this->status) {
Status::Success => ['bg' => 'bg-green-100', 'text' => 'text-green-700'],
Status::Failed => ['bg' => 'bg-red-100', 'text' => 'text-red-700'],
Status::Pending => ['bg' => 'bg-gray-100', 'text' => 'text-gray-600'],
};
}
public function render()
{
return view('livewire.components.badge');
}
}