Snackbar.js (Vanilla-Snackbar)
A simple implementation of a full width snackbar message using "vanilla js".
View exmple at http://chrisdimoulis.com/snackbar.js
Changelog

Production Dependencies
None! (not even jquery)
Installation
Node
npm install --save vanilla-snackbar
Ruby Gem for Rails
gem install vanilla-snackbar
Or simply add to your Gemfile:
gem 'vanilla-snackbar'
Usage
Importing/Including
Node
Import vanilla-snackbar
into your module:
import Snackbar from 'vanilla-snackbar';
Rails
Add to app/assets/javascripts/application.js
. Note that you should just require snackbar, not vanilla-snackbar.
Style
See src/snackbar.scss
for default style and reference if you desire to override any styles.
Pre DOM ready
If you create a snackbar and create a message before the DOM is ready the message will be stored in a queue which which will execute once the DOM is ready.
Create Snackbar
var default_snack = new Snackbar();
var short_snack = new Snackbar({time: 2000});
var manual_snack = new Snackbar({manual_close: true});
All options passed when creating the snackbar object are default. Overrides can be passed in each call to display a message.
Available Options
manual_close
: Boolean. Provide a close X button (true) vs timed close (false). Default: falsetime
: ms of time before automatic close. (ignored if manual_close: true
). Default: 5000class
: String containing desired classes to add to snackbar. Default: empty
NOTE: Default Options and Multiple Snackbar Objects
A new Snackbar object will not inject new #snackbar-wrapper
elements. All Snackbar objects use the same wrapper. It simply creates a new object with a different set of default options for displaying a Snackbar message. See below for overriding default options on a message specific basis as opposed to creating multiple Snackbar objects.
Displaying Messages
Displaying a message is as simple as calling the .message(msg, opts)
function of the Snackbar. There are also four helper methods for common Snackbar usage. All of these functions take 2 parameters:
msg
: the message to be displayed.opts
: the options to override default options.
snack.message('Hello World');
snack.stickyMessage('Acknowledge me!');
snack.success('You did it!');
snack.error("Something didn't work");
snack.warn("I'd be careful if I were you...");
Creating a Snackbar message will return a Promise object. This promise object will resolve when the Snackbar has finished fading in.
Overriding Default Options
var snack = new Snackbar();
snack.message('Read this', {manual_close: true})
var snack = new Snackbar({time: 2000});
snack.message("A slightly longer message..."), {time: 7500});
snack.message("My special snackbar", {class: 'my-snackbar your-snackbar'})