npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notify-rc

v1.0.2

Published

A simple library for displaying notifications to a user.

Downloads

5

Readme

notify-rc

npm version Build Status codecov MIT license

notify-rc is a small package which allows developers to easily display notifications to the users.

Usage

The package is hosted on npm and can be installed within your repository using the following command:

npm install --save notify-rc

The notification system makes use of the React Context API to allow for any component within the tree to easily display notifications at any level of the render tree.

The package surfaces the context provider and a custom hook which provides some helper functions to display Info, Success, Warning and Error notifications whilst abstracting away the Context API.

At the root of you application, import the NotifierProvider and wrap your 'App' with it.

...
import { NotifierProvider } from 'notify-rc'

function Root() {
	return (
		<NotifierProvider>
			<App />
		</NotifierProvider>
	);
}
...

This will setup the notifier context and give every component within the provider access to it.

You can then import the custom notifier hook in any of your functional components and use it. This will provide access to four helpers functions allowing you to display the different kinds of notifications.

...
import {useNotifier} from 'notify-rc'

const Component = ()=> {
    const {
	    showSuccessNotification,
	    showInfoNotification,
	    showWarningNotification,
	    showErrorNotification
    } =  useNotifier();

    return (
	    <div>
		    <button onClick={() => showSuccessNotification('Success')}>Success</button>
		    <button onClick={() => showInfoNotification('Info Banner')}>Info</button>
		    <button onClick={() => showWarningNotification('Warning')}>Warning</button>
		    <button onClick={() => showErrorNotification('Error')}>Error</button>
	    </div>
    );
};
...

Options

In addition to the message, the helper functions provided by the custom hook allow for an object of options to be passed.

These options allow you to set the positioning or add on a timer to the notification.

Positioning

The Notification system supports the following positions:

  • Top
  • Bottom
  • TopLeft
  • TopRight
  • BottomLeft
  • BottomRight
  • Centre

Top and Bottom are rendered as 'Banners' which span across the full width of the screen.

TopLeft, TopRight, BottomLeft, BottomRight are rendered as 'Toastrs' with a fixed width.

Centre is rendered as an overlay in the centre of the screen with a fixed width.

By default if no position is provided the notification will be displayed on the Top as a banner.

Timed Notifications

The notification supports a timed mode, whereby the notification will close automatically after the elapsed time has passed.

This mode is optional and can be activated by simply passing the number of seconds you want the notification to display for in the options parameter of the custom hook functions.

Future Work

  • Add support for class components.
  • Add theming capabilities.
  • Add ability to default options at an app Level.
  • Enhance styles and add optional animations.