diff --git a/README.md b/README.md index 56339fd..ccc45c7 100644 --- a/README.md +++ b/README.md @@ -99,12 +99,44 @@ $panel Menu panels are the panels that contain the menu items which you can add to the menus. -#### Custom Menu Panel +#### Custom Link Menu Panel By default, the package provides a **Custom Link** menu panel that allows you to add custom links to the menus. ![Custom Link Menu Panel](https://github.com/datlechin/filament-menu-builder/raw/main/art/custom-link.png) +The panel can be disabled by using the following when configuring the plugin, should you not need this functionality. + +```php +use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin; + +$panel + ... + ->plugin( + FilamentMenuBuilderPlugin::make() + ->showCustomLinkPanel(false) + ) +``` + +#### Custom Text Menu Panel + +This package provides a **Custom Text** menu panel that allows you to add custom text items to the menus. + +It is identical to the **Custom Link** menu panel except for the fact that you only set a title without a URL or target. This can be useful to add headers to mega-style menus. + +The panel is disabled by default to prevent visual clutter. To enable the Custom Text menu panel, you can use the following when configuring the plugin. + +```php +use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin; + +$panel + ... + ->plugin( + FilamentMenuBuilderPlugin::make() + ->showCustomTextPanel() + ) +``` + #### Static Menu Panel The static menu panel allows you to add menu items manually. diff --git a/resources/lang/en/menu-builder.php b/resources/lang/en/menu-builder.php index 308c983..c189402 100644 --- a/resources/lang/en/menu-builder.php +++ b/resources/lang/en/menu-builder.php @@ -55,6 +55,7 @@ ], ], 'custom_link' => 'Custom Link', + 'custom_text' => 'Custom Text', 'open_in' => [ 'label' => 'Open in', 'options' => [ diff --git a/resources/lang/fr/menu-builder.php b/resources/lang/fr/menu-builder.php index b8d251d..579c4c2 100644 --- a/resources/lang/fr/menu-builder.php +++ b/resources/lang/fr/menu-builder.php @@ -55,6 +55,7 @@ ], ], 'custom_link' => 'Lien personnalisé', + 'custom_text' => 'Custom Text', 'open_in' => [ 'label' => 'Ouvrir dans', 'options' => [ diff --git a/resources/lang/nl/menu-builder.php b/resources/lang/nl/menu-builder.php index c9df6ea..7e9f4a7 100644 --- a/resources/lang/nl/menu-builder.php +++ b/resources/lang/nl/menu-builder.php @@ -55,6 +55,7 @@ ], ], 'custom_link' => 'Aangepaste link', + 'custom_text' => 'Aangepaste tekst', 'open_in' => [ 'label' => 'Openen op', 'options' => [ diff --git a/resources/lang/vi/menu-builder.php b/resources/lang/vi/menu-builder.php index 4e29746..9ee9d84 100644 --- a/resources/lang/vi/menu-builder.php +++ b/resources/lang/vi/menu-builder.php @@ -55,6 +55,7 @@ ], ], 'custom_link' => 'Liên kết Tùy chỉnh', + 'custom_text' => 'Custom Text', 'open_in' => [ 'label' => 'Mở trong', 'options' => [ diff --git a/resources/views/edit-record.blade.php b/resources/views/edit-record.blade.php index e23c200..8843587 100644 --- a/resources/views/edit-record.blade.php +++ b/resources/views/edit-record.blade.php @@ -39,9 +39,13 @@ @endforeach - @if (\Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin::get()->isShowCustomLink()) + @if (\Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin::get()->isShowCustomLinkPanel()) @endif + + @if (\Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin::get()->isShowCustomTextPanel()) + + @endif
diff --git a/resources/views/livewire/create-custom-text.blade.php b/resources/views/livewire/create-custom-text.blade.php new file mode 100644 index 0000000..57b7772 --- /dev/null +++ b/resources/views/livewire/create-custom-text.blade.php @@ -0,0 +1,16 @@ +
+ + {{ $this->form }} + + + + {{ __('filament-menu-builder::menu-builder.actions.add.label') }} + + + +
diff --git a/src/FilamentMenuBuilderPlugin.php b/src/FilamentMenuBuilderPlugin.php index 29e2558..212241d 100644 --- a/src/FilamentMenuBuilderPlugin.php +++ b/src/FilamentMenuBuilderPlugin.php @@ -33,7 +33,9 @@ class FilamentMenuBuilderPlugin implements Plugin */ protected array $menuPanels = []; - protected bool $showCustomLink = true; + protected bool $showCustomLinkPanel = true; + + protected bool $showCustomTextPanel = false; public function getId(): string { @@ -126,9 +128,16 @@ public function addMenuPanels(array $menuPanels): static return $this; } - public function showCustomLink(bool $show = true): static + public function showCustomLinkPanel(bool $show = true): static { - $this->showCustomLink = $show; + $this->showCustomLinkPanel = $show; + + return $this; + } + + public function showCustomTextPanel(bool $show = true): static + { + $this->showCustomTextPanel = $show; return $this; } @@ -177,9 +186,14 @@ public function getMenuPanels(): array ->all(); } - public function isShowCustomLink(): bool + public function isShowCustomLinkPanel(): bool + { + return $this->showCustomLinkPanel; + } + + public function isShowCustomTextPanel(): bool { - return $this->showCustomLink; + return $this->showCustomTextPanel; } public function getLocations(): array diff --git a/src/FilamentMenuBuilderServiceProvider.php b/src/FilamentMenuBuilderServiceProvider.php index 711fd79..9c8bd9d 100644 --- a/src/FilamentMenuBuilderServiceProvider.php +++ b/src/FilamentMenuBuilderServiceProvider.php @@ -5,6 +5,7 @@ namespace Datlechin\FilamentMenuBuilder; use Datlechin\FilamentMenuBuilder\Livewire\CreateCustomLink; +use Datlechin\FilamentMenuBuilder\Livewire\CreateCustomText; use Datlechin\FilamentMenuBuilder\Livewire\MenuItems; use Datlechin\FilamentMenuBuilder\Livewire\MenuPanel; use Filament\Support\Assets\AlpineComponent; @@ -63,6 +64,7 @@ public function packageBooted(): void Livewire::component('menu-builder-items', MenuItems::class); Livewire::component('menu-builder-panel', MenuPanel::class); Livewire::component('create-custom-link', CreateCustomLink::class); + Livewire::component('create-custom-text', CreateCustomText::class); } protected function getAssetPackageName(): ?string diff --git a/src/Livewire/CreateCustomText.php b/src/Livewire/CreateCustomText.php new file mode 100644 index 0000000..0bd9fee --- /dev/null +++ b/src/Livewire/CreateCustomText.php @@ -0,0 +1,60 @@ +validate([ + 'title' => ['required', 'string'], + ]); + + $this->menu + ->menuItems() + ->create([ + 'title' => $this->title, + 'order' => $this->menu->menuItems->max('order') + 1, + ]); + + Notification::make() + ->title(__('filament-menu-builder::menu-builder.notifications.created.title')) + ->success() + ->send(); + + $this->reset('title'); + $this->dispatch('menu:created'); + } + + public function form(Form $form): Form + { + return $form + ->schema([ + TextInput::make('title') + ->label(__('filament-menu-builder::menu-builder.form.title')) + ->required(), + ]); + } + + public function render(): View + { + return view('filament-menu-builder::livewire.create-custom-text'); + } +} diff --git a/src/Models/MenuItem.php b/src/Models/MenuItem.php index 0d0a27a..d4e5b6d 100644 --- a/src/Models/MenuItem.php +++ b/src/Models/MenuItem.php @@ -91,6 +91,7 @@ protected function type(): Attribute return Attribute::get(function () { return match (true) { $this->linkable instanceof MenuPanelable => $this->linkable->getMenuPanelName(), + is_null($this->linkable) && is_null($this->url) => __('filament-menu-builder::menu-builder.custom_text'), default => __('filament-menu-builder::menu-builder.custom_link'), }; });