react-redux-notifier
React-redux-notifier helps you show your own notification and customize them.
Installation
To install the stable version:
npm install --save react-redux-notifier
Add notifier to your project.
Add add Reducer to combineReducers function:
;; notifier: Reducer
Add Notifications to Component:
;; { return <Notifications nKey="some.key" /> ; }
Create and delete Notifications.
There are four kinds of notifications:
- NOTIFICATION_INFO
- NOTIFICATION_SUCCESS
- NOTIFICATION_WARNING
- NOTIFICATION_ERROR
And actions for create them:
- ADD_INFO(key, message, options)
- ADD_SUCCESS(key, message, options)
- ADD_WARNING(key, message, options)
- ADD_ERROR(key, message, options)
Also you can clear notification store:
- CLEAR_BY_KEY(key) - delete notification by key
- CLEAR() - clean the whole notifications store
Create and delete the notification:
{ thisprops; thisprops; }
Also, you can specify OPTIONS like "hideAfter | ha" and "showAfter | sa":
thisprops; thisprops;
Customization.
Set global settings for each kind of notification:
;const CUSTOMIZE = ActionsCUSTOMIZE;// or; { thisprops; }
You can set global "className" and "style" for particular kind of notifications.
Notification Component.
Notification Component has several props like:
- nkey - that's key that you specify when to create an action.
- kind - that's a type of notification.
- style - style for notification.
- className - classes for notification.
- isUseDefSettings - specify if a component must use global settings (default = true).
- isShowMessage - specify if a component must show a message that you specify when to create an action (default = true).
<Notifications nkey="demo.key" kind=KindsNOTIFICATION_ERROR style=background: 'red' className="error" isUseDefSettings=false/>
Nested components:
<Notifications nkey="demo.key" kind=KindsNOTIFICATION_INFO isShowMessage=false > <p>It is nested element</p> </Notifications>
Full example.
;;;;;;; /* ***** DEMO COMPONENT ***** */ { super } { thispropsactions; thispropsactions; thispropsactions; thispropsactions; thispropsactions; thispropsactions; thispropsactions; thispropsactions; } { return <div className="container"> <Navbar> <NavbarHeader> <NavbarBrand> React Redux Notifier </NavbarBrand> <NavbarToggle /> </NavbarHeader> </Navbar> <Row> <Col xs=12> <Notifications nkey="demo.key" kind=KindsNOTIFICATION_INFO> <p>It is nested element</p> </Notifications> <Notifications nkey="demo.key" kind=KindsNOTIFICATION_ERROR style=background: 'red' className="super" isUseDefSettings=true/> <Notifications nkey="demo.key.ha" kind=KindsNOTIFICATION_SUCCESS/> <Notifications nkey="demo.key.sa" kind=KindsNOTIFICATION_WARNING/> </Col> </Row> </div> ; } { return notifier: storenotifier;} { return actions: ;} const DemoDecorated = Demo; /* ***** STORE ***** */ const createStoreWithMiddleware = createStore; const store = ; /* ***** RENDER ***** */ ReactDOM