SmartCane/laravel_app/resources/views/components/badge.blade.php

32 lines
1 KiB
PHP

@props([
'status' => \App\Enums\Status::Success,
])
<?php
// Define a mapping of status to its corresponding colors
$statusToColors = [
'success' => ['bg' => 'bg-green-100', 'text' => 'text-green-700'],
'error' => ['bg' => 'bg-red-100', 'text' => 'text-red-700'],
'warning' => ['bg' => 'bg-yellow-100', 'text' => 'text-yellow-800'],
'info' => ['bg' => 'bg-blue-100', 'text' => 'text-blue-700'],
'pending' => ['bg' => 'bg-gray-100', 'text' => 'text-gray-600'],
];
// If status is an object, try to convert it to a string
if (is_object($status)) {
$status = (string) $status;
}
// Default to 'success' if the provided status is not in the defined array
if (!array_key_exists($status, $statusToColors)) {
$status = \App\Enums\Status::Success;
}
// Get the color class for the given status
$colorClasses = $statusToColors[$status];
?>
<span {{ $attributes }} class="inline-flex items-center rounded-md {{ $colorClasses['bg'] }} px-1.5 py-0.5 text-xs font-medium {{ $colorClasses['text'] }}">
{{ $status }}
</span>