Toasts
UtilitySimple notifications utilizing a dynamic queue system.
Import
Types
Package
Source
Docs
Examples
Usage
For the best results, add the following to your app's root component to make toasts available in global scope.
<Toast background="bg-accent-500" position="tr" variant="filled" duration={250} />
Create a Toast Message
Config the toast message object to your preference.
const toastMessage: ToastMessage = {
message: 'Your Message Here',
// Optional:
autohide: true,
timeout: 5000,
button: { label: 'Greeting', action: () => { alert('Hello, Skeleton'); }}
};
Toast Queue
Use the Toast store to manipulate the toast queue using the following methods.
import { toastStore } from '@brainandbones/skeleton';
// Trigger a toast
toastStore.trigger(toastMessage);
// Close the foremost open toast.
toastStore.close();
// Clear all toasts from the queue.
toastStore.clear();
Debugging
Log the Queue
Use the following to monitor the queue in your console as it updates. Note that Svelte store contents are only visible for the current logged line.
toastStore.subscribe(() => { console.log($toastStore); });
Visualize the Queue
Use the following to display the queue in your UI.
<pre>queue: {JSON.stringify($toastStore, null, 2)}</pre>
Accessibility
Meets the ARIA Guidelines.