Code Monkey home page Code Monkey logo

react-notifier's Introduction

React Notifier

React component for notifications on the fron end.

Installation

$ npm i --save bc-react-notifier

How to use it

  1. Add the Notifier tag anywhere in your web app
import {Notifier} from 'bc-react-notifier';
ReactDOM.render(
    <Notifier />,
    document.querySelector('#root')
);
  1. Call the Notify function from anywhere in you code
import {Notify} from 'bc-react-notifier';

//Pass the error string or array, auto closes on 2 sec
Notify.error("Hey! There is an error");
//or successs string
Notify.success("Excelent! Everything went well");
//or info stirng
Notify.info("Everything is cool");

//you can also pass a confirmation callback to any of the notifications
Notify.error("Hey! Are you sure?", () => {
    //this functions runs on confirmation
});

Customize the notification with a custom component

  1. Create the component
    
    const ModalComponent = ({ onConfirm }) => 
        <div>
            <h1>Are you sure?</h1>
            <button onClick={()=>onConfirm(true)}>Yes</button>
            <button onClick={()=>onConfirm(false)}>No</button>
        </div>;
  1. Call the Notify function from anywhere else (passing the component)
    /**
     * @param1: Wrapper css class 
     * @param2: Component to render it
     * @param3: callback when answered
     * @param4: timeout in millisecons (null for no timout)
    **/
    let noti = Notify.add('info', ModalComponent, (answer)=>{
        
        console.log("The user answer is: ", answer);
        noti.remove();
        
    }, 9999999999999);

react-notifier's People

Contributors

alesanchezr avatar rafaelesaa avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rafaelesaa

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.