Skip to content

Commit

Permalink
Merge pull request #51 from abishekrsrikaanth/custom-render-hook
Browse files Browse the repository at this point in the history
Render the plugin in a custom render hook
  • Loading branch information
awcodes authored May 29, 2024
2 parents d37a0aa + 649eff6 commit f78d64d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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;
}
}

0 comments on commit f78d64d

Please sign in to comment.