@axew/toast
@axew/toast is a toast component.
- light-weight
- promise
- cancelable
- non-dependence
Demo at https://daief.tech/axew-toast/.
Usage
Install.
$ yarn add @axew/toast
$ npm i @axew/toast
import toast, { createToast } from '@axew/toast';
toast.show('This a message. It will be hidden in 2.5 seconds.');
toast.show('This a message', 3000);
toast.success('This a message', 3000);
toast.config({ timeout: 3000 });
toast.show('This message will be hidden in 3 seconds.');
toast.loading('Loading...');
toast.show({
icon: 'loading',
className: 'my-custom-class',
onClick() {
console.log('clicked');
},
});
const cancel = toast.show(
{
text: 'This a message',
onClose: why => {
console.log(why);
},
},
4000
);
setTimeout(() => {
cancel();
}, 1000);
toast.destroyAll();
const toast2 = createToast();
API.
export declare function createToast(initCfg?: Partial<IObjectOptions>): {
show: IToastFunction;
success: IToastFunction;
error: IToastFunction;
warning: IToastFunction;
loading: IToastFunction;
destroyAll: () => void;
config: (opts: Partial<IObjectOptions>) => void;
};
export declare const toast: {
show: IToastFunction;
success: IToastFunction;
error: IToastFunction;
warning: IToastFunction;
loading: IToastFunction;
destroyAll: () => void;
config: (opts: Partial<IObjectOptions>) => void;
};
export default toast;
export interface IEventHandler {
(this: HTMLDivElement, ev: MouseEvent): void;
options?: boolean | AddEventListenerOptions;
}
export interface IObjectOptions {
text?: string;
asHtml?: boolean;
icon?: 'success' | 'error' | 'warning' | 'loading' | string;
iconSize?: number | string;
iconSpin?: boolean;
timeout?: number | true;
isModal?: boolean;
className?: string;
onClick?: IEventHandler;
onClose?: (why: 'auto' | 'cancel') => void;
}
export type IOptions = IObjectOptions | string;
export interface IToastFunction {
(argOpts: IOptions, timeout?: number): VoidFunction;
}