Notification handler. KISS, light and library free.

Overview

Notification.js

License

Notification.js is a standalone ES6 module that allows you to easily handle several notifications from different types at the same time. It features a lot of options so you can customize it.

Get started

Notification.js handles four different types of notifications : Success, Info, Warning and Error.

The first step for you to get started with Notification.js is to copy both the dist/Notification.min.js and dist/notification.min.css files in your code base. Once pasted, don't forget to include the style and the script in your HTML page. Notification.js is ready to be used.

With ~18Ko minified, Notification.js is designed to be stable and remain as light as possible. It is meant to be used application wide.

Basic usage

To make Notification.js work, you must call for a new notification handler. It will handle all new notifications coming to the stack, with their specificities. Attach preferably this handler to the window object, so you can access it from anywhere in your app:

import Notification from 'path/to/Notification.js';
window.notification = new Notification();

Now that the handler is set, you can call for new notifications anywhere, at anytime using the following calls:

window.notification.success({ message: 'Great success!' });
window.notification.info({ message: 'Much info, very text' });
window.notification.warning({ message: 'Snake?' });
window.notification.error({ message: 'Snaaaaaaaake!' });

The message string passed is mandatory. Forget to pass it and you will raise an error in the console.

Advanced usage

The Notification constructor can take an options object with the following attributes :

import Notification from 'path/to/Notification.js';
window.notification = new Notification({
    position: 'top-left',
    thickBorder: 'bottom',
    duration: 2000,
    transition: 100,
    maxActive: 5
});

The handler is now ready with your custom settings. To call for a new notification, you can still use the typed methods .success(), .info(), .warning() and .error() from Basic Usage, but you can also use the .new() method :

let id = window.notification.new({
   type: 'info', // Mandatory
   title: 'My test notification',
   message: 'My test message.', // Mandatory
   thickBorder: 'top',
   iconless: false,
   closable: true,
   sticky: true,
   renderTo: document.body,
   CBtitle: 'My callback',
   callback: () => {
     alert('Called from my test notification');
   }
});

The only difference with the typed methods is that with the .new() method, you must give it a type beside giving it a message: those are the two required options to create a standard notification. You can also pass this options object to the typed methods.

As for the typed methods, the new() method return the notification ID, in case you want some manual control over your notifications, this is why we store it in the id variable. Using this ID, you can dismiss a specific notification :

window.notification.dismiss(id);

Or dismiss them all :

window.notification.dismissAll();

Or dismiss them by type :

window.notification.dismissType('error');

Finally, if you want to clear the Notification singleton, use the destroy() method on the handler :

window.notification.destroy();

Notification options

Handler settings

Options Default Values
position top-right top-left, top-right, bottom-left, bottom-right
thickBorder top left, right, top, bottom, none
duration 5000 ms Positive integer
transition 200 ms Positive integer, not greater than half duration
maxActive 5 Positive integer

Notification settings

Option Default Values
type info success, info, warning, error
title '' String
message '' String with a length greater than 0
thickBorder Handler value left, right, top, bottom, none
iconless false true, false
closable true true, false
sticky false true, false
renderTo Handler container DOM Object
CBtitle '' String
callback null JavaScript function

You're now good to go! If however you need more information, you can read the online documentation.

Development

If you clone this repository, you can npm install to install development dependencies. This will allow you to build dist file, run the component tests or generate the documentation ;

  • npm run build to generate the minified file ;
  • npm run dev to watch for any change in source code ;
  • npm run web-server to launch a local development server ;
  • npm run doc to generate documentation ;
  • npm run test to perform all tests at once ;
  • npm run testdev to keep browsers open to debug tests ;
  • npm run beforecommit to perform tests, generate doc and bundle the JavaScript.

To avoid CORS when locally loading the example HTML file, run the web server. Please do not use it on a production environment. Unit tests are performed on both Firefox and Chrome ; ensure you have both installed before running tests, otherwise they might fail.

If you have any question or idea, feel free to DM or open an issue (or even a PR, who knows) ! I'll be glad to answer your request.

You might also like...

JavaScript Alert/Notification System

alertify.js - browser dialogs never looked so good The end of maintenance... at least for now Unfortunately, I will no longer be maintaining alertify.

Dec 22, 2022

jQuery quick notification plugin. jQuery плагин быстрых уведомлений

Note: English translation by Google Translate Notific About Description: this is a jQuery plugin that helps you display notifications on your site. Li

Nov 7, 2021

Vanilla JS toast notification.

Toasting Toasting - is a javascript library for notifications. There is no dependencies needed. Installing There is no npm or cdn is available yet. by

Jun 30, 2022

jQuery plugin for a Notification Bar

jquery.peekABar A jQuery plugin for a notification bar with customization options. Important Note We have stopped supporting bower as a package manage

Dec 11, 2022

Error and Success Handler for Passport.js

Error and Success Handler for Passport.js

passport-handler Developed with ❤️ by Swôth 🔎 Installation npm i passport-handler --save yarn add passport-handler 🔮 Importing import Handler from '

Oct 29, 2022

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

Discord.js v14 Command-Handler Commands, Events, Permissions and Cooldown Handlers for Discord.js v14 bot ~ Made by Lynx Discord.js v14 (dev version)

Dec 19, 2022

A Discord bot Template made with Discord.JS version 14 includes Prefix, Slash commands and MongoDB handler.

A Discord bot Template made with Discord.JS version 14 includes Prefix, Slash commands and MongoDB handler.

Project Language: Fork/Download for: Project Requirements: Database Available: DiscordJS V14 Bot Template - Introduction: A Discord bot project made w

Jan 3, 2023

🌗 1 line of code to apply auto dark / light theme and support custom theme for your website. Super fast and lightweight theme library.

themes.js A super lightweight and fast Theme library with auto system color scheme detection in JavaScript. Features Auto detect Dark / Light mode by

Nov 29, 2022

An Amazing SlashCommands Handler (With Sharding & Mongo) Made by discord.gg/azury

An Amazing SlashCommands Handler (With Sharding & Mongo) Made by discord.gg/azury

SlashCommands Handler by The Azury Team If this Git-Repo gets "40" Stars ⭐ i'll add some more Commands! 🛠️ FEATURES: 1. SlashCommands Support 2. Cont

Dec 2, 2022
Releases(1.1.0)
Owner
Arthur Beaulieu
Web UI/UX engineer – Paris 🇫🇷
Arthur Beaulieu
Unified JavaScript logging system. KISS, light and library free.

Logger.js Logger.js is a JavaScript ES6 module that offers a unified console output across Firefox and Chromium based browsers. It handles standard er

Arthur Beaulieu 1 Oct 1, 2020
A simple and light jquery library for toast notification!

What is notify message? Notify message it's a simple jquery library for create a simple and light push notification in your website! How does this wor

Ivan Persiani 3 Feb 23, 2022
DiscordJs13-handler is the solution for all the discord.js developper who want a complete handler for slash commands

DiscordJs13-handler is the solution for all the discord.js developper who want a complete handler for slash commands

null 9 Jul 2, 2022
In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. I followed the JavaScript, CSS, HTML, DRY, KISS and YAGNI Best practices.

To Do list: add & remove In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. All the elements of th

Olivier 6 Nov 20, 2022
Lightweight and simple notification library in Vanilla JavaScript.

SimpleNotification SimpleNotification is a library to display simple yet customizable notifications. You can stylize text with a simple syntax, add bu

null 14 Dec 11, 2022
Manage and monitorize your notification using only your terminal :3

Notifications Monitor Monitor your notifications and get a temporary list of the notifications. Dependencies Node.js (to run the program; by default,

Gabriel Guerra 3 Apr 12, 2022
Send slack notification with BQ results

bq2slack-github-action Send slack notification with BQ results. How to use Sample github actions workflow yaml name: Run SQL against BQ and notify sla

Data-i Consulting 4 Dec 16, 2022
Adds a notification to hydrate yourself!

Water Break This plugin simply puts a notification in the upper-left of the window. This will alert you to drink some water! Install ipm install water

Andrew Burke 6 Sep 24, 2022
Get a desktop notification every time a new correction slot is available for your 42 project.

42_slot_watcher A simple node.js corrections slots watcher for 42, working on Windows - MacOS - Linux. What is this I was bored of having to refresh t

Maxime 7 Dec 20, 2022
Simple, cli-first, mobile push notification across systems.

Notify.sh Simple, cli-first, mobile push notification across systems. Install In each folder, run npm install. The expected node version is 14. (Highe

David Alen 7 May 20, 2022