vanilla-toast
A toast notification module writtern in vanilla js that has no dependencies on other libraries.
Installation
Download or install with npm package manager.
$ npm install vanilla-toast
Add javascript and css file on your html document.
...
API Documentation
.show( text [, option] [, callback] )
Show toast using text. If you have toast present, or call .show()
multiple times at a time, the built-in queue will be used to show it sequentially.
text
Type: String
A text to show in toast.
option
Type: PlainObject
A map of additional options
-
duration (default:
2000
)
Type: Number
A number that determines the milliseconds at which toast is shown. (except fade animation) -
fadeDuration (default:
400
)
Type: Number
A number that determines the milliseconds of the fade animation. -
closeButton (default:
false
)
Type: Boolean
A boolean value that determines close button visible. -
immediately (default:
false
)
Type: Boolean
A boolean value that causes all currently visible or queued toast to be canceled and the new toast visible immediately. -
className (default:
'default'
)
Type: String
A string of class name to be set on the toast element for custom CSS styling.
callback
Type: Function
A function to be called after the toast show is complete.
Examples
Show with default options.
vanillaToast;
Show toast 10 seconds and fade-in, fade-out animation for 0.5 seconds each. (total 11 seconds)
vanillaToast;
Write console log after toast show is complete.
vanillaToast;
Show multiple toast sequentially using built-in queue.
// Call show method multiple times at a time.vanillaToast;vanillaToast; // With method chain.vanillaToast ;
.cancel( )
Cancel current showing toast immediately.
.cancelAll( )
Cancel current and all queued toast immediately.
.default( text [, option] [, callback] )
Equalvalent to .show()
.success( text [, option] [, callback] )
Equalvalent to .show()
but uses additional following option.
className: 'success'
.info( text [, option] [, callback] )
Equalvalent to .show()
but uses additional following option.
className: 'info'
.warning( text [, option] [, callback] )
Equalvalent to .show()
but uses additional following option.
className: 'warning'
.error( text [, option] [, callback] )
Equalvalent to .show()
but uses additional following option.
className: 'error' duration: 3000 closeButton: true
Styling
vanilla-toast creates the following DOM structure. With this, you can freely stylize with CSS.
some text. ✖
Example
Show toast with custom style.
...