lukas-frey / filament-icon-picker

An icon picker field for Filament
MIT License
101 stars 20 forks source link

showing icon only when it has value and ... #23

Open tiagofrancafernandes opened 6 months ago

tiagofrancafernandes commented 6 months ago

On branch fix/check-state-before-load-icon modified: resources/views/tables/icon-column.blade.php modified: src/Tables/IconColumn.php

tiagofrancafernandes commented 6 months ago

Allow

\Guava\FilamentIconPicker\Tables\IconColumn::make('icon')

    // Hide programmatically
    ->hideIcon(fn(?Model $record) => !$record?->icon)

    // Set manually an icon
    ->useIcon('feathericon-tag') // string
    ->useIcon(fn(?Model $record) => $record?->icon) // Closure
    ->useIcon(fn(?Model $record) => $record?->icon ?? 'feathericon-tag') // With alter/default value

  // Note: In the future, maybe create a default icon method if it has no value in the 'state'
tiagofrancafernandes commented 6 months ago

In blade:

+@if (!$toHideIcon())
 <div class="filament-icon-picker-icon-column px-4 py-3">
-       <x-icon class="h-6" name="{{$getState()}}" />
+    <x-icon class="h-6" name="{{$getIcon()}}" />
 </div>
+@endif