Giter Club home page Giter Club logo

angular-toastr's Introduction

Angular Toastr

Code Climate Build Status devDependency Status

angular-toastr is a port of CodeSeven/toastr

The goal is to provide the same API than the original one but without jQuery and using all the angular power.

Todo

There is an issue with a list of all the stuff I want to do next.

Demo

Demo

Installation

Grab the latest release and add both the css and javascript file:

<link rel="stylesheet" type="text/css" href="angular-toastr.css" />
<script type="text/javascript" src="angular-toastr.js"></script>

If you want animations, don't forget to add angular-animate.

Then add toastr to your modules dependencies:

angular.module('app', ['toastr'])

bower/npm/... packages coming soon. (Bower will come next version, I did it wrong and it needs an update to download the changes (jeezz...)

Usage

Basic usage

Toastr usage is very simple, by default it comes with four types of notification messages:

Success:

app.controller('foo', function($scope, toastr) {
  toastr.success('Hello world!', 'Toastr fun!');
});

Success Image

Info:

app.controller('foo', function($scope, toastr) {
  toastr.info('We are opened today from 10 to 22', 'Information');
});

Info Image

Error:

app.controller('foo', function($scope, toastr) {
  toastr.error('Your credentials are gone', 'Error');
});

Error Image

Warning:

app.controller('foo', function($scope, toastr) {
  toastr.warning('Your computer is about to explode!', 'Warning');
});

Warning Image

Apart from that you can customize your basic toasts:

No title:

app.controller('foo', function($scope, toastr) {
  toastr.success('I don\'t need a title to live');
});

No Title

Toastr customization

You can customize the entire library like:

app.config(function(toastrConfig) {
  angular.extend(toastrConfig, {
    allowHtml: true,
    closeButton: false,
    closeHtml: '<button>&times;</button>',
    containerId: 'toast-container',
    extendedTimeOut: 1000,
    iconClasses: {
      error: 'toast-error',
      info: 'toast-info',
      success: 'toast-success',
      warning: 'toast-warning'
    },
    messageClass: 'toast-message',
    positionClass: 'toast-top-right',
    tapToDismiss: true,
    timeOut: 5000,
    titleClass: 'toast-title',
    toastClass: 'toast'
  });
});

Those are the default values, you can pick what you need from it and override with your values.

  • allowHtml: Your toast can use custom HTML here (See Issue 3)
  • closeButton: Whether to display an "X" close button on the toast.
  • closeButton: Html element to be used as a close button.
  • containerId: The name of the container where you want to append your toasts (the container will be created for you).
  • extendedTimeOut: The timeout after you hover a toast.
  • iconClasses: The default type classes for the different toasts.
  • messageClass: The class for the toast's message.
  • positionClass: The position where the toasts are added.
  • tapToDismiss: Whether the toast should be dismissed when it is clicked.
  • timeOut: The timeout before the toasts disappear.
  • titleClass: The class for the toast's title.
  • toastClass: Base class for toasts.

You can also override options per toast, for example:

Toast with custom HTML (available in both title and message):

app.controller('foo', function($scope, toastr) {
  toastr.info('<input type="checkbox" checked> Success!', 'With HTML', {
    allowHtml: true
  });
});

Html Image

Toast with a close button:

toastr.success('What a nice button', 'Button spree', {
  closeButton: true
});

Html Image

Toast with a custom button for apple fans:

toastr.info('What a nice apple button', 'Button spree', {
  closeButton: true,
  closeHtml: '<button></button>'
});

Html Image

A pinky custom style (you can also create here new types with $decorate):

app.controller('foo', function($scope, toastr) {
  toastr.info('I am totally custom!', 'Happy toast', {
    iconClass: 'toast-pink'
  });
});

toast-pink is a custom class created for the occasion:

.toast-pink {
    background-image: url(...) !important;
    background-color: #fa39c3;
}

Pink image

See how we passed a third parameter to the toast.

There you can override:

  • closeButton: Putting a close button on the toast.
  • closeHtml: If you need to override how the close button looks like.
  • extendedTimeout: The timeout after you hover it.
  • iconClass: For the type class you want to use for the toast.
  • messageClass: If you want to modify the message look.
  • tapToDismiss: If you want a concrete toast to toggle the close on click.
  • timeOut: For that concrete toast timeout.
  • titleClass: To override the title class of the toast.
  • toastClass: For the main toast class.

Toast template

You can also override the toast template. To do that, put a template on your template cache like:

angular.module('yourApp').run(['$templateCache', function($templateCache) {
  $templateCache.put('templates/toastr/toastr.html',
    "<div>Your template here</div>"
  );
}]);

The important part here is to have a key named templates/toastr/toastr.html. The module you run it is not important, you just need to do it after you load toastr.

Building

If you want to build from master, you need to:

$ npm install -g grunt-cli
$ grunt && grunt prod

Grab the compressed files under /dist and the dev files at /gen.

Contributing

For contributing in this project, you need to create a pull request containing both your code and tests.

To create a proper patch I suggest:

$ npm install -g grunt-cli testem
$ grunt watch

And in another terminal:

$ testem -f config/testem.json

Then you can see if you have your new tests pass.

Credits

All the credits for the guys at CodeSeven/toastr for creating the original implementation.

License

Mit License: http://www.opensource.org/licenses/mit-license.php

angular-toastr's People

Contributors

chrisg2 avatar foxandxss avatar naz avatar sroe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.