• Stars
    star
    2,102
  • Rank 21,855 (Top 0.5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure JavaScript library for better notification messages

Toastify

Built with JavaScript

toastify-js MIT License

Toastify is a lightweight, vanilla JS toast notification library.

Demo

Click here

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.
npm install --save toastify-js

or

yarn add toastify-js -S
  • Import toastify-js into your module to start using it.
import Toastify from 'toastify-js'

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

import "toastify-js/src/toastify.css"

Adding ToastifyJs to HTML page using the traditional method

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

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

And the script at the bottom of the page

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

Files are delivered via the CDN service provided by jsdeliver

Documentation

Toastify({
  text: "This is a toast",
  duration: 3000,
  destination: "https://github.com/apvarun/toastify-js",
  newWindow: true,
  close: true,
  gravity: "top", // `top` or `bottom`
  position: "left", // `left`, `center` or `right`
  stopOnFocus: true, // Prevents dismissing of toast on hover
  style: {
    background: "linear-gradient(to right, #00b09b, #96c93d)",
  },
  onClick: function(){} // Callback after click
}).showToast();

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

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:

Toastify({
  text: "This is a toast",
  className: "info",
  style: {
    background: "linear-gradient(to right, #00b09b, #96c93d)",
  }
}).showToast();

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:

Toastify({
  text: "This is a toast with offset",
  offset: {
    x: 50, // horizontal axis - can be a number or a string indicating unity. eg: '2em'
    y: 10 // vertical axis - can be a number or a string indicating unity. eg: '2em'
  },
}).showToast();

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

Option Key type Usage Defaults
text string Message to be displayed in the toast "Hi there!"
node ELEMENT_NODE Provide a node to be mounted inside the toast. node takes higher precedence over text
duration number Duration for which the toast should be displayed.
-1 for permanent toast
3000
selector string | ELEMENT_NODE ShadowRoot CSS Selector or Element Node on which the toast should be added
destination URL string URL to which the browser should be navigated on click of the toast
newWindow boolean Decides whether the destination should be opened in a new window or not false
close boolean To show the close icon or not false
gravity "top" or "bottom" To show the toast from top or bottom "top"
position "left" or "right" To show the toast on left or right "right"
backgroundColor CSS background value To be deprecated, use style.background option instead. Sets the background color of the toast
avatar URL string Image/icon to be shown before text
className string Ability to provide custom class name for further customization
stopOnFocus boolean To stop timer when hovered over the toast (Only if duration is set) true
callback Function Invoked when the toast is dismissed
onClick Function Invoked when the toast is clicked
offset Object Ability to add some offset to axis
escapeMarkup boolean Toggle the default behavior of escaping HTML markup true
style object Use the HTML DOM Style properties to add any style directly to toast
ariaLive string Announce the toast to screen readers, see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions for options "polite"
oldestFirst boolean Set the order in which toasts are stacked in page true

Deprecated properties: backgroundColor - use style.background option instead

Browsers support


IE / Edge

Firefox

Chrome

Safari

Opera
IE10, IE11, Edge last 10 versions last 10 versions last 10 versions last 10 versions

Contributors

AStoker
AStoker
caiomoura1994
caiomoura1994
rndevfx
rndevfx
1ess
1ess
d4rn0k
d4rn0k
danielkaiser80
danielkaiser80
skjnldsv
skjnldsv
chasedeanda
chasedeanda
chrisgraham
chrisgraham
Wachiwi
Wachiwi
FeixuRuins
FeixuRuins
gavinhungry
gavinhungry
haydster7
haydster7
joaquinwojcik
joaquinwojcik
juliushaertl
juliushaertl
mort3za
mort3za
Sandip124
Sandip124
Tadaz
Tadaz
t12ung
t12ung
victorfeijo
victorfeijo
fiatjaf
fiatjaf
prousseau-korem
prousseau-korem

License

MIT © Varun A P

Buy Me A Coffee

More Repositories

1

blist-hugo-theme

Blist is a clean and fast blog theme for your Hugo site.
HTML
333
star
2

graphize

Visualize and download JSON / YAML content
TypeScript
255
star
3

digital-garden-hugo-theme

Build your own personal Digital Garden effortlessly with this Hugo theme
HTML
236
star
4

showfolio-hugo-theme

Modern portfolio theme for your Hugo site
HTML
98
star
5

showcase-hugo-theme

Showcase is a minimal, single page theme for Hugo
HTML
60
star
6

celestial-theme

VS Code theme for all the people who love to code in deep dark spaces.
29
star
7

productlog-nextjs-theme

NextJS-based changelog theme for your product
TypeScript
25
star
8

poppyjs

Simple, Multipurpose Open Source Pop-in Messages
JavaScript
24
star
9

tailwindcss-analysis

Analyse the TailwindCSS classes used in your application
TypeScript
18
star
10

sapper-stunning-theme

Static Site/Blog built with Sapper/Svelte
Svelte
17
star
11

ng-tailwindcss-jit

Configures your angular project to use jit compiler for tailwindcss
JavaScript
9
star
12

learndevtools

Debug Better With DevTools
HTML
7
star
13

parcel-plugin-prettier

📦 Parcel plugin to add Prettier to your code
JavaScript
6
star
14

demo-ng-tailwindcss-jit

Demo Angular application using ng-tailwindcss-jit
TypeScript
5
star
15

linkverse

A one page link-in-bio page with Astro
Astro
5
star
16

react-onboarding-pro

Onboarding flow for reducing friction to use the application and improving the workflow
JavaScript
5
star
17

wouter-hono

Minimalist-friendly ~1.5KB router - wouter, adapted for Hono
TypeScript
3
star
18

contributors-table-generator

Generate HTML table of contributors list for readme
Svelte
2
star
19

magic-regexp-angular-demo

Demo of magic-regexp usage with an Angular project
JavaScript
2
star
20

CleanNation

App for Swachh Bharat with Material design
Java
2
star
21

apvarun

2
star
22

systic-astro-theme

Astro theme to create a curated list page.
Astro
2
star
23

sapper-sources

Helpers for supporting external sources in a sapper app
JavaScript
2
star
24

apvarun.com

Personal website, built with VueJS and Gridsome
HTML
2
star
25

sapper-job-board

Job board template built on top of Sapper
JavaScript
1
star
26

collecte

Minimal plugin to get feedback from your website
JavaScript
1
star
27

parcel-plugin-shell

Plugin to run shell commands before/after bundling process.
JavaScript
1
star
28

openperf-page

Custom Google Analytics Performance page
TypeScript
1
star
29

rewind-components

Ready to use components for your next project
JavaScript
1
star