@axew/toast
@axew/toast is a html toast component.
Demo as https://daief.tech/axew-toast/.
Usage
Install.
$ yarn add @axew/toast
$ npm i @axew/toast
import toast from '@axew/toast';
toast('This a message');
toast('This a message', 3000);
toast(true, 3000);
toast(true, true);
toast({
loading: true,
className: 'className',
onClick() {
console.log('clicked');
},
});
toast('This a message', 3000).promise.then(() => {
console.log('Now is end.');
});
const { cancel, promise } = toast('This a message', 4000);
promise.catch(() => {
console.log('Catched when toast is canceled.');
});
setTimeout(() => {
cancel();
}, 1000);
API.
function toast(
opts: IOptions,
argTimeout?: number | true,
): {
promise: Promise<void>;
cancel: () => void;
};
type IOptions =
| true
| string
| {
text?: string;
loading?: boolean;
timeout?: number | true;
isModal?: boolean;
className?: string;
onClick?: IEventHandler;
};
interface IEventHandler {
(this: HTMLDivElement, ev: MouseEvent): void;
options?: boolean | AddEventListenerOptions;
}