1.1.3-fix-readme • Published 2 years ago

@codebundlesbyvik/simple-notifier v1.1.3-fix-readme

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
2 years ago

Simple Notifier

npm

A lightweight and easy to use notification library.

Installation

npm install @codebundlesbyvik/simple-notifier

Basic usage

import SimpleNotifier from "@codebundlesbyvik/simple-notifier";


const notifier = new SimpleNotifier();

notifier.init();

// The following is inserted in the DOM.
// <div class="simple-notifier">
//     <p class="simple-notifier__message"></p>
// </div>


const message = "This is an example message.";
const type = "success";

notifier.show(message, type);

// Notification is shown for 3500 ms.

Methods

.init()

Initialize a SimpleNotifier instance.

A single instance shows at most a single notification. Should a message be passed to the instance whilst one is already being shown, the current one will be replaced by the new one.

.show(text, type)

Show a notification.

Parameters

ParameterTypeDefaultDescription
textStringSome dummy text.Text to show.
typeString"dummy" if text is undefined, else "default"Element's parent. Will be added as class (BEM modifier) to .simple-notifier.

.hide()

Hide the shown notification.

.destroy()

Doesn't exist yet.

Destroy a SimpleNotifier instance.

Options

Options should be passed in as an object on instance creation.

ParameterTypeDefaultDescription
autoHideNumber / Boolean3500Time in milliseconds after which .hide() will be called. true defaults to 3500, set to false or 0 to make the notification sticky.
parentElElementdocument.body.simple-notifier's parent element.
animationsString / Boolean"auto"Animation preference. "auto" checks user's device motion preference on each .show().

License

MIT © Viktor Chin-Kon-Sung