Skip to content

Commit

Permalink
Feat: support slide overs for simple resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
awcodes committed Aug 9, 2023
1 parent 2f2e0dd commit 197b04d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
])
}
```
14 changes: 14 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
3 changes: 2 additions & 1 deletion src/Components/QuickCreateMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
});
Expand Down
20 changes: 17 additions & 3 deletions src/QuickCreatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -77,15 +79,15 @@ 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,
'label' => Str::ucfirst($resource->getModelLabel()),
'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,
];
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down

0 comments on commit 197b04d

Please sign in to comment.