Lightweight and simple notification library in Vanilla JavaScript.

Overview

SimpleNotification

SimpleNotification is a library to display simple yet customizable notifications. You can stylize text with a simple syntax, add buttons to make the notifications interactable and add callbacks for some events during the life of a notification.

SimpleNotification weighs 11.12 Kb (3.57 Kb gzipped), with no dependencies.

You can find a live demo here: https://notification.nikurasu.org/

Installation

You simply need to include simpleNotification.css, simpleNotification.js (or the minified versions) and you're ready to go!

How to use

SimpleNotification has static methods to display notifications with 5 default templates. You can call each of the templates by their name directly on SimpleNotification without instantiating it, like so: SimpleNotification.success(...).

The five templates are success, error, info, warning and message.

SimpleNotification.success({
    title: 'Title', // The title of the notification
    image: 'url', // Optional image displayed inside the notification
    text: 'Content', // Content of the notification
    // Optional list of buttons to interact with the notification
    buttons: [{
        value: 'Confirm', // The text inside the button
        type: 'success', // The type of the button, same as for the notifications
        onClick: (notification) => {
            // The onClick function receive the notification from which the button has been clicked
            // You can call notification.remove(), notification.close() or notification.closeFadeout()
            // if you wish to remove the notification by clicking on  the buttons
        }
    }]
}, options);

All keys in the first parameter are optional, but at least one is required.

You can still update the content and state of any notification after it's been created with these functions:

setType(type), setTitle(title), setImage(image), setText(text), addButton(button), removeButtons(), disableButtons()

You can use custom classes and make your own design by using SimpleNotification.custom(classes, content, options) where classes is an array of CSS classes that will be added to the body of each notification.

You can jump lines inside the notification content by using any linebreak character (\r, \n or \r\n).

Options

There are a few options that you can set by using SimpleNotification.options(object) or more specifically for a single notification on the third parameter.

Name Description Default
duration The time (in ms) that the notification is displayed. 4000
position Valid positions: top-left, top-center, top-right, bottom-left, bottom-center and bottom-right. "top-right"
sticky If true, the notification will not disappear until the user clicks it or its close button. false
closeButton If true, a close button will be added either on the title or the content. true
closeOnClick If true, clicking anywhere in the notification will close it. true
removeAllOnDisplay If true, all notifications will be cleared before the new one is added to the screen. false
maxNotifications If >0, notifications (starting with oldest) will clear out until the number displayed is less than or equal to the specified option. 0
events Object with events functions, see Events.
insertAnimation Object with CSS class name and duration, see Animations. { name: 'default-insert', duration: 250 }
removeAnimation Object with CSS class name and duration, see Animations. { name: 'fadeout', duration: 400 }
display Display the notification when creating it. true

If a notification is sticky and closeOnClick is disabled, closeButton is set to true to always have a way to close a notification.

Events

There are four events during the process of displaying every notification:

  • onCreate(notification) called when the notification node is created but empty.
  • onDisplay(notification) called when the notification node is appended to its wrapper.
  • onDeath(notification) called when the duration timer has expired.
    • If you set the onDeath function you need to call notification.close(), notification.remove() or notification.closeFadeout() or else the notification won't disappear.
  • onDisplay(notification) after the notification has been closed.

Animations

You can customize the insert and remove animations of a notification by giving a value to the insertAnimation (or removeAnimation) option. The option take an object like the following:

{
    name: "default-insert", // See the list below
    duration: 250 // In ms
}

The insert animations are: insert-[left|top|right|bottom], fadein, scalein and rotatein.

By default the animation is default-insert which is a special value that automatically choose the corresponding insert animation after the notification position.

The remove animations are: fadeout, scaleout and rotateout.

You can add your own animations by adding them in your own CSS files and setting the name of the animation as the parameter.

Markdown-like tags

You can insert links, images and stylize text by using tags that resemble Markdown. Most of these tags can be nested to combine their effects.

Name Description
Inline code ``code``
Header (h1) # Header 1\n
Header (h2) ## Header 2\n
Link {{title|http://www.example.org/}} or {{http://www.example.org/}} without title.
Image ![title|http://www.example.org/image.jpg] or ![http://www.example.org/image.jpg] without title.
Bold **http://www.example.org/**
Italic *http://www.example.org/*
Separator \n---\n
Float right >*>Text<

Tags work by looking for an open token, an optional separator if there is a title, and the close token.
If the tag can have a title you need to use | as the separator with the content.

You can add custom tags easily by adding them to SimpleNotification.tags or by using SimpleNotification.addTag(name, object).
A tag object can have the following properties:

{
    type: 'span', // The node type, e.g <span>
    class: ['class1', 'class2'], // Optional class list as an array or string to use
    attributes: {
        name: value
    }, // Optional attributes to set
    textContent: "$content", // textContent of the created node, see below for variables
                             // If textContent is defined and not false the content cannot have childs (nested other tags)
    title: false, // See "Title" below
    open: '{{', // The opening token - any length
    close: '}}' // The closing token - can be linebreak by using \n - can also be empty
}

Variables

There are two usable variables inside attribute values textContent and title:

  • $content: the content found between the open and close token, without the title if there is one.
  • $title: the title found, if there is none it is replaced by the same value as $content.
Comments
  • More Mask

    More Mask

    Hi, @Glagan Notification is very nice and light

    There is no Mask Add Mask option

    • Add a background Mask : option

    • text: 'Content', is it possible to add comprehensive Html? For example: Content.html or Div.

    opened by anhdoantm 5
  • Issue with new notification style

    Issue with new notification style

    Before the notifications would get pretty wide to show my message in a clean manner, like this:

    old

    But now they only get so wide then stop, leaving the messages extremely unattractive:

    new

    I don't know what changed and I have been unable to pinpoint the issue myself, so I'm going to stick with using my unsupported hacky method until this is resolved. I can upload my entire old CSS if that will help you, but I'm leaving tomorrow so I won't be able to be much help fixing it.

    opened by ajmeese7 5
  • Feature request: detect if a notification already exists

    Feature request: detect if a notification already exists

    It would be a really useful feature if when a new notification is opened there was an option to detect if one is already present and to decide what action to take if there is. For example, you could choose to still show the new notification (default) or to close the old one as as it closes bring in the new notification.

    Currently in my project if a user clicks buttons too quickly they will have more than one notification show at once and it is not attractive with how they are styled in my app. If you do not plan on working on this I will see if I can brew up my own solution in a few months when I have time.

    enhancement 
    opened by ajmeese7 4
  • Feature request: opening and closing animation options

    Feature request: opening and closing animation options

    It would be neat if there could be things like sliding in from the right, left, top, and bottom for opening then sliding out for closing. Basically something like this but with options instead of the one preset method.

    It could be implemented with an openingAnimation and closingAnimation option, with things like slideInLeft and possibly an option for timings, making it an object parameter like openingAnimation= { animation: "slideInLeft", time: 400 } with a default amount like 400. The default could be fadeIn for openingAnimation and fadeOut for closingAnimation.

    I have already implemented a small version of this in my project, where I replaced the code of @keyframes insert-right with the following to make it actually insert from the bottom:

    from {
        transform: rotateX(-70deg);
        transform-origin: bottom;
    }
    to {
        transform: rotateX(0deg);
        transform-origin: bottom;
    }
    

    If there was official support for this, it would make customization much easier. This actually ties in with my next issue I will create. Don't hesitate to clarify any confusions, I know this is a lot in one issue.

    enhancement 
    opened by ajmeese7 3
  • Documentation for #3

    Documentation for #3

    Added the new options to the table. You should probably also make a new release so people can download the minified version easily and you should update the file size in the README to reflect the changes.

    Thanks for implementing these features! If you don't mind, I'm going to make another few issues with feature requests since soon I won't have access to a computer for a few months because I'm leaving for the Army. There's no rush to implement them, I just want to give you some ideas of how people use the library and what might attract more users. I know I'm liking it a lot more than the alternatives, and hopefully others will see what I do soon as the feature set grows. Cheers!

    opened by ajmeese7 2
  • Bump terser from 5.6.1 to 5.14.2

    Bump terser from 5.6.1 to 5.14.2

    Bumps terser from 5.6.1 to 5.14.2.

    Changelog

    Sourced from terser's changelog.

    v5.14.2

    • Security fix for RegExps that should not be evaluated (regexp DDOS)
    • Source maps improvements (#1211)
    • Performance improvements in long property access evaluation (#1213)

    v5.14.1

    • keep_numbers option added to TypeScript defs (#1208)
    • Fixed parsing of nested template strings (#1204)

    v5.14.0

    • Switched to @​jridgewell/source-map for sourcemap generation (#1190, #1181)
    • Fixed source maps with non-terminated segments (#1106)
    • Enabled typescript types to be imported from the package (#1194)
    • Extra DOM props have been added (#1191)
    • Delete the AST while generating code, as a means to save RAM

    v5.13.1

    • Removed self-assignments (varname=varname) (closes #1081)
    • Separated inlining code (for inlining things into references, or removing IIFEs)
    • Allow multiple identifiers with the same name in var destructuring (eg var { a, a } = x) (#1176)

    v5.13.0

    • All calls to eval() were removed (#1171, #1184)
    • source-map was updated to 0.8.0-beta.0 (#1164)
    • NavigatorUAData was added to domprops to avoid property mangling (#1166)

    v5.12.1

    • Fixed an issue with function definitions inside blocks (#1155)
    • Fixed parens of new in some situations (closes #1159)

    v5.12.0

    • TERSER_DEBUG_DIR environment variable
    • @​copyright comments are now preserved with the comments="some" option (#1153)

    v5.11.0

    • Unicode code point escapes (\u{abcde}) are not emitted inside RegExp literals anymore (#1147)
    • acorn is now a regular dependency

    v5.10.0

    • Massive optimization to max_line_len (#1109)
    • Basic support for import assertions
    • Marked ES2022 Object.hasOwn as a pure function
    • Fix delete optional?.property
    • New CI/CD pipeline with github actions (#1057)

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Feature request: more notification location options

    Feature request: more notification location options

    Right now I have my notifications displayed in the center of the bottom of my page, which wasn't that hard to customize myself, but it would be cool if there was a way to specify location: "bottomCenter" as an option or something similar. This is my current hacked way of getting it to display how I want:

    .gn-wrapper {
        position: absolute;
        bottom: 0;
        width: 100%;
        overflow: hidden;
        pointer-events: none;
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        z-index: 1080;
    }
    

    Depending on the layout of the page, displaying in the center from the top or the bottom might be very visually attractive. This is what a notification looks like in my application:

    Coming from the bottom and being centered makes it best for my use case.

    enhancement 
    opened by ajmeese7 1
Releases(v1.3.1)
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
Notification handler. KISS, light and library free.

Notification.js Notification.js is a standalone ES6 module that allows you to easily handle several notifications from different types at the same tim

Arthur Beaulieu 2 Nov 25, 2020
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
EggyJS is a Javascript micro Library for simple, lightweight toast popups focused on being dependency-less, lightweight, quick and efficient.

EggyJS EggyJS is a Javascript micro Library for simple, lightweight toast popups. The goal of this library was to create something that meets the foll

Sam 10 Jan 8, 2023
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.

Fabien Doiron 4.3k Dec 22, 2022
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

What is it ? Shaders are the new front-end web developpment big thing, with the ability to create very powerful 3D interactions and animations. A lot

Martin Laxenaire 1.4k Jan 1, 2023
A lightweight scrollbar library written in vanilla javascript.

A lightweight, dependency-free scrollbar library written in vanilla javascript. Fully customisable via CSS Native scrolling behaviour preserved Vertic

Karl 56 Dec 4, 2022
A lightweight vanilla JavaScript context menu library with FontAwesome support.

Contextify A lightweight vanilla JavaScript context menu library with FontAwesome support. This library was written for use in a personal project of m

Jacob Hampton 2 Jun 1, 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
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

Webarion 2 Nov 7, 2021
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

null 59 Dec 11, 2022
Lightweight and easy to use vanilla js library to add css animations to elements on scroll.

Scrollrisen Trigger css animations on scroll as elements enter the viewport. Zero dependencies, lightweight and easy to use and customize Installation

null 1 Oct 13, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
A small, lightweight JavaScript plugin for placing items in straight rows (jQuery and vanilla JS version) – Demo:

rowGrid.js rowGrid.js is a small, lightweight (~1000 bytes gzipped) jQuery plugin for placing images (or other items) in straight rows. The grid is si

Bruno Joseph 669 Jul 22, 2022
Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.

loading="lazy" attribute polyfill Fast and lightweight vanilla JavaScript polyfill for native lazy loading, meaning the behaviour to load elements rig

Maximilian Franzke 571 Dec 30, 2022