Wrapper for Toastr.js notifications
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
addon
app
blueprints
config
tests
vendor
.editorconfig
.ember-cli
.eslintrc.js
.gitignore
.npmignore
.npmrc
.travis.yml
.watchmanconfig
.yarnrc
CHANGELOG.md
LICENSE.md
README.md
ember-cli-build.js
index.js
package.json
testem.js
yarn.lock

README.md

ember-toastr

A service wrapper for toastr.js with auto injection into routes, components, and controllers.

npm version Build Status Ember Observer Score

Usage

ember install ember-toastr

The toastr service is injected as toast into controllers, routes, and components, so it can be used like so:

this.toast.info('Hello there!');

⚠️ Version 2.0 will probably remove the automatic injection into controllers and components in favor of service injection, and your own automatic injection.

If you want to access it anywhere else, please inject it

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
  notifications: service('toast'),

  test() {
    // don't forget to use `get`, since injections are computed properties
    let notifications = this.get('notifications');

    notifications.info('text', 'title', options);
  }
});

You can also use toast.clear() and toast.remove() to remove all toasts. For example:

<button onclick={{action toast.clear}}>Clear</button>

See the toastr.js demo for other possible uses, and the toastr.js documentation for explanation of options.

API

toast Service

success(msg = '', title = '', options = {})

A method with the above default values for displaying a success toast.

info(msg = '', title = '', options = {})

A method with the above default values for displaying a info toast.

warning(msg = '', title = '', options = {})

A method with the above default values for displaying a warning toast.

error(msg = '', title = '', options = {})

A method with the above default values for displaying an error toast.

clear() or clear(toast)

A method to clear all toasts, or the individual toast.

remove() or remove(toast)

A method to remove all toasts, or the individual toast.

toasts

A property to access all toasts that are added.

Configuration

These are the default options:

ENV['ember-toastr'] = {
  injectAs: 'toast',
  toastrOptions: {
    closeButton: true,
    debug: false,
    newestOnTop: true,
    progressBar: true,
    positionClass: 'toast-top-right',
    preventDuplicates: true,
    onclick: null,
    showDuration: '300',
    hideDuration: '1000',
    timeOut: '4000',
    extendedTimeOut: '1000',
    showEasing: 'swing',
    hideEasing: 'linear',
    showMethod: 'fadeIn',
    hideMethod: 'fadeOut'
  }
};

All options in toastrOptions are direct options for toastr.js.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

Publish Demo Site

ember github-pages:commit --message <message>
git push

For more information on using ember-cli, visit http://www.ember-cli.com/.