Skip to content

Commit

Permalink
Update AnnouncementResource.php
Browse files Browse the repository at this point in the history
Used Toggle instead of Checkbox, and also moved elements into a Section for better visibility.
  • Loading branch information
Rizayev authored Feb 19, 2024
1 parent 4d44cc7 commit cc65dfb
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/Resources/AnnouncementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

use App\Models\User;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Support\Facades\FilamentColor;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Forms\Components\Checkbox;
use Guava\FilamentIconPicker\Forms\IconPicker;
use Guava\FilamentIconPicker\Tables\IconColumn;
use Rupadana\FilamentAnnounce\Models\Announcement;
Expand All @@ -30,33 +32,38 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn ($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn (Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),
Section::make()
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn(Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),

Select::make('users')
->options(User::pluck('name', 'id')->toArray())
->multiple()
->required(),
Select::make('users')
->options(User::pluck('name', 'id')->toArray())
->hidden(fn(Get $get) => $get('all') == true)
->multiple()
->required(),
])->columns(2),

Checkbox::make('all')
Toggle::make('all')
->live()
->label('All users')
->default(false),
]);
Expand Down

0 comments on commit cc65dfb

Please sign in to comment.