Add a context menu (right click menu) for resource pages, custom pages and table cells of Filament Admin Panel.
AymanAlhattami\FilamentContextMenu\Actions\RefreshAction
to refresh the page.AymanAlhattami\FilamentContextMenu\Actions\GoBackAction
to go back to the previous page.AymanAlhattami\FilamentContextMenu\Actions\GoForward
to go back to the forward page.Demo project | Youtube video | Laravel Daily (Povilas Korop) Video
You can install the package via Composer:
composer require aymanalhattami/filament-context-menu
AymanAlhattami\FilamentContextMenu\PageHasContextMenu
to the page you want to add the context menu.getContextMenuActions
method inside the page, the method should return an array of Filament Actions
use App\Filament\Resources\UserResource\Pages\CreateUser;use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Actions\Action;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â public function getContextMenuActions(): array { return [ Action::make('Create user') ->url(CreateUser::getUrl()) ]; }Â //}
You can use AymanAlhattami\FilamentContextMenu\ContextMenuDivider
to set divider between menu actions
use App\Filament\Resources\UserResource\Pages\CreateUser;use App\Filament\Resources\UserResource\Pages\TrashedUsers;use AymanAlhattami\FilamentContextMenu\ContextMenuDivider;use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Actions\Action;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ Action::make('Create user') ->url(CreateUser::getUrl()), ContextMenuDivider::make(), Action::make('Trashed user') ->url(TrashedUsers::getUrl()), ]; }Â //}
You can use Filament\Actions\CreateAction
, visit filament create action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\CreateAction::make() ->model(App\Models\User::class) ->form([ TextInput::make('name') ->required(), // ... ]) ]; }Â //}
You can use Filament\Actions\EditAction
, visit filament edit action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\EditAction::make() ->record($this->user) ->form([ TextInput::make('name') ->required(), // ... ]) ]; }Â //}
You can use Filament\Actions\ViewAction
, visit filament view action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\EditRecord;Â class EditUser extends EditRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\ViewAction::make() ->record($this->user) ->form([ TextInput::make('name') ->required(), // ... ])Â ]; }Â //}
You can use Filament\Actions\DeleteAction
, visit filament delete action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\DeleteAction::make() ->record($this->user) ]; }Â //}
You can use Filament\Actions\ReplicateAction
, visit filament replicate action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\ReplicateAction::make() ->record($this->user) ]; }Â //}
You can use Filament\Actions\ForceDeleteAction
, visit filament force delete action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\ForceDeleteAction::make() ->record($this->user) ]; }Â //}
You can use Filament\Actions\RestoreAction
, visit filament restore action for more information.
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\RestoreAction::make() ->record($this->user) ]; }Â //}
You can use Filament\Actions\ImportAction
, visit filament import action for more information.
use App\Filament\Imports\UserImporter;use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\ImportAction::make() ->importer(UserImporter::class) ]; }Â //}
You can use Filament\Actions\ExportAction
, visit filament export action for more information.
use App\Filament\Exports\UserExporter;use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ListRecords;Â class ListUsers extends ListRecords{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ \Filament\Actions\ExportAction::make() ->exporter(UserExporter::class) ]; }Â //}
You can use filament action with modal
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;use Filament\Actions\Action;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ Action::make('Quick edit user') ->form([ \Filament\Forms\Components\Grid::make(2) ->schema([ TextInput::make('name'), TextInput::make('email'), ]) ]) ->action(function($data){ $this->getRecord()->update([ 'name' => $data['name'], 'email' => $data['email'], ]); }) ]; }Â //}
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;use AymanAlhattami\FilamentContextMenu\Actions\{ RefreshAction, GoBackAction, GoForwardAction};Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â //Â public static function getContextMenuActions(): array { return [ RefreshAction::make(), GoBackAction::make(), GoForwardAction::make() ]; }Â //}
Method 1: To globally enable or disable the context menu, you need to define an env variable called CONTEXT_MENU_ENABLED
and to set the value to true
or false
.
Method 2: You can also define a static variable called public static bool $contextMenuEnabled
in the page and set the value to true
or false
;
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â # enable / disable context menu public static bool $contextMenuEnabled = true;Â //Â public static function getContextMenuActions(): array { return []; }Â //}
Method 3: define a static method called isContextMenuEnabled
in the page
use AymanAlhattami\FilamentContextMenu\Traits\PageHasContextMenu;use Filament\Resources\Pages\ViewRecord;Â class ViewUser extends ViewRecord{ use PageHasContextMenu;Â public static function isContextMenuEnabled(): bool { return true; }Â //Â public static function getContextMenuActions(): array { return []; }Â //}
To add a context menu to the table cell, you can use the following columns:
AymanAlhattami\FilamentContextMenu\Columns\ContextMenuTextColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuCheckboxColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuSelectColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuColorColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuIconColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuImageColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuTextInputColumn;AymanAlhattami\FilamentContextMenu\Columns\ContextMenuToggleColumn;
use Filament\Tables\Table;use Filament\Tables\Actions\Action;use AymanAlhattami\FilamentContextMenu\Columns\ContextMenuTextColumn;use App\Filament\Resources\UserResource\Pages\{ ViewUser, EditUser };Â //public static function table(Table $table): Table { return $table ->columns([ ContextMenuTextColumn::make('id') ->searchable() ->contextMenuActions(fn (Model $record) => [ Action::make('View user') ->url(ViewUser::getUrl(['record' => $record])) ->link() ->icon('heroicon-o-user'), ]), ContextMenuTextColumn::make('name') ->searchable() ->contextMenuActions(fn (Model $record) => [ Action::make('View user') ->url(Pages\ViewUser::getUrl(['record' => $record])) ->link() ->icon('heroicon-o-user'), Action::make('Edit user') ->url(Pages\EditUser::getUrl(['record' => $record])) ->link() ->icon('heroicon-o-pencil'), ]) , , ])}
Use AymanAlhattami\FilamentContextMenu\ContextMenuDivider
to set a divider between menu actions.
Use ->contextMenuEnabled()
method to enable/disable the context menu for the table cell.
//public static function table(Table $table): Table { return $table ->columns([ ContextMenuTextColumn::make('id') ->contextMenuEnabled(false) ->contextMenuActions(fn (Model $record) => [ Action::make('View user') ->url(ViewUser::getUrl(['record' => $record])) ->link() ->icon('heroicon-o-user'), ]),//
For action to have a nice style, use ->link()
method of the action, more information
public static function getContextMenuActions(): array{ return [ Action::make('Create user') ->url(CreateUser::getUrl()) ->link() ];}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.