Skip to content

Commit

Permalink
Added option for always using modal instead of resource create page
Browse files Browse the repository at this point in the history
  • Loading branch information
eneskomur authored Jul 17, 2024
1 parent 16624cd commit 16ae178
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/QuickCreatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class QuickCreatePlugin implements Plugin

protected string | Closure | null $label = null;

protected bool | Closure $shouldUseModal = false;

public function boot(Panel $panel): void
{
Livewire::component('quick-create-menu', Components\QuickCreateMenu::class);
Expand Down Expand Up @@ -112,8 +114,8 @@ public function getResources(): array
'model' => $resource->getModel(),
'icon' => $resource->getNavigationIcon(),
'action_name' => $actionName,
'action' => ! $resource->hasPage('create') ? 'mountAction(\'' . $actionName . '\')' : null,
'url' => $resource->hasPage('create') ? $resource::getUrl('create') : null,
'action' => ! $resource->hasPage('create') || $this->shouldUseModal ? 'mountAction(\'' . $actionName . '\')' : null,
'url' => $resource->hasPage('create') && ! $this->shouldUseModal ? $resource::getUrl('create') : null,
'navigation' => $resource->getNavigationSort(),
];
}
Expand Down Expand Up @@ -235,4 +237,16 @@ public function getLabel(): ?string
{
return $this->evaluate($this->label) ?? null;
}

public function shouldUseModal(): bool
{
return $this->evaluate($this->shouldUseModal) ?? false;
}

public function alwaysShowModal(bool $condition = true): static
{
$this->shouldUseModal = $condition;

return $this;
}
}

0 comments on commit 16ae178

Please sign in to comment.