diff --git a/CHANGELOG.md b/CHANGELOG.md index 490d795b..77c172de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## [Unreleased](https://github.com/php-flasher/php-flasher/compare/v2.1.4...2.x) +* feature [Flasher] Add event dispatching system for all notification adapters and themes with Livewire integration: + - [Toastr] Dispatch events: `flasher:toastr:click`, `flasher:toastr:close`, `flasher:toastr:show`, `flasher:toastr:hidden` + - [Noty] Dispatch events: `flasher:noty:click`, `flasher:noty:close`, `flasher:noty:show`, `flasher:noty:hover` + - [Notyf] Dispatch events: `flasher:notyf:click`, `flasher:notyf:dismiss` + - [Themes] Dispatch events: `flasher:theme:click` (generic) and `flasher:theme:{name}:click` (specific) + - [Laravel] Add LivewireListener classes for all adapters and themes to enable Livewire event handling + ## [v2.1.3](https://github.com/php-flasher/php-flasher/compare/v2.1.2...v2.1.3) - 2025-01-25 * bug [#208](https://github.com/php-flasher/php-flasher/issues/208) [Flasher] Add GitHub workflow for automatic publishing of assets to NPM. See [PR #211](https://github.com/php-flasher/php-flasher/pull/211) by [ToshY](https://github.com/ToshY) diff --git a/docs/pages/livewire.html b/docs/pages/livewire.html index fabb938c..b543dc7d 100644 --- a/docs/pages/livewire.html +++ b/docs/pages/livewire.html @@ -444,6 +444,211 @@ class UserComponent extends Component +
+ For Toastr notifications, you can listen to the following events: +
+ +| Event | +Description | +
|---|---|
toastr:click |
+ Fired when user clicks the notification | +
toastr:close |
+ Fired when notification is closed by user | +
toastr:show |
+ Fired when notification is shown | +
toastr:hidden |
+ Fired when notification is hidden | +
<?php
+
+namespace App\Livewire;
+
+use Livewire\Attributes\On;
+use Livewire\Component;
+
+class ToastrEventsComponent extends Component
+{
+ #[On('toastr:click')]
+ public function onToastrClick(array $payload): void
+ {
+ // Handle notification click
+ }
+
+ #[On('toastr:close')]
+ public function onToastrClose(array $payload): void
+ {
+ // Handle notification close
+ }
+
+ #[On('toastr:show')]
+ public function onToastrShow(array $payload): void
+ {
+ // Handle notification shown
+ }
+
+ #[On('toastr:hidden')]
+ public function onToastrHidden(array $payload): void
+ {
+ // Handle notification hidden
+ }
+}
+ + For Noty notifications, you can listen to the following events: +
+ +| Event | +Description | +
|---|---|
noty:click |
+ Fired when user clicks the notification | +
noty:close |
+ Fired when notification is closed | +
noty:show |
+ Fired when notification is shown | +
noty:hover |
+ Fired when user hovers over the notification | +
+ For Notyf notifications, you can listen to the following events: +
+ +| Event | +Description | +
|---|---|
notyf:click |
+ Fired when user clicks the notification | +
notyf:dismiss |
+ Fired when notification is dismissed | +
+ For PHPFlasher built-in themes, you can listen to the following events. Two types of events are dispatched: + a generic event and a theme-specific event. +
+ +| Event | +Description | +
|---|---|
theme:click |
+ Generic event fired when any theme notification is clicked | +
theme:{name}:click |
+ Specific event fired for a particular theme (e.g., theme:flasher:click) |
+
<?php
+
+namespace App\Livewire;
+
+use Livewire\Attributes\On;
+use Livewire\Component;
+
+class ThemeEventsComponent extends Component
+{
+ // Listen to clicks on any theme notification
+ #[On('theme:click')]
+ public function onThemeClick(array $payload): void
+ {
+ // Handle notification click
+ }
+
+ // Listen to clicks on a specific theme (e.g., 'flasher')
+ #[On('theme:flasher:click')]
+ public function onFlasherThemeClick(array $payload): void
+ {
+ // Handle flasher theme notification click
+ }
+}
+ Each listener method accepts an array $payload parameter, which contains: