GithubHelp home page GithubHelp logo

hardevgun17 / react-notifications-component Goto Github PK

View Code? Open in Web Editor NEW

This project forked from teodosii/react-notifications-component

0.0 1.0 0.0 4.32 MB

Highly customisable React component to show UI notifications

Home Page: https://teodosii.github.io/react-notifications-component/

License: MIT License

JavaScript 95.71% CSS 4.29%

react-notifications-component's Introduction

npm version npm Build Status Coverage Status Dependency Status Minified & Gzipped size License

react-notifications-component

Highly configurable and easy to use React component to notify your users!

Demo

https://teodosii.github.io/react-notifications-component/

alt text

Features

Touch support
Responsive notifications
Standard notification types
(default, success, info, danger, warning)
Custom notification types
Custom notification content
(images, icons etc)
Dismiss after timeout
Dismissable by swiping
Dismissable by clicking
Dismissable by custom × icon
Custom animations on show
Custom animations on exit
Custom transitions on sliding
Custom transitions on swiping
Notification insertion at both ends of container

Install

npm install react-notifications-component

Usage

You must place ReactNotificationsComponent component at the root level of the application in order to work properly, otherwise it might conflict with other DOM elements due to the positioning.

Use ref syntax when declaring ReactNotificationsComponent in order to have access to internal method addNotification. All API methods provided must be called like this.

For further information on supported options, check documentation.

import React from "react";
import ReactNotification from "react-notifications-component";
import "react-notifications-component/dist/theme.css";

class App extends React.Component {
  constructor(props) {
    super(props);
    this.addNotification = this.addNotification.bind(this);
    this.notificationDOMRef = React.createRef();
  }

  addNotification() {
    this.notificationDOMRef.current.addNotification({
      title: "Awesomeness",
      message: "Awesome Notifications!",
      type: "success",
      insert: "top",
      container: "top-right",
      animationIn: ["animated", "fadeIn"],
      animationOut: ["animated", "fadeOut"],
      dismiss: { duration: 2000 },
      dismissable: { click: true }
    });
  }

  render() {
    return (
      <div className="app-content">
        <ReactNotification ref={this.notificationDOMRef} />
        <button onClick={this.addNotification} className="btn btn-primary">
          Add Awesome Notification
        </button>
      </div>
    );
  }
}

Note: It is important to import react-notifications-component CSS theme, which is located in dist/theme.css

Development

First build the library

npm run build:library:dev

then run the webpack server to see the app running

npm run start

Test

npm run test

API

addNotification(options)

Render a new notification. Method returns a unique ID representing the rendered notification. Supplied options are internally validated and an exception will be thrown if validation fails.

removeNotification(id)

Manually remove a notification by ID. Nothing will happen if notification does not exist.

Examples

View examples here and here

Options

There are 2 types of options. In order to configure the root component - <ReactNotificationComponent /> - you need to set props to be used as options

Name Type Description
isMobile Boolean Set whether you want component to be responsive or not
breakpoint Number Breakpoint for showing mobile notifications, it defaults to 768 (px). If window width is smaller than set number, then the responsive containers will be shown - top and bottom
types Object User defined types - see examples on GitHub pages
onNotificationRemoval Function Callback function to be called when notification has been removed. Function is called with id and removedBy as parameters. removedBy parameter takes one of the following values
  • 1 - timeout
  • 2 - click
  • 3 - touch
  • 4 - API call

In order to configure the notification itself you need to use the following properties when calling addNotification

Name Type Description
id String Id of the notification. Option is not required and should be used only if you want to have custom id over random id that is generated internally
title String Title of the notification. Option is ignored if content is set
message String Message of the notification. Option is ignored if content is set, otherwise it is required
content React.Component Custom notification content, must be a valid React component
type String Type of the notification (success, danger, default, info, warning or custom). Option is ignored if content is set, otherwise it is required
container String Container in which the notification will be displayed (top-left, top-right, bottom-left, bottom-right). Option is required
insert String Insert notification at the top or at the bottom of the container. Option defaults to top
userDefinedTypes Array Define allowed types when rendering custom types
  • htmlClasses - Array - CSS classes to be applied to the notification element
  • name - String - name of the custom type
dismissable Object Specify how a notification should be manually dismissed
  • click - Boolean - dismiss by clicking (option defaults to true)
  • touch - Boolean - dismiss by swiping on mobile devices (option defaults to true)
dismissIcon Object Custom X icon
  • className - Array - CSS classes to be applied to icon's parent
  • content - React.Component - must be a valid React component
animationIn Array CSS classes used to animate notification on show
animationOut Array CSS classes used to animate notification on removal
slidingEnter Object Transition to be used when sliding to show a notification
  • duration - Number (ms)
  • cubicBezier - String
  • delay - Number (ms)
slidingExit Object Transition to be used when sliding to hide a notification
  • duration - Number (ms)
  • cubicBezier - String
  • delay - Number (ms)
touchSlidingBack Object Transition to be used when sliding back after an incomplete swipe
  • duration - Number (ms)
  • cubicBezier - String
  • delay - Number (ms)
touchSlidingExit Object Transition to be used when sliding on swipe
  • duration - Number (ms)
  • cubicBezier - String
  • delay - Number (ms)
dismiss Object Automatically dismiss a notification after specified timeout
  • duration - Number (ms - 0 means Infinite)
width Number Overwrite notification's width defined by stylesheets

react-notifications-component's People

Contributors

saravmajestic avatar teodosii avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.