react-notie

Simple notifications for react

NPM version Build Status Dependency Status Dev Dependency Status

React Notie

Simple notification for React.

Inspired from notie by @jaredreich

Table of Contents

Installation

Using npm

npm install --save react-notie

Using yarn

yarn add react-notie

Browser Support

  • Edge >= 12
  • FireFox >= 38
  • Chrome >= 47
  • Opera >= 34
  • Safari >= 9

Note: For other browsers like Safari < 9 and IE 11, you need to polyfill Object.assign and Promise.

Usage

  1. Render root of your app within <NotieProvider />.
  2. use withNotie decorator/hoc with the component where you want to notie.
  3. include react-notie/css/notie.css.
// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { NotieProvider } from 'react-notie';

const App = (
    <NotieProvider>
        <MyApp/>
    </NotieProvider>
)

ReactDOM.render(App, document.getElementById('root'));

// MyComponent.js
import React, { Component } from 'react';
import { withNotie } from 'react-notie';

class MyComponent extends Component {
    someAsyncAction = () => {
        fetch('/do-something').then(() => {
            this.props.notie.success('Thing Done!')
        });
    }

    render() {
        return (
            ......
        )
    }
}

export default withNotie(MyComponent);

API

The following methods are availble on notie prop.

alert(props: Object)

Show an alert message.

props.message: String

The message to be shown

props.level: String

The type of alert-box to shown.

Must be one of:

  • SUCCESS
  • WARN
  • INFO
  • ERROR
  • CONFIRM

props.ttl: Number

The time (in ms) after which the alert-box disappears. Default is 5000 ms.

success(message: String[, ttl: Number])

Convenience method for showing message with level set to SUCCESS

message: String

The message to be shown

ttl: Number

The time (in ms) after which the alert-box disappears. Default is 5000 ms.

warn(message: String[, ttl: Number])

Convenience method for showing message with level set to WARN

message: String

The message to be shown

ttl: Number

The time (in ms) after which the alert-box disappears. Default is 5000 ms.

error(message: String[, ttl: Number])

Convenience method for showing message with level set to ERROR

message: String

The message to be shown

ttl: Number

The time (in ms) after which the alert-box disappears. Default is 5000 ms.

info(message: String[, ttl: Number])

Convenience method for showing message with level set to INFO

message: String

The message to be shown

ttl: Number

The time (in ms) after which the alert-box disappears. Default is 5000 ms.

confirm(message: String[, settings: Object]): Promise

Show a confirmation message with Yes/No options. It returns a Promise, which will be resolved if ‘Yes’ is selected and will be rejected if ‘No’ is selected.

message: String

The message to be shown

settings.yesBtnText: String

Text to be shown for ‘Yes’ button. Default is ‘Yes’.

settings.noBtnText: String

Text to be shown for ‘No’ button. Default is ‘No’.

Advanced Usage

coming soon

Contributors

All Contributors

Changelog

For Changelog, see releases

License

MIT. Copyright© Vivek Kumar Bansal

Related Repositories

react-notie

react-notie

Simple notifications for react ...