Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render the plugin in a custom render hook #51

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,21 @@ public function panel(Panel $panel): Panel
])
}
```

### Render Plugin on a Custom Panel Hook

By default, Quick Create plugin renders using `'panels::user-menu.before'` Filament Panel Render Hook. If you would like to customize this to render at a different render hook, you may use the `renderUsingHook(string $panelHook)` modifier to do so. You may read about the available Render Hooks in Filament PHP [here](https://filamentphp.com/docs/3.x/support/render-hooks#available-render-hooks)

```php
use Awcodes\FilamentQuickCreate\QuickCreatePlugin;
use Filament\View\PanelsRenderHook;

public function panel(Panel $panel): Panel
{
return $panel
->plugins([
QuickCreatePlugin::make()
->renderUsingHook(PanelsRenderHook::SIDEBAR_NAV_END),
])
}
```
11 changes: 10 additions & 1 deletion src/QuickCreatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class QuickCreatePlugin implements Plugin

protected bool | Closure | null $rounded = null;

protected string $renderUsingHook = 'panels::user-menu.before';

public function boot(Panel $panel): void
{
Livewire::component('quick-create-menu', Components\QuickCreateMenu::class);
Expand Down Expand Up @@ -146,7 +148,7 @@ public function register(Panel $panel): void
{
$panel
->renderHook(
name: 'panels::user-menu.before',
name: $this->renderUsingHook,
hook: fn (): string => Blade::render('@livewire(\'quick-create-menu\')')
);
}
Expand Down Expand Up @@ -192,4 +194,11 @@ public function shouldBeHidden(): bool
{
return $this->evaluate($this->hidden) ?? false;
}

public function renderUsingHook(string $panelHook): static
{
$this->renderUsingHook = $panelHook;

return $this;
}
}