Home

Awesome

Codacy Badge bitHound Overall Score bitHound Code Code Climate Build Status GitHub license

NPM JavaScript Style Guide Package Quality

mini-toastr

Greenkeeper badge

mini-toastr - it's a small non-blocking notification library. No dependencies.

Demo

================

Instalation

  1. Install

via npm:

npm i mini-toastr --save

or download latest release

  1. Include in project

include in project:

import miniToastr from 'mini-toastr' //ES6
  1. Init
miniToastr.init()// config can be passed here miniToastr.init(config)

Usage

miniToastr.success(message, title, timeout, cb, config)
miniToastr.info(message, title, timeout, cb, config)
miniToastr.warn(message, title, timeout, cb, config)
miniToastr.error(message, title, timeout, cb, config)

Attention: You can specify your own types in global config: miniToastr.init({types: {debug: 'debug'}}) and use it - miniToastr.debug(message, title, timeout, cb, config)

Methods arguments

NameTypeDefaultRequiredDescription
messageStringundefinedYesMessage in notification
titleStringundefinedNoTitle for notification
timeoutNumber3000NoTime before notification gone
cbFunctionundefinedNoCallback function
configObjectundefinedNoLocal config for this menthod call

Global config

You can specify global config.

Here is default config:

const defaultConfig = {
    types: TYPES,
    animation: fadeOut,
    timeout: 3000,
    appendTarget: document.body,
    node: document.createElement('div'),
    style: {
      //Styles
    }
  }
NameTypeDefaultDescription
typesObject{error: 'error', warn: 'warn', success: 'success', info: 'info'}List of methods that would be accessable via miniToastr i.e. miniToastr.success(), miniToastr.info(), etc
animationFunctionfadeOutFunction for remove notification. Can be overrrided
timeoutNumber3000Notification time of life
appendTargetNodedocument.bodyDom element that miniToastr will be attached to
nodeNodedocument.createElement('div')Dom element for notification's container
styleObjectObject of objectsStyles that would be applyied for notifications (after they wuld be translated from js to css

Notifications structure

<!-- Container-->
<div id="mini-toastr" class="mini-toastr">

    <!-- Notification 1-->
    <div class="mini-toastr__notification -error">
        <div class="mini-toastr-notification__title">My Title</div>
        <div class="mini-toastr-notification__message">My message</div>
    </div>

    <!-- Notification 2-->
    <div class="mini-toastr__notification -success">
        <div class="mini-toastr-notification__title">My Title 2</div>
        <div class="mini-toastr-notification__message">My message 2</div>
    </div>

    <!-- Notification 3-->
    <div class="mini-toastr__notification -warning">
        <div class="mini-toastr-notification__title">My Title 3</div>
        <i class="your_class mini-toastr-notification__icon"></i> <!-- You're able to use "img"or whatever instead-->
        <div class="mini-toastr-notification__message">My message 3</div>
    </div>
</div>

You can override those classes in your styles or in global config:

miniToastr.init({
    style: {
        'mini-toastr__notification': {
          'mini-toastr-notification__message': {
              'border-radius': '5px',
              color: 'red'
          }
        }
    }
})

Adding an icon

You're able to add icons

//You can use any font icon
miniToastr.setIcon('error', 'i', {'class': 'fa fa-warning'})
miniToastr.setIcon('info', 'i', {'class': 'fa fa-info-circle'})
miniToastr.setIcon('success', 'i', {'class': 'fa fa-check-circle-o'})

//Or image (or any other element)
miniToastr.setIcon('warn', 'img', {src: 'assets/img/demo-warn.png', style: 'vertical-align: bottom;'})

Basically setIcon get 3 params:

Usually you have to set miniToastr.setIcon() after miniToastr.init() but also you can do it on each toast call.

Keep in mind, that if you will add class like miniToastr.setIcon('info', 'i', {'class': 'fa fa-info-circle'}), your actual class will be fa fa-info-circle mini-toastr-notification__icon.

So you'll be able to customize all the icons with css

Browser support.

Versions up to v0.6.6 - All modern browsers (ES5 support require). See ECMAScript 5 compliant browsers. Versions v0.7.0 and above - browsers with ES6 support only

License

MIT License

Copyright (c) 2016 Sergei Panfilov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.