Skip to content

Commit

Permalink
Merge pull request #8 from Log1x/enhance/empty-state
Browse files Browse the repository at this point in the history
💄 Add empty state for menu panels
  • Loading branch information
datlechin authored Aug 9, 2024
2 parents 58d3110 + 6ce5e7d commit 0704855
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions resources/lang/en/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@
'title' => 'Link created',
],
],
'panel' => [
'empty' => [
'heading' => 'No items found',
'description' => 'There are no items in this menu.',
],
],
];
6 changes: 6 additions & 0 deletions resources/lang/vi/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@
'title' => 'Liên kết đã được tạo',
],
],
'panel' => [
'empty' => [
'heading' => 'Không tìm thấy mục nào',
'description' => 'Không có mục nào trong menu này.',
],
],
];
11 changes: 11 additions & 0 deletions resources/views/components/empty-state.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@props([
'heading' => __('filament-menu-builder::menu-builder.panel.empty.heading'),
'description' => __('filament-menu-builder::menu-builder.panel.empty.description'),
'icon' => 'heroicon-o-link-slash',
])

<x-filament-tables::empty-state
:heading="$heading"
:description="$description"
:icon="$icon"
/>
12 changes: 7 additions & 5 deletions resources/views/livewire/panel.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
>
{{ $this->form }}

<x-slot:footerActions>
<x-filament::button type="submit">
{{ __('filament-menu-builder::menu-builder.actions.add.label') }}
</x-filament::button>
</x-slot:footerActions>
@if ($this->items)
<x-slot:footerActions>
<x-filament::button type="submit">
{{ __('filament-menu-builder::menu-builder.actions.add.label') }}
</x-filament::button>
</x-slot:footerActions>
@endif
</x-filament::section>
</form>
4 changes: 1 addition & 3 deletions src/FilamentMenuBuilderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public function addLocation(string $key, string $label): static

public function addMenuPanel(MenuPanel $menuPanel): static
{
if ($menuPanel->getItems()) {
$this->menuPanels[] = $menuPanel;
}
$this->menuPanels[] = $menuPanel;

return $this;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Livewire/MenuPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Datlechin\FilamentMenuBuilder\Contracts\MenuPanel as ContractsMenuPanel;
use Datlechin\FilamentMenuBuilder\Models\Menu;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
Expand Down Expand Up @@ -75,13 +75,19 @@ public function add(): void

public function form(Form $form): Form
{
$items = collect($this->items)->mapWithKeys(fn ($item) => [$item['title'] => $item['title']]);

return $form
->schema([
CheckboxList::make('data')
Components\View::make('filament-menu-builder::components.empty-state')
->visible($items->isEmpty()),

Components\CheckboxList::make('data')
->hiddenLabel()
->required()
->bulkToggleable()
->options(collect($this->items)->mapWithKeys(fn ($item) => [$item['title'] => $item['title']])),
->visible($items->isNotEmpty())
->options($items),
]);
}

Expand Down

0 comments on commit 0704855

Please sign in to comment.