GithubHelp home page GithubHelp logo

kathgironpe / re-notif Goto Github PK

View Code? Open in Web Editor NEW

This project forked from indexiatech/re-notif

0.0 1.0 0.0 572 KB

Redux & React based Notifications center.

Home Page: http://indexiatech.github.io/re-notif

License: BSD 3-Clause "New" or "Revised" License

CSS 6.51% HTML 5.55% JavaScript 87.95%

re-notif's Introduction

redux-notifications

โš ๏ธ The previous package re-notif has been deprecated on NPM and renamed to redux-notifications. A list of changes can be found in the Changelog. Please update your applications accordingly.

React & Redux based notifications center.

Thanks to Redux, the notification objects are maintained within Redux Store's State and are fired by Actions.

Implementation

1. Installation

npm install --save redux-notifications

2. The next thing you need to do is to add the re-notif reducer to Redux.
import { createStore, combineReducers } from 'redux'
import { reducer as notifReducer } from 're-notif';
combineReducers({
  notifs: notifReducer,
  // ... more reducers here ...
})
3. Add the Notifs component at the root of your app
import { Provider }  from 'react-redux'
import { Notifs } from 're-notif';

<Provider store={store}>
  <div>
    // ... other things like router ...
    <Notifs />
  </div>
</Provider>

Sending notifications

Thanks to Redux, sending notification is simply done by firing an Action:

import { reducer as notifReducer, actions as notifActions, Notifs } from 're-notif';
const { notifSend } = notifActions;

class Demo extends React.Component {
  send() {
    this.props.dispatch(notifSend({
      message: 'hello world',
      kind: 'info',
      dismissAfter: 2000
    }));
  }

  render() {
    <button onClick={this.send}>Send Notification</button>
  }
}

Demo

Watch the demo or checkout its source code

API

Actions

actions.notifSend({config})

config.message : string [required]

The notification message.

config.componentClassName : string [optional] [default:'notif']

The base className for the Notif component. Can be used to override CSS styles.

config.kind : string [optional] [default:'info']

The notification kind, can be one of: info, success, warning, danger.

config.id : string [optional] [default:Date.now()]

Set an ID for the notification. If not set, defaults to Date.now().

config.dismissAfter : integer [optional] [default:null]

Auto dismiss the notification after the given number of milliseconds.

config.transitionEnterTimeout : integer [optional] [default:600]

Define the react-transition-group enter timeout is milliseconds.

config.transitionLeaveTimeout : integer [optional] [default:600]

Define the react-transition-group leave timeout is milliseconds.

actions.notifClear()

Clear all current notifications.

actions.notifDismiss(id)

Dismiss a notification by ID


Custom Component

<Notifs CustomComponent={ReactComponent}/>

CustomComponent : React component

A custom react component can be used instead of the default Notif component

id : string || number

The notification's unique ID

message : string

The notification's message

actionLabel : string

Label for action click

onActionClick : func

Function when action is clicked. Requires actionLabel prop

Development

git clone https://github.com/indexiatech/re-notif.git
cd re-notif
npm install
npm run start

Listening on localhost:3000

re-notif's People

Contributors

kylecesmat avatar asaf avatar steplerbox avatar namefilip avatar kathgironpe avatar

Watchers

James Cloos 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.