Toastify

Pure JavaScript library for better notification messages

README


Toastify


Built with JavaScript
toastify-js
MIT License

Toastify is a lightweight, vanilla JS toast notification library.

Demo



Features


Multiple stacked notifications
Customizable
No blocking of execution thread

Customization options


Notification Text
Duration
Toast background color
Close icon display
Display position
Offset position

Installation


Toastify now supports installation via NPM


Run the below command to add toastify-js to your exisitng or new project.

  1. ```
  2. npm install --save toastify-js
  3. ```

or

  1. ```
  2. yarn add toastify-js -S
  3. ```

Import toastify-js into your module to start using it.

  1. ```
  2. import Toastify from 'toastify-js'
  3. ```

You can use the default CSS from Toastify as below and later override it or choose to write your own CSS.

  1. ```
  2. import "toastify-js/src/toastify.css"
  3. ```

Adding ToastifyJs to HTML page using the traditional method


To start using Toastify, add the following CSS on to your page.

  1. ``` html
  2. <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
  3. ```

And the script at the bottom of the page

  1. ``` html
  2. <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
  3. ```

Files are delivered via the CDN service provided by jsdeliver


Documentation


  1. ``` js
  2. Toastify({
  3.   text: "This is a toast",
  4.   duration: 3000,
  5.   destination: "https://github.com/apvarun/toastify-js",
  6.   newWindow: true,
  7.   close: true,
  8.   gravity: "top", // `top` or `bottom`
  9.   position: "left", // `left`, `center` or `right`
  10.   stopOnFocus: true, // Prevents dismissing of toast on hover
  11.   style: {
  12.     background: "linear-gradient(to right, #00b09b, #96c93d)",
  13.   },
  14.   onClick: function(){} // Callback after click
  15. }).showToast();
  16. ```

Toast messages will be centered on devices with screen width less than 360px.


See the changelog

Add own custom classes


If you want to use custom classes on the toast for customizing (like info or warning for example), you can do that as follows:

  1. ``` js
  2. Toastify({
  3.   text: "This is a toast",
  4.   className: "info",
  5.   style: {
  6.     background: "linear-gradient(to right, #00b09b, #96c93d)",
  7.   }
  8. }).showToast();
  9. ```

Multiple classes also can be assigned as a string, with spaces between class names.

Add some offset


If you want to add offset to the toast, you can do that as follows:

  1. ``` js
  2. Toastify({
  3.   text: "This is a toast with offset",
  4.   offset: {
  5.     x: 50, // horizontal axis - can be a number or a string indicating unity. eg: '2em'
  6.     y: 10 // vertical axis - can be a number or a string indicating unity. eg: '2em'
  7.   },
  8. }).showToast();
  9. ```

Toast will be pushed 50px from right in x axis and 10px from top in y axis.

Note:

If position is equals to left, it will be pushed from left.
If gravity is equals to bottom, it will be pushed from bottom.

API


OptiontypeUsageDefaults
|-----------------|----------------------|----------------------------------------------------------------------------|-------------|
textstringMessage"Hi
nodeELEMENT_NODEProvide|
durationnumberDuration3000
selectorstringELEMENT_NODEShadowRoot
destinationURLURL|
newWindowbooleanDecidesfalse
closebooleanTofalse
gravity"top"To"top"
position"left"To"right"
backgroundColorCSSTo|
avatarURLImage/icon|
classNamestringAbility|
stopOnFocusbooleanTotrue
callbackFunctionInvoked|
onClickFunctionInvoked|
offsetObjectAbility|
escapeMarkupbooleanToggletrue
styleobjectUse|
ariaLivestringAnnounce"polite"
oldestFirstbooleanSettrue

Deprecated properties: backgroundColor - use style.background option instead


Browsers support


![][ie]![][firefox]![][chrome]![][safari]![][opera]
------------------------------------------------------------------------------------------------------------------
IE10,lastlastlastlast

Contributors





        <img
          alt="AStoker"
          src="https://avatars.githubusercontent.com/u/2907279?v=4"
          width="117"
        />

        AStoker
        <img
          alt="caiomoura1994"
          src="https://avatars.githubusercontent.com/u/9389139?v=4"
          width="117"
        />

        caiomoura1994
        <img
          alt="rndevfx"
          src="https://avatars.githubusercontent.com/u/5052076?v=4"
          width="117"
        />

        rndevfx
        <img
          alt="1ess"
          src="https://avatars.githubusercontent.com/u/36092926?v=4"
          width="117"
        />

        1ess
        <img
          alt="d4rn0k"
          src="https://avatars.githubusercontent.com/u/2183269?v=4"
          width="117"
        />

        d4rn0k
        <img
          alt="danielkaiser80"
          src="https://avatars.githubusercontent.com/u/33827555?v=4"
          width="117"
        />

        danielkaiser80
        <img
          alt="skjnldsv"
          src="https://avatars.githubusercontent.com/u/14975046?v=4"
          width="117"
        />

        skjnldsv
        <img
          alt="chasedeanda"
          src="https://avatars.githubusercontent.com/u/8203134?v=4"
          width="117"
        />

        chasedeanda
        <img
          alt="chrisgraham"
          src="https://avatars.githubusercontent.com/u/195389?v=4"
          width="117"
        />

        chrisgraham
        <img
          alt="Wachiwi"
          src="https://avatars.githubusercontent.com/u/4199845?v=4"
          width="117"
        />

        Wachiwi
        <img
          alt="FeixuRuins"
          src="https://avatars.githubusercontent.com/u/66232834?v=4"
          width="117"
        />

        FeixuRuins
        <img
          alt="gavinhungry"
          src="https://avatars.githubusercontent.com/u/744538?v=4"
          width="117"
        />

        gavinhungry
        <img
          alt="haydster7"
          src="https://avatars.githubusercontent.com/u/4540595?v=4"
          width="117"
        />

        haydster7
        <img
          alt="joaquinwojcik"
          src="https://avatars.githubusercontent.com/u/3205737?v=4"
          width="117"
        />

        joaquinwojcik
        <img
          alt="juliushaertl"
          src="https://avatars.githubusercontent.com/u/3404133?v=4"
          width="117"
        />

        juliushaertl
        <img
          alt="mort3za"
          src="https://avatars.githubusercontent.com/u/510242?v=4"
          width="117"
        />

        mort3za
        <img
          alt="Sandip124"
          src="https://avatars.githubusercontent.com/u/37034590?v=4"
          width="117"
        />

        Sandip124
        <img
          alt="Tadaz"
          src="https://avatars.githubusercontent.com/u/10881931?v=4"
          width="117"
        />

        Tadaz
        <img
          alt="t12ung"
          src="https://avatars.githubusercontent.com/u/9781423?v=4"
          width="117"
        />

        t12ung
        <img
          alt="victorfeijo"
          src="https://avatars.githubusercontent.com/u/8865899?v=4"
          width="117"
        />

        victorfeijo
        <img
          alt="fiatjaf"
          src="https://avatars.githubusercontent.com/u/1653275?v=4"
          width="117"
        />

        fiatjaf
        <img
          alt="prousseau-korem"
          src="https://avatars.githubusercontent.com/u/59747802?v=4"
          width="117"
        />

        prousseau-korem




License


MIT © Varun A P

Buy Me A Coffee

[ie]: https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/edge.png
[firefox]: https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/firefox.png
[chrome]: https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/chrome.png
[safari]: https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/safari.png
[opera]: https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/opera.png