Skip to content

Commit

Permalink
Merge pull request #15 from Log1x/enhance/improve-menu-location
Browse files Browse the repository at this point in the history
💄 Improve menu location form styling
  • Loading branch information
datlechin authored Aug 17, 2024
2 parents dee1785 + 5b2f889 commit cd21926
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions resources/lang/en/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
'label' => 'Locations',
'description' => 'Choose where to display the menu.',
'empty' => 'Unassigned',
'actions' => [
'select_all' => 'Select all',
'deselect_all' => 'Deselect all',
],
],
'is_visible' => [
'label' => 'Visible',
Expand Down
4 changes: 4 additions & 0 deletions resources/lang/vi/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
'label' => 'Vị trí',
'description' => 'Chọn vị trí hiển thị menu.',
'empty' => 'Chưa gán',
'actions' => [
'select_all' => 'Chọn tất cả',
'deselect_all' => 'Bỏ chọn tất cả',
],
],
'is_visible' => [
'label' => 'Hiển thị',
Expand Down
19 changes: 16 additions & 3 deletions src/Resources/MenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Datlechin\FilamentMenuBuilder\Models\Menu;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Resources\Resource;
use Filament\Tables;
Expand All @@ -33,12 +35,23 @@ public static function form(Form $form): Form
TextInput::make('name')
->label(__('filament-menu-builder::menu-builder.resource.name.label'))
->required(),
CheckboxList::make('locations')
->bulkToggleable()
ToggleButtons::make('locations')
->multiple()
->inline()
->reactive()
->visible(fn (string $context) => $context === 'edit' && $locations)
->label(__('filament-menu-builder::menu-builder.resource.locations.label'))
->afterStateHydrated(fn (Menu $menu, Set $set) => $set('locations', $menu->locations->pluck('location')))
->helperText(__('filament-menu-builder::menu-builder.resource.locations.description'))
->hintActions([
Action::make(__('filament-menu-builder::menu-builder.resource.locations.actions.select_all'))
->action(fn (Set $set) => $set('locations', array_keys($locations)))
->visible(fn (Get $get) => count($get('locations')) !== count($locations)),

Action::make(__('filament-menu-builder::menu-builder.resource.locations.actions.deselect_all'))
->action(fn (Set $set) => $set('locations', []))
->visible(fn (Get $get) => count($get('locations')) === count($locations)),
])
->options($locations),
Toggle::make('is_visible')
->label(__('filament-menu-builder::menu-builder.resource.is_visible.label'))
Expand Down

0 comments on commit cd21926

Please sign in to comment.