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

@reflect/react-notification

v5.0.3

Published

Snackbar style notification component for React.

Downloads

4

Readme

react-notification

npm version Dependency Status Build Status npm downloads

Overview

This is a component designed to provide "snackbar" notification messages and notification stacks (similar to how notifications stack on OS X). I would suggest reading the usage guidelines for snackbars.

Getting Started

Install the component via npm: npm install react-notification.

If you are using the React 0.13.x or lower, you can install the previously compatible version of this component with npm i [email protected] -S. The current version only works with React 0.14.x.

Please read the contributing guide if you are interested in contributing. If you are coming from version 1.0.0, there is an upgrade guide to help you make the switch. If you have questions, please feel free to create an issue on GitHub.

Usage

Single notification:

import { Notification } from 'react-notification';

<Notification
  isActive={boolean}
  message={string}
  action={string}
  onClick={myClickHander}
/>

Notification stack:

import { NotificationStack } from 'react-notification';
import { OrderedSet } from 'immutable';

constructor () {
  super();
  this.state = {
    notifications: OrderedSet()
  };
}

addNotification () {
  const newCount = count + 1;
  return this.setState({
    notifications: this.state.notifications.add({
      message: `Notification ipsum...`,
      key: 'some UID',
      action: 'Dismiss',
      onClick: () => this.removeNotification('some UID'),
    })
  });
}

removeNotification (count) {
  this.setState({
    notifications: this.state.notifications.filter(n => n.key !== count)
  })
}

render () {
  return (
    <NotificationStack
      notifications={this.state.notifications.toArray()}
      onDismiss={notification => this.setState({
        notifications: this.state.notifications.delete(notification)
      })}
    />
  );
}

See the examples for more context on how to use a notification stack.

Props

For Notification component:

| Name | Type | Description | Required | Default | |-----------------|-------------------------|-------------------------------------------------------------|-----------|----------------------------| | isActive | boolean | If true, the notification is visible | true | false | | message | string or React element | The message or component for the notification | true | | | title | string | The title for the notification | | | | action | string | The name of the action, e.g., "close" or "undo" | | | | style | boolean | Setting this prop to false will disable all inline styles | | | | barStyle | object | Custom snackbar styles | | | | activeBarStyle | object | Custom snackbar styles when the bar is active | | | | actionStyle | object | Custom action styles | | | | className | string | Custom class to apply to the top-level component | | | | activeClassName | string | Custom class to apply to the top-level component when active| | 'notification-bar-active'| | dismissAfter | number or false | Timeout for onDismiss event | | 2000 |

The style prop useful if you are not using React inline styles and would like to use CSS instead. See styles for more.

For NotificationStack component:

| Name | Type | Description | Required | Default | |----------------|-------|----------------------------------------------|---------- |----------| | notifications | array | Array of notifications to render | true | |

Update v5.0.3: Now notifications used in a stack can have all properties included in the regular notification component.

Events

For Notification component:

| Event | Description | |-----------|------------------------------------------------------------| | onClick | Callback function to run when the action is clicked | | onDismiss | Callback function to run when dismissAfter timer runs out |

For NotificationStack component:

| Event | Description | Arguments | |-----------|------------------------------------------------------------------------------|-----------------------------------------------------------| | onDismiss | Callback function to run when dismissAfter timer runs out for a notification | The object for the notification currently being dismissed |

Styles

This component does use basic inline CSS to style the position and visibility of the notification. You have two options for adding additional styles:

  1. Remove all inline styles and use only CSS.
  2. Add additional inline styles via the style prop.

The DOM tree of the component for reference:

<div class="notification-bar">
  <div class="notification-bar-wrapper" onClick={this.props.onClick}>
    <span class="notification-bar-message">{this.props.message}</span>
    <span class="notification-bar-action">{this.props.action}</span>
  </div>
</div>

To use additional inline styles, return two objects. The bar object applies styles to the entire notification "snackbar" and the action object applies styles to the action message. Under the hood, this uses Object.assign to handle properly combining styles.

I would highly suggest using this method since the styles included in the component by default handle the visibility of the notification. If you remove these styles, the component won't actually show or hide itself.


Built with care in New Orleans by Patrick Burtchaell.

Copyright 2016 Patrick Burtchaell. Licensed MIT. Gratipay.