Socket
Book a DemoInstallSign in
Socket

notification-util

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notification-util

Very simple notification system for JS/TS projects.

1.0.8
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Notification util

Very simple notification system for JS/TS projects.

Installation

npm i notification-util

Configuration

Only has to be called once, before using the Notification or Loader class.

import {
  Notification,
  Loader,
  configureNotifications
} from 'notification-util';

configureNotification({}); // Required, but can be empty

Configuration options

You must run configureNotification before using the Notification or Loader class.

To run without customization, pass an empty object as argument.

You can override any of default settings by following the structure below.

Notifiation dissection

OptionDescription
containerSelectorSelector for notification container. Attribute, ID, class as string with # or . as needed
classesOverride the default CSS classes by providing your own
→ notificationClassCSS class as string, no prefixed .
→ headingWrapperClassCSS class as string, no prefixed .
→ iconClassCSS class as string, no prefixed .
→ messageClassCSS class as string, no prefixed .
→ headingClassCSS class as string, no prefixed .
iconsOverride the default icons by providing your own.
→ successstring injected as HTML
→ warningstring injected as HTML
→ errorstring injected as HTML
→ debugstring injected as HTML
→ loadingstring injected as HTML
injectCssboolean Inject default CSS. If disabling, be sure to provide your own animation CSS.

Defaults

configureNotification({
  containerSelector: '[sn-notification-container]',
  classes: {
    notificationClass: 'sn_notification',
    headingWrapperClass: 'sn_notification-heading-wrapper',
    iconClass: 'sn_notification-icon',
    messageClass: 'sn_notification-message',
    headingClass: 'sn_notification-heading'
  },
  icons: {
    success: icons.success,
    warning: icons.warning,
    error: icons.error,
    debug: icons.debug,
    loading: icons.loading
  },
  injectCss: false
});

Animation CSS provided

growWidth is used for showing duration of notification, rotation is used in loading icon.

@keyframes growWidth {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}
@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

Notification

Displays a notification with a heading and message. Can be closed by clicking on it when enabled.

Returns an object if you need to remove it programmatically. e.g.: myNotification.remove().

Options

new Notification({
  type: 'success' | 'warning' | 'error' | 'debug', // Required
  heading: string, // Required
  message: string,
  duration: number | null, // Default: 3500 (ms), null for infinite
  clickToClose: boolean // Default: true
});

Example usage

import { Notification, configureNotifications } from 'notification-util';

configureNotification({}); // Required, but can be empty

new Notification({
  type: 'success',
  heading: 'Success heading',
  message: 'Success message'
});

Loader

Displays a spinning loader with a heading and message. Returns an object with methods to update the loader and close it.

Options

new Loader({
  heading: string, // Required
  message: string
});

Example usage

import { Loader, configureNotifications } from 'notification-util';

configureNotification({}); // Required, but can be empty

const myLoaderMessage = new Loader({
  heading: 'Loader heading',
  message: 'Loader message'
});

// some time passes

myLoaderMessage.update({
  heading: 'Updated heading',
  message: 'Updated message'
});

// some time passes

myLoaderMessage.close();

FAQs

Package last updated on 24 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.