diff --git a/README.md b/README.md index 961213e..650857d 100644 --- a/README.md +++ b/README.md @@ -100,3 +100,20 @@ public function panel(Panel $panel): Panel ]) } ``` + +### Slide Overs + +By default, Quick Create will render simple resources in a standard modal. If you would like to render them in a slide over instead you may use the `slideOver()` modifier to do so. + +```php +use Awcodes\FilamentQuickCreate\QuickCreatePlugin; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugins([ + QuickCreatePlugin::make() + ->slideOver(), + ]) +} +``` diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..322d8d2 --- /dev/null +++ b/pint.json @@ -0,0 +1,14 @@ +{ + "preset": "laravel", + "rules": { + "blank_line_before_statement": true, + "concat_space": { + "spacing": "one" + }, + "method_argument_space": true, + "single_trait_insert_per_statement": true, + "types_spaces": { + "space": "single" + } + } +} \ No newline at end of file diff --git a/src/Components/QuickCreateMenu.php b/src/Components/QuickCreateMenu.php index ff9999b..2f107d9 100644 --- a/src/Components/QuickCreateMenu.php +++ b/src/Components/QuickCreateMenu.php @@ -51,7 +51,7 @@ protected function cacheActions(): void foreach ($actions as $action) { if (! $action instanceof Action) { - throw new InvalidArgumentException('Header actions must be an instance of '.Action::class.', or '.ActionGroup::class.'.'); + throw new InvalidArgumentException('Header actions must be an instance of ' . Action::class . ', or ' . ActionGroup::class . '.'); } $this->cacheAction($action); $this->cachedActions[$action->getName()] = $action; @@ -66,6 +66,7 @@ public function getActions(): array return CreateAction::make($resource['action_name']) ->authorize($r::canCreate()) ->model($resource['model']) + ->slideOver(fn (): bool => QuickCreatePlugin::get()->shouldUseSlideOver()) ->form(function ($arguments, $form) use ($r) { return $r->form($form->operation('create')->columns()); }); diff --git a/src/QuickCreatePlugin.php b/src/QuickCreatePlugin.php index d003e1a..0ac5c6e 100644 --- a/src/QuickCreatePlugin.php +++ b/src/QuickCreatePlugin.php @@ -22,6 +22,8 @@ class QuickCreatePlugin implements Plugin protected bool $sort = true; + protected bool | Closure | null $shouldUseSlideOver = null; + public function boot(Panel $panel): void { Livewire::component('quick-create-menu', Components\QuickCreateMenu::class); @@ -77,7 +79,7 @@ public function getResources(): array $resource = app($resourceName); if ($resource->canCreate()) { - $actionName = 'create_'.Str::of($resource->getModel())->replace('\\', '')->snake(); + $actionName = 'create_' . Str::of($resource->getModel())->replace('\\', '')->snake(); return [ 'resource_name' => $resourceName, @@ -85,7 +87,7 @@ public function getResources(): array 'model' => $resource->getModel(), 'icon' => $resource->getNavigationIcon(), 'action_name' => $actionName, - 'action' => ! $resource->hasPage('create') ? 'mountAction(\''.$actionName.'\')' : null, + 'action' => ! $resource->hasPage('create') ? 'mountAction(\'' . $actionName . '\')' : null, 'url' => $resource->hasPage('create') ? $resource::getUrl('create') : null, ]; } @@ -125,7 +127,19 @@ public function register(Panel $panel): void ); } - public function sort(bool|Closure $condition = true): static + public function shouldUseSlideOver(): bool + { + return $this->evaluate($this->shouldUseSlideOver) ?? false; + } + + public function slideOver(bool $condition = true): static + { + $this->shouldUseSlideOver = $condition; + + return $this; + } + + public function sort(bool | Closure $condition = true): static { $this->sort = $condition; diff --git a/tests/TestCase.php b/tests/TestCase.php index 3b2cb41..db9da96 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,7 +15,7 @@ protected function setUp(): void parent::setUp(); Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'Awcodes\\FilamentExtras\\Database\\Factories\\'.class_basename($modelName).'Factory' + fn (string $modelName) => 'Awcodes\\FilamentExtras\\Database\\Factories\\' . class_basename($modelName) . 'Factory' ); }