Alpine toast is a toast library which allows users to label an element with x-toast and will make it a toast.
The library aims to be configurable for the 99% use case an forkable for the last 1%.
AlpineToast does not use the Alpine library but follows the simplicity of the project.
mcraealex.github.io/AlpineToast/dist/index.html
If using node just npm i alpine-toast then start using the lib.
npm i alpine-toast
If you need a cdn link create an issue and I will make it avaiable through a cdn.
First we have to create the instance of the AlpineToast library
import {AlpineToast, TailWindCSSConfig} from 'alpine-toast';
// Good defaults if your using tailwindcss
const toaster = AlpineToast(TailWindCSSConfig);
// Then we convert all the elements with x-toast into toasts
document.addEventListener('DOMContentLoaded', () => {
toaster.start();
})
Then we can add toasts by adding it to attributes. But we must remember that start must be called to convert these so if you doing this using flashes like in phoenix then you will need to call toaster.start again.
Important: AlpineToast does not create a new element. It transforms the elemen given into a toast by adding the classes passed into the config and adding it to the toast container. All attributes but the x-toast attribute are maintained
<div x-toast="{ duration: 1000, showProgressBar: true }">
Alternatively if its easier for you to use JS
toaster.newToast('content', optionalConfig);
This will create a new toast with text content
Lastly if you already have a element which you are building in js to add as a toast.
toaster.makeToast(elem, optionalConfig);
This will covert the element into a toast.
The easiest way to get started editing the codebase is by running
npm install
Then start the dev server
npm run dev
To see the changes do the same thing in the example dir which will allow you to modify both the example code and the library code an see you changes right away.