Download the PHP package ingress-it-solutions/livewire-toaster without Composer
On this page you can find all versions of the php package ingress-it-solutions/livewire-toaster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ingress-it-solutions/livewire-toaster
More information about ingress-it-solutions/livewire-toaster
Files in ingress-it-solutions/livewire-toaster
Package livewire-toaster
Short Description Beautiful toast notifications for Laravel / Livewire.
License MIT
Homepage https://github.com/masmerise/livewire-toaster
Informations about the package livewire-toaster
Beautiful toast notifications for Livewire
Toaster provides a seamless experience to display toast notifications in your Livewire powered Laravel apps.
Unlike many other toast implementations that are available, Toaster makes it effortless to dispatch a toast notification
from either a standard Controller
or a Livewire Component
. You don't have to think about "flashing" things to the
session or "dispatching browser events" from your Livewire components. Just dispatch your toast and Toaster will route the message accordingly.
Showcase
Contents
- Installation
- Preparing your template
- Configuring scripts
- Tailwind styles
- Usage
- Sending toasts from the back-end
- Sending toasts from the front-end
- Automatic translation of messages
- Accessibility
- Unit testing
- View customization
- Testing
- Changelog
- Security
- Credits
- License
Installation
You can install the package via composer:
You can publish the package's config file:
This is the contents of the toaster.php
config file:
Preparing your template
Next, you'll need to use the <x-toaster-hub />
component in your master template:
Configuring scripts
After that, you'll need to register the Toaster
plugin with your resources/js/app.js
bundle to start listening to incoming toasts:
Tailwind styles
Note Skip this step if you're going to customize Toaster's default view.
Toaster provides a minimal view that utilizes Tailwind CSS defaults.
If the default toast appearances suffice your needs, you'll need to register it with Tailwind's purge list:
Otherwise, please refer to View customization.
Usage
Sending toasts from the back-end
Note Toaster supports the dispatch of multiple toasts at once, you are not limited to dispatching a single toast.
Toaster
The standard recommended way for dispatching toast messages is through the Toaster
facade.
If you need fine-grained control, you can always use the PendingToast
class directly to which Toaster
proxies its calls:
Toastable
You can make any class Toastable
to dispatch toasts from:
Redirects
Whenever you return a RedirectResponse
from anywhere in your app, you can chain any of the Toaster
methods
to dispatch a toast message:
This is, of course, not limited to Controller
s as you can also redirect in Livewire Component
s.
Dependency injection
If you'd like to keep things "pure", you can also inject the Collector
contract
and use the ToastBuilder
to dispatch your toasts:
Sending toasts from the front-end
You can invoke the globally available Toaster
instance to dispatch any toast message from anywhere:
Available methods: error
, info
, warning
& success
Automatic translation of messages
Note The
translate
configuration value must be set totrue
.
Instead of doing this:
Toaster makes it possible to do this:
You can mix and match without any problems:
You can do whatever you want, whenever you want.
Accessibility
Note The
accessibility
configuration value must be set totrue
.
Toaster will add an additional second to a toast's on-screen duration for every 100th word. This way, your users will have enough time to read toasts that are a tad larger than usual.
So, if your base duration value is 3 seconds
and your toast contains 223 words,
the total on-screen duration of the toast will be 3 + 2 = 5 seconds
Unit testing
Note If you make use of automatic translation of messages, you should assert whether the translation keys are passed along correctly instead of the human readable messages that are replaced by Laravel's translator. Otherwise, your tests are going to fail as the messages are not translated during unit testing.
Toaster provides a couple of testing capabilities in order for you to build a robust application:
View customization
Warning You must keep the
x-data
andx-init
directives and you must keep using thex-for
loop. Otherwise, the Alpine component that powers Toaster will start malfunctioning.
Even though the default toasts are pretty, they might not fit your design and you may want to customize them.
You can do so by publishing Toaster's views:
The hub.blade.php
view will be published to your application's resources/views/vendor/toaster
directory.
Feel free to modify anything to your liking.
Available viewData
$alignment
- can be used to align the toast container vertically depending on the configuration$closeable
- whether the close button should be rendered by the Blade component$config
- default configuration values, used by the Alpine component$position
- can be used to position the toasts depending on the configuration$toasts
- toasts that were flashed to the session by Toaster, used by the Alpine component
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Muhammed Sari
- Greg Korba
- All Contributors
License
The MIT License (MIT). Please see License File for more information.