|
1 |
| -# React Toastify Redux |
| 1 | +# React Toastify Redux [](https://travis-ci.org/fayster/react-toastify-redux) [](https://badge.fury.io/js/react-toastify-redux) [](https://github.com/fayster/react-toastify-redux) [](https://coveralls.io/github/fayster/react-toastify-redux?branch=master) |
| 2 | + |
| 3 | + |
| 4 | + |
2 | 5 | Wraps [react-toastify](https://github.com/fkhadra/react-toastify) into a component and exposes actions and reducer.
|
3 | 6 |
|
4 | 7 | ## Installation
|
@@ -111,16 +114,130 @@ ToastContainer extends properties from ToastContainer in react-toastify. Also ha
|
111 | 114 | | Parameter | Type | Default | Description |
|
112 | 115 | |------------------------|---------|---------|----------------------|
|
113 | 116 | | renderDefaultComponent | boolean | false | Render default toast component? Use this propery if using custom toast component. |
|
114 |
| -| type <td colspan=3>same as ToastContainer |
115 |
| -| autoClose <td colspan=3>same as ToastContainer |
116 |
| -| hideProgressBar <td colspan=3>same as ToastContainer |
117 |
| -| position <td colspan=3>same as ToastContainer |
118 |
| -| pauseOnHover <td colspan=3>same as ToastContainer |
119 |
| -| className <td colspan=3>same as ToastContainer |
120 |
| -| bodyClassName <td colspan=3>same as ToastContainer |
121 |
| -| progressClassName <td colspan=3>same as ToastContainer |
122 |
| -| draggable <td colspan=3>same as ToastContainer |
123 |
| -| draggablePercent <td colspan=3>same as ToastContainer |
| 117 | +| type <td colspan=3>sa# React Toastify Redux |
| 118 | +Wraps [react-toastify](https://github.com/fkhadra/react-toastify) into a component and exposes actions and reducer. |
| 119 | + |
| 120 | +## Installation |
| 121 | +``` |
| 122 | +$ npm install --save react-toasify-redux |
| 123 | +$ yarn add react-toastify-redux |
| 124 | +``` |
| 125 | + |
| 126 | +## Usage |
| 127 | +Import the reducer and pass it to your combineReducers: |
| 128 | +```javascript |
| 129 | +import {combineReducers} from 'redux'; |
| 130 | +import {toastsReducer as toasts} from 'react-toasify-redux'; |
| 131 | + |
| 132 | +export default combineReducers({ |
| 133 | + // ...other reducers |
| 134 | + toasts |
| 135 | +}); |
| 136 | +``` |
| 137 | + |
| 138 | +Include the toast controller in main view: |
| 139 | +```javascript |
| 140 | +import {ToastController} from 'react-toasify-redux'; |
| 141 | + |
| 142 | +export default () => { |
| 143 | + return ( |
| 144 | + <div> |
| 145 | + ... |
| 146 | + <ToastController /> |
| 147 | + </div> |
| 148 | + ); |
| 149 | +}; |
| 150 | +``` |
| 151 | + |
| 152 | +### Actions |
| 153 | +Use actions for create, update and remove toasts: |
| 154 | + |
| 155 | +```javascript |
| 156 | +import {dismiss, update, error, message, warning, success, info} from 'react-toastify-redux'; |
| 157 | + |
| 158 | +dispatch(dismiss(id)); |
| 159 | +dispatch(dismiss()); // dismiss all toasts |
| 160 | +dispatch(update(id, options)); |
| 161 | +dispatch(message('Default message')); |
| 162 | +dispatch(success('Success message')); |
| 163 | +dispatch(error('Error message')); |
| 164 | +dispatch(warning('Warning message')); |
| 165 | +dispatch(info('Info message')); |
| 166 | +``` |
| 167 | + |
| 168 | +### Customization toast |
| 169 | +Create toast component |
| 170 | +```javascript |
| 171 | +export default ({ title, message }) => ( |
| 172 | + <div className='toast'> |
| 173 | + <div className='header'>{title}</div> |
| 174 | + <div className='message'>{message}</div> |
| 175 | + </div> |
| 176 | +); |
| 177 | +``` |
| 178 | + |
| 179 | +Include this component in ToastConroller |
| 180 | +```javascript |
| 181 | +import {ToastController} from 'react-toasify-redux'; |
| 182 | +import CustomToastComponent from 'awesome-folder/custom-toast-component'; |
| 183 | + |
| 184 | +export default () => { |
| 185 | + return ( |
| 186 | + <div> |
| 187 | + ... |
| 188 | + <ToastController toastComponent={CustomToastComponent} /> |
| 189 | + </div> |
| 190 | + ); |
| 191 | +}; |
| 192 | +``` |
| 193 | + |
| 194 | +## API |
| 195 | + |
| 196 | +### ToastContainer |
| 197 | +ToastContainer extends properties from ToastContainer in react-toastify. Also have new properties: |
| 198 | + |
| 199 | +| Props | Type | Default | Description | |
| 200 | +|----------------|-------------------------|---------|--------------------------------------------------| |
| 201 | +| toastComponent | ComponentClass or false | - | Element that will be displayed after emit toast | |
| 202 | + |
| 203 | +### Dismiss |
| 204 | +| Parameter | Type | Required | Description | |
| 205 | +|-----------|--------|----------|--------------------------------------------------------------------------| |
| 206 | +| toast id | string | ✘ | Id toast for dismiss. If call action without id, then dismiss all toasts | |
| 207 | + |
| 208 | +### Update |
| 209 | +| Parameter | Type | Required | Description | |
| 210 | +|-----------|--------|----------|----------------------| |
| 211 | +| toast id | string | ✓ | Id toast for update | |
| 212 | +| options | object | ✘ | Options listed below | |
| 213 | +* Available options : |
| 214 | + * [See: Toast Base Options](#toast-base-option) |
| 215 | + * message: toast message for update |
| 216 | + |
| 217 | +### Toast Actions (Message, Success, Info, Warning, Error) |
| 218 | +| Parameter | Type | Required | Description | |
| 219 | +|-----------|--------|----------|----------------------| |
| 220 | +| message | string | ✓ | Message for toast | |
| 221 | +| options | object | ✘ | Options listed below | |
| 222 | +* Available options : |
| 223 | + * [See: Toast Base Options](#toast-base-option) |
| 224 | + * id: custom id for a toast. By default in generated automatically. |
| 225 | + |
| 226 | +### <a name="toast-base-option">Toast Base Options</a> |
| 227 | +| Parameter | Type | Default | Description | |
| 228 | +|------------------------|---------|---------|----------------------| |
| 229 | +| renderDefaultComponent | boolean | false | Render default toast component? Use this propery if using custom toast component. | |
| 230 | +| title | string | '' | Title for custom toast component |
| 231 | +| type | One of: 'info', 'success', 'warning', 'error', 'default' | 'default' | same as ToastContainer |
| 232 | +| autoClose | number or false | 5000 | Set the delay in ms to close the toast automatically |
| 233 | +| hideProgressBar | boolean | false | Hide or show the progress bar |
| 234 | +| position | One of: 'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left' | 'top-right' | Set the default position to use |
| 235 | +| pauseOnHover | boolean | true | Pause the timer when the mouse hover the toast |
| 236 | +| className | string or object | - | An optional css class to set |
| 237 | +| bodyClassName | string or object | - |same as ToastContainer |
| 238 | +| progressClassName | string or object | - |same as ToastContainer |
| 239 | +| draggable | boolean | true | Allow toast to be draggable |
| 240 | +| draggablePercent | number | 80 | The percentage of the toast's width it takes for a drag to dismiss a toast |
124 | 241 |
|
125 | 242 | ## License
|
126 | 243 | Licensed under MIT
|
0 commit comments