Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bezhansalleh/filament-panel-switch
The Panel Switch Plugin for Filament offers a robust and customizable component for switching between panels in applications built with FilamentPHP.
https://github.com/bezhansalleh/filament-panel-switch
filament filament-plugin filamentphp panel-switch panels
Last synced: 19 days ago
JSON representation
The Panel Switch Plugin for Filament offers a robust and customizable component for switching between panels in applications built with FilamentPHP.
- Host: GitHub
- URL: https://github.com/bezhansalleh/filament-panel-switch
- Owner: bezhanSalleh
- License: mit
- Created: 2023-08-04T02:26:51.000Z (over 1 year ago)
- Default Branch: 3.x
- Last Pushed: 2024-03-25T03:58:56.000Z (9 months ago)
- Last Synced: 2024-04-12T12:28:19.916Z (8 months ago)
- Topics: filament, filament-plugin, filamentphp, panel-switch, panels
- Language: PHP
- Homepage:
- Size: 2.48 MB
- Stars: 82
- Watchers: 4
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
- awesome-laravel-filament - Layout - Panel Switch
README
![Panel Switch](./art/banner.jpg?raw=true "Panel Switch")
Table Of Contents
-
Panel Switch-
Installation -
Configuration-
Design or Style -
Labels -
Icons/Images -
Icon/Image Size -
Visibility -
Who Can Switch Panels? -
Panel [New 1.0.7]
Sort Order [New 1.0.7] -
-
Placement -
Usage -
Theming
Panel Exclusion [@deprecated] -
-
Testing
Changelog
Contributing
Security Vulnerabilities
Credits
License
# Panel Switch
The Panel Switch Plugin for Filament offers a robust and customizable component for switching between panels in applications built with FilamentPHP.
![Demo](https://raw.githubusercontent.com/bezhanSalleh/filament-panel-switch/master/art/modern-icon-demo.gif?raw=true "Modern Icon Demo")
![Demo](https://raw.githubusercontent.com/bezhanSalleh/filament-panel-switch/master/art/modern-image-demo.gif?raw=true "Modern Image Demo")
![Demo](https://raw.githubusercontent.com/bezhanSalleh/filament-panel-switch/master/art/demo.gif?raw=true "Simple Demo")
## Installation
You can install the package via composer:
```bash
composer require bezhansalleh/filament-panel-switch
```
Upon installation, the Plugin seamlessly integrates with Filament without any further setup.
Though the plugin works out-of-the-box, it's designed for customization. Delve into the Configuration section below for detailed customization options.
## Configuration
Start your custom configuration using the `configureUsing` method in your service provider's boot method:
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
// Custom configurations go here
});
```
### Design or Style
By default, the Plugin uses Filament's [Modal Blade component](https://filamentphp.com/docs/3.x/support/blade-components/modal) as the modern design for the panel switch menu. But you can change it to the simple design by using the `simple()` method.
- #### Modern
- ##### Modal Heading
Set a custom Modal Heading for the Panel Switcher. By default, the modal heading is set to `Switch Panels`.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->modalHeading('Available Panels');
});
```
- ##### Modal Width
By default, the modal width is set to `screen` but you can use the options avaialbel for [Modal Blade component](https://filamentphp.com/docs/3.x/support/blade-components/modal#changing-the-modal-width).
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->modalWidth('sm');
});
```
- ##### Slide-Over
You can use the `slideOver()` method to open a `slide-over` dialog instead of the modal.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->slideOver();
});
```
- #### Simple
The `simple()` method transforms the panel switch menu to a dropdown list, allowing users to switch between panels directly from the list.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->simple();
});
```
### Labels
By using `labels()` method you can provide textual representation for each panel. The keys of the array should be valid panel IDs, and the values can be either regular strings or Laravel's translatable strings:
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
->labels([
'admin' => 'Custom Admin Label',
'general_manager' => __('General Manager')
]);
});
```
### Icons/Images
Define icons/images for available panels using the `icons()` method which accepts an array. The keys of the array should be valid panel IDs. If using images instead of icons, set the `$asImage` parameter to `true` and the value of the array should be the path to the image meaning a valid url:
- **Icons**
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->icons([
'validPanelId1' => 'heroicon-o-square-2-stack',
'validPanelId2' => 'heroicon-o-star',
], $asImage = false);
});
```
- **Images**
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->icons([
'validPanelId1' => 'https://raw.githubusercontent.com/bezhanSalleh/filament-panel-switch/3.x/art/banner.jpg',
'validPanelId2' => 'https://raw.githubusercontent.com/bezhanSalleh/filament-panel-switch/3.x/art/banner.jpg',
], $asImage = true);
});
```
### Icon/Image Size
Use the `iconSize()` method to set the size of the icons/images. The default size is `128px`. The value provided will be multiplied by 4 and then used as the size of the icon/image.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
// This would result in an icon/image size of 128 pixels.
$panelSwitch->iconSize(32);
});
```
### Visibility
By default, the package checks whether the user can access the panel if so the switch will be visible. You can further customize whether the panel switch should be shown.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
->visible(fn (): bool => auth()->user()?->hasAnyRole([
'admin',
'general_manager',
'super_admin',
]));
});
```
### Who Can Switch Panels?
You might want an option in a situation where you want a group of your users to see the panel but not be able to switch panels. You can do that by using the `canSwitchPanels()` method.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
->canSwitchPanels(fn (): bool => auth()->user()?->can('switch_panels'));
});
```
### Panels
By default all the panels available will be listed in the panel switch menu. But by providing an array of panel ids to the `panels()` method you can limit the panels that will be listed.
```php
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->panels([
'admin',
'dev',
'app'
]);
});
```
Then `panels()` method also accepts a closure that returns an array of panel ids. This is useful when you want to dynamically determine the panels that will be listed. The plugin will also validate the panels to ensure that they are valid filament panels. If any of the panels provided are invalid, the plugin will throw an `InvalidArgumentException`.
### Sort Order
By default the panels will be listed in the order they were registered in `config/app.php`'s `providers` array or in the order they are provided through the `panels()` method. But you can opt-in to sort the panels either in `asc` or `desc` order via `sort()` method.
```php
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
...
->panels(['admin', 'dev', 'app']) // default order if `sort()` method not used
->sort() // ['admin', 'app', 'dev']
// ->sort(order: 'desc') // ['dev', 'app', 'admin']
...
;
});
```
### Placement
You can choose where the panel switch menu should be placed. By default panel switch menu is rendered via 'panels::global-search.before' `Hook`. But you can change it to anyone of the other available Filament [Render Hooks](https://filamentphp.com/docs/3.x/support/render-hooks#available-render-hooks).
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->renderHook('panels::global-search.after');
});
```
### Usage
The `Panel Switch Plugin` has a fluent api so you can chain the methods together and configure everything in one go.
```php
use BezhanSalleh\PanelSwitch\PanelSwitch;
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch
->panels(['admin', 'app', 'dev'])
->heading('Available Panels')
->modalWidth('sm')
->slideOver()
->icons([
'admin' => 'heroicon-o-square-2-stack',
'app' => 'heroicon-o-star',
])
->iconSize(16)
->labels([
'admin' => 'Admin Panel',
'app' => 'SaaS Application'
]);
});
```
### Theming
By default the plugin uses the default filament theme, but you can customize it by adding the view path into the `content` array of your `panels'` `tailwind.config.js` file:
```php
export default {
content: [
// ...
'./vendor/bezhansalleh/filament-panel-switch/resources/views/panel-switch-menu.blade.php',
],
// ...
}
```
### Panel Exclusion
**`@deprecated`** use **`panels()`** method instead.
By default all the panels available will be listed in the panel switch menu. But you can exclude some of them by using the excludes() method.
```php
PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->excludes([
'saas'
]);
});
```
Optionally, you can publish the views using
```bash
php artisan vendor:publish --tag="filament-panel-switch-views"
```
### Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
If you want to contribute to this packages, you may want to test it in a real Filament project:
* Fork this repository to your GitHub account.
* Create a Filament app locally.
* Clone your fork in your Filament app's root directory.
* In the `/filament-panel-switch` directory, create a branch for your fix, e.g. `fix/error-message.`
Install the packages in your app's `composer.json:`
```php
"require": {
"bezhansalleh/filament-panel-switch": "dev-fix/error-message as main-dev",
},
"repositories": [
{
"type": "path",
"url": "filament-panel-switch"
}
]
```
Now, run composer update.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Bezhan Salleh](https://github.com/bezhanSalleh)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.