Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-notification

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-notification

Snackbar style notification component for React.

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
increased by1.94%
Maintainers
1
Weekly downloads
 
Created
Source

react-notification npm version Dependency Status

Overview

NOTICE: If you are using the React 0.14.0 beta, you can install the compatible version of this component with npm i react-notification@2.2.0-beta -S.

This is a component designed to provide "snackbar" notification messages. I would suggest reading the usage guidelines for snackbars.

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 or message me (@pburtchaell) on the Reactiflux Slack community.

Getting Started

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

Usage

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

Props

NameTypeDescriptionRequiredDefault
isActivebooleanIf true, the notification is visibletruefalse
messagestringThe message for the notificationtrue
actionstringThe name of the action, e.g., "close" or "undo"true
styleobject or booleanCustom styles to apply to the component*
dismissAfternumberTimeout for onDismiss event2000

*Setting this prop to false will disable all inline styles. This is useful if you aren't using React inline styles and would like to use CSS instead. See styles for more.

Events

EventDescription
onClickCallback function to run when the action is clicked
onDismissCallback function to run when dismissAfter timer runs out

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.

getNotificationStyles() {
  let bar = {
    background: '#263238'
  };

  let active = {
    left: '3rem'
  };

  let action = {
    color: '#FFCCBC'
  };

  return { bar, active, action };
},

render() {
  return (
    <div>
      <Notification
        ref="notification"
        message={this.state.message}
        action={this.state.action}
        styles={this.getNotificationStyles()}
      />
    </div>
  );
}

Built with care in New Orleans by Patrick Burtchaell.

Copyright 2015 Patrick Burtchaell. Licensed MIT.

Keywords

FAQs

Package last updated on 04 Sep 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc