lbreda / livewire3-notify
Simple Notify binding for Livewire3
v1.0
2024-08-13 12:57 UTC
Requires
- php: ^8.2
- illuminate/support: >10.0
- livewire/livewire: ^3.0
README
Livewire3 Notify is a Livewire3 binding for SimpleNotify. That's it.
Installation
You have to install both SimpleNotify and this library:
npm i simple-notify composer require lbreda/livewire3-notify
Then you should include the SimpleNotify scripts in your app.js
(or equivalent):
import Notify from 'simple-notify' import 'simple-notify/dist/simple-notify.css' window.Notify = Notify
And this library component in your main layout:
<html> <head> ... @simpleNotify() </head> <body> ... </body> </html>
Usage
You can simply dispatch the notify
event inside your Livewire application. You can set the Simple Notify parameters (here is a reference) in the payload.
For example, you can use it in a component method:
#[On('test')] public function test(): void { $this->dispatch('notify', status: 'error', title: 'Error', text: 'Send halp'); }
or you can use it in a view:
<div> <button type="button" wire:click="$dispatch('notify', {status: 'error', title: 'Error', text: 'Send halp'})">Notify</button> </div>
Setting up the default configuration
You can export the default configuration via:
php artisan vendor:publish --provider 'LBreda\Livewire3Notify\Providers\SimpleNotifyServiceProvider'
You'll find a simple-notify.php
file in your config
directory. Customise it as you like.
Happy coding!