Code Monkey home page Code Monkey logo

react-notifications's Introduction

React Notifications

Installation

npm install --save react-notifications

Usage

Note

Use only one 'NotificationContainer' component in the app.

CSS

Webpack:

import 'react-notifications/lib/notifications.css';

Other

<link rel="stylesheet" type="text/css" href="path/to/notifications.css">

JS

import React from 'react';
import { NotificationContainer, NotificationManager } from '../../../../dist/react-notifications';

class Example extends React.Component {
    createNotification = (type) => () => {
        switch (type) {
            case 'info':
                NotificationManager.info('Info message');
                break;
            case 'success':
                NotificationManager.success('Success message', 'Title here');
                break;
            case 'warning':
                NotificationManager.warning('Warning message', 'Close after 3000ms', 3000);
                break;
            case 'error':
                NotificationManager.error('Error message', 'Click me!', 5000, () => {
                    alert('callback');
                });
                break;
            case 'tag':
                NotificationManager.error('With tag', 'With tag', 10000, undefined, false, 'tag');
                break;
            default:
                break;
        }
    };

    removeByTag = () => {
        NotificationManager.removeByTag('tag');
    };

    render() {
        return (
            <div>
                <div className="page-header">
                    <h1>Simple sample</h1>
                </div>
                <button type="button" className="btn btn-info" onClick={this.createNotification('info')}>
                    Info
                </button>
                <hr/>
                <button type="button" className="btn btn-success" onClick={this.createNotification('success')}>
                    Success
                </button>
                <hr/>
                <button type="button" className="btn btn-warning" onClick={this.createNotification('warning')}>
                    Warning
                </button>
                <hr/>
                <button type="button" className="btn btn-danger" onClick={this.createNotification('error')}>
                    Error
                </button>
                <hr/>
                <button type="button" className="btn btn-default" onClick={this.createNotification('tag')}>
                    Tag
                </button>
                <hr/>
                <button type="button" className="btn btn-default" onClick={this.removeByTag}>
                    Clear all with tag
                </button>

                <NotificationContainer/>
            </div>
        );
    }
}

export default Example;

UMD

<link rel="stylesheet" type="text/css" href="path/to/react-notifications/dist/react-notifications.css">
<script src="path/to/react-notifications/dist/react-notifications.js"></script>
const NotificationContainer = window.ReactNotifications.NotificationContainer;
const NotificationManager = window.ReactNotifications.NotificationManager;

NotificationContainer Props

Name Type Default Required
enterTimeout number 400 false
leaveTimeout number 400 false

NotificationManager API

  • NotificationManager.info(message, title, timeOut, callback, priority, tag);
  • NotificationManager.success(message, title, timeOut, callback, priority, tag);
  • NotificationManager.warning(message, title, timeOut, callback, priority, tag);
  • NotificationManager.error(message, title, timeOut, callback, priority, tag);
Name Type Description
message string The message string
title string The title string
timeOut integer The popup timeout in milliseconds
callback function A function that gets fired when the popup is clicked
priority boolean If true, the message gets inserted at the top
tag string or array of strings The notification tags

Example

View demo or example folder.

Contributing

When contributing to this reposity, please first open an issue and discuss intended changes with maintainers. If there is already an issue open for the feature you are looking to develop, please just coordinate with maintainers before assigning issue to yourself.

Branches

master is the main branch from which we publish packages. next is the branch from which we will publish the next release. All issue branches should be branched from master, unless specifically told by the maintainers to use a different branch. All pull requests should be submitted to merge with next in order to make the next release.

Workflow

  • Fork repo
  • Create an issue branch
  • Commit your changes
  • Open a PR against next.
  • Link the Issue to your PR.

Pull Request Guidelines

  • PRs should be submitted to merge with next.
  • PRs should be small in scope, work on 1 issue in a single PR.
  • Link the Issue you are working to your PR.

You can add as many commits to your PR as you would like. All commits will be squashed into a single commit when merging PR.

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.