Code Monkey home page Code Monkey logo

x-notify's Introduction

X:/Notify (penpendede version)

This project is based on the original notification system by X:/Notify by Xtrendence but follows a slightly different approach. Instead of having just a single JavaScript file it uses JavaScript and less. The latter does almost all the styling. Both files together are even smaller than the original single file.

component(s) size (plain) size (minified)
CSS 1709 Bytes 1410 Bytes
JavaScript 3914 Bytes 2325 Bytes
all 5623 Bytes 3735 Bytes

As far as the interface is concerned there is one major change: Instead of success, error, alert, and info there only is display - the kind of output is controlled by the optional second parameter that defaults to 'info'. In addition to this the style options no longer exists - as far as notifications are concerned I prefer consistency over more freedom how they are displayed.

Installation

Important My version of X-Notify is intended to be used with a builder like esbuild. You can however still use it in the following manner provided that you remove the export default from the beginning of the code:

To add X-Notify to a web page, you need to include x-notify.js and x-notify.css (alternatively x-notify.min.js and x-notify.min.css), i.e. use

<script src="x-notify.js"></script>
<link rel="stylesheet" href="x-notify.css" type="text/css">

or similar.

Usage:

const Notify = new XNotify('TopLeft');
Notify.display({
  title: 'Title',
  description: 'Description',
  duration: 4000
},
'success');

The above would show a notification on the top right of the screen and it'd stay there for 4 seconds before disappearing. There are quite a few options you can change, such as:

Notify.display({
  title: 'Failed to Upload File',
  description: 'The file you submitted couldn't be uploaded.',
  duration: 4000
},
'error');

There are 4 different notification types: 'success', 'error', 'alert', and 'info', all of which can be used in the following manner:

Notify.display(options, 'success');
Notify.display(options, 'error');
Notify.display(options, 'alert');
Notify.display(options, 'info'); // alternatively just 'Notify.display(options)'

Here's a list of all the options you can use, and acceptable values:

Option Type Value Description
position String 'TopRight', 'BottomRight', 'BottomLeft', 'TopLeft' Where the notification popup would appear (this is passed to the constructor).
title String Usually, some short text. The title of the notification; something like 'Upload Error', or 'Form Submitted'.
description String A longer description of the event. A description of the event the notification was shown for.
duration Integer Any integer. The duration, in milliseconds, that the notification would stay on screen for.

A full example with a button click event listener, and a fully custom notification:

document.addEventListener('DOMContentLoaded', () => {
  const Notify = new XNotify();

  let custom = document.getElementById('custom');

  custom.addEventListener('click', () => {
    Notify.display({
      title: 'Customized Notification',
      description: 'Description of the notification.',
      duration: 10000
    },
    'info');
  });
});

x-notify's People

Contributors

penpendede avatar xtrendence avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.