Skip to content

Commit

Permalink
add onAttentionClick and expose remove
Browse files Browse the repository at this point in the history
- Feature request: #170
- Expose remove on toastr object to simply copy default behavior
  • Loading branch information
Daniel Keller authored and diegoddox committed Dec 31, 2017
1 parent 156ea05 commit 2e8cc85
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ constructor(props) {
title: 'your title',
position: 'top-left', // This will override the global props position.
attention: true, // This will add a shadow like the confirm method.
onAttentionClick: (id) => {}, //override default behavior of 'attention' background click.
message: 'message',
options: {}
});
Expand All @@ -132,11 +133,11 @@ constructor(props) {
```

# Toastr methods
Toastr accepts the following methods: `success` `info` `warning` `light` `error` `confirm` `message` and `removeByType`
Toastr accepts the following methods: `success` `info` `warning` `light` `error` `confirm` `message`, `remove` and `removeByType`

##### Toastr: `success` `info` `warning` `light` `error` and `removeByType`
##### Toastr: `success` `info` `warning` `light` `error` `remove` and `removeByType`
Each of these methods can take up to three arguments the `title` a `message` and `options`.
In `options` you can specify `timeOut` `icon` `onShowComplete` `onHideComplete` `className` `component` `removeOnHover`, `showCloseButton`, `onCloseButtonClick`, `progressBar`, `transitionIn`, `position`, `attention` and `transitionOut`.
In `options` you can specify `timeOut` `icon` `onShowComplete` `onHideComplete` `className` `component` `removeOnHover`, `showCloseButton`, `onCloseButtonClick`, `progressBar`, `transitionIn`, `position`, `attention`, `onAttentionClick` and `transitionOut`.

``` javascript
import {toastr} from 'react-redux-toastr'
Expand All @@ -160,6 +161,7 @@ toastr.info('The message', toastrOptions)
toastr.warning('The title', 'The message')
toastr.error('The message')
toastr.removeByType('error') // Remove all toastrs with the type error.
toastr.remove('123') // Removes toastr with id '123'
```

##### Toastr methods light
Expand Down
4 changes: 4 additions & 0 deletions development/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default class Menu extends React.Component {
icon: (<Avatar />),
position: 'top-center',
attention: true,
onAttentionClick: (id) => {
console.log('Attention background clicked, id: ', id);
toastr.remove(id);
},
timeOut: 0,
transitionIn: 'fadeIn',
transitionOut: 'fadeOut'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-toastr",
"version": "7.1.6",
"version": "7.2.0",
"description": "react-redux-toastr is a React toastr message implemented with Redux",
"main": "lib/index.js",
"jsnext:main": "./src/index.js",
Expand Down
14 changes: 12 additions & 2 deletions src/ReduxToastr.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ export class ReduxToastr extends React.Component {
}

componentDidMount() {
const {add, showConfirm, clean, removeByType} = this.props;
const {add, showConfirm, clean, removeByType, remove} = this.props;
EE.on('toastr/confirm', showConfirm);
EE.on('add/toastr', add);
EE.on('clean/toastr', clean);
EE.on('removeByType/toastr', removeByType);
EE.on('remove/toastr', remove);
}

componentWillUnmount() {
EE.removeListener('toastr/confirm');
EE.removeListener('add/toastr');
EE.removeListener('clean/toastr');
EE.removeListener('removeByType/toastr');
EE.removeListener('remove/toastr');
this.toastrFired = {};
}

Expand Down Expand Up @@ -100,7 +102,15 @@ export class ReduxToastr extends React.Component {
{...this.props}
/>
{item.options && item.options.attention &&
<div onClick={() => this.props.remove(item.id)} className="toastr-attention" />
<div
onClick={() => {
if (typeof item.options.onAttentionClick === 'function') {
item.options.onAttentionClick(item.id);
} else {
this.props.remove(item.id);
}
}}
className="toastr-attention"/>
}
</span>
);
Expand Down
2 changes: 2 additions & 0 deletions src/toastrEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ actions.clean = () => emitter.emit('clean/toastr');
*/
actions.removeByType = (type) => emitter.emit('removeByType/toastr', type);

actions.remove = (id) => emitter.emit('remove/toastr', id);

actions.confirm = (...args) => {
emitter.emit('toastr/confirm', {
message: args[0],
Expand Down

0 comments on commit 2e8cc85

Please sign in to comment.