Skip to content

Instantly share code, notes, and snippets.

@LucasHayashi
Created July 9, 2024 14:24
Show Gist options
  • Save LucasHayashi/a637e365ede3fe610765206e1df048f4 to your computer and use it in GitHub Desktop.
Save LucasHayashi/a637e365ede3fe610765206e1df048f4 to your computer and use it in GitHub Desktop.
Componente de badge para o Laravel e Tailwind v3.4.4
@props([
'type',
'text'
])
@php
$type = [
'success' => 'bg-green-50 text-green-700 ring-green-600/20',
'danger' => 'bg-red-50 text-red-700 ring-red-600/10',
'warning' => 'bg-yellow-50 text-yellow-800 ring-yellow-600/20',
'info' => 'bg-blue-50 text-blue-700 ring-blue-700/10',
'normal' => 'bg-gray-50 text-gray-600 ring-gray-500/10'
][$type];
@endphp
<span class="inline-flex items-center rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset {{ $type }}">
{{ $text }}
</span>
@LucasHayashi
Copy link
Author

Exemplo de como utilizar:

// ...
$text = 'foo';
$type = $value ? 'success' : 'danger';
return view('components.badge', compact('type', 'text'));

Exemplo com Laravel Livewire Tables v3:

Column::make('Destaque', 'highlight')
    ->format(function ($value, $row, Column $column) {
        $text = $value ? 'Sim' : 'Não';
        $type = $value ? 'success' : 'danger';
        return view('components.badge', compact('type', 'text'));
    })->sortable(),

@LucasHayashi
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment