Add close notification event

This commit is contained in:
Ben
2024-06-27 10:37:22 +01:00
parent 4cb232fba5
commit 4f9ce38936
2 changed files with 23 additions and 0 deletions
@@ -414,6 +414,28 @@ new FilamentNotification()
.send()
```
## Close notification
You can close a notification automatically by dispatching a browser event on the window called `close-notification`.
```php
use Filament\Notifications\Notification;
Notification::make('custom')
->persistent()
->send()
```
Close from within Livewire page
```php
$this->dispatch('close-notification', id: 'custom');
```
Or frontend Alpine.js
```blade
<button x-on:click="$dispatch('close-notification', { id: 'custom' })">Close Notification</button>
```
## Using the JavaScript objects
The JavaScript objects (`FilamentNotification` and `FilamentNotificationAction`) are assigned to `window.FilamentNotification` and `window.FilamentNotificationAction`, so they are available in on-page scripts.
@@ -8,6 +8,7 @@
$attributes
->merge([
'wire:key' => "{$this->getId()}.notifications.{$notification->getId()}",
'x-on:close-notification.window' => "if (\$event.detail.id == '{$notification->getId()}') close()",
], escape: false)
->class(['pointer-events-auto invisible'])
}}