react-notification
Advanced tools
Comparing version 5.0.2 to 5.0.3
@@ -41,5 +41,2 @@ 'use strict'; | ||
dismissAfter: isLast ? dismissAfter : dismissAfter + index * 1000, | ||
onClick: function onClick() { | ||
return props.onDismiss(notification); | ||
}, | ||
onDismiss: function onDismiss() { | ||
@@ -46,0 +43,0 @@ setTimeout(function () { |
@@ -44,7 +44,7 @@ 'use strict'; | ||
value: function componentDidMount() { | ||
setTimeout(this.setState.bind(this, { | ||
this.activeTimeout = setTimeout(this.setState.bind(this, { | ||
isActive: true | ||
}), 1); | ||
setTimeout(this.setState.bind(this, { | ||
this.dismissTimeout = setTimeout(this.setState.bind(this, { | ||
isActive: false | ||
@@ -54,2 +54,7 @@ }), this.props.dismissAfter); | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
clearTimeout(this.dismissTimeout); | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -60,3 +65,2 @@ value: function render() { | ||
return _react2.default.createElement(_notification2.default, _extends({}, this.props, { | ||
action: false, | ||
isActive: this.state.isActive, | ||
@@ -63,0 +67,0 @@ barStyle: Object.assign({}, { |
@@ -11,28 +11,42 @@ import React, { Component } from 'react'; | ||
this.state = { | ||
notifications: OrderedSet(), | ||
notifications: {}, | ||
}; | ||
// This is just used for the sake of an example to make sure | ||
// notifications have unique keys. In production, you should have | ||
// a different system for UIDs. | ||
count: 0 | ||
}; | ||
this.removeNotification = this.removeNotification.bind(this); | ||
this.renderNotifications = this.renderNotifications.bind(this); | ||
} | ||
addNotification() { | ||
const { notifications, count } = this.state; | ||
const id = notifications.size + 1; | ||
const newCount = count + 1; | ||
// This is just used for the sake of an example to make sure | ||
// notifications have unique keys. In production, you should have | ||
// a different system for UIDs. | ||
const id = Date.now(); | ||
return this.setState({ | ||
count: newCount, | ||
notifications: notifications.add({ | ||
const notifications = Object.assign({}, this.state.notifications, { | ||
[id]: { | ||
action: 'Dismiss', | ||
dismissAfter: 3400, | ||
onClick: () => this.removeNotification(id), | ||
message: `Notification ${id}`, | ||
key: newCount, | ||
barStyle: { | ||
background: 'grey' | ||
} | ||
}) | ||
key: id | ||
} | ||
}); | ||
return this.setState({ | ||
notifications: notifications | ||
}); | ||
} | ||
removeNotification (notif) { | ||
const notifications = Object.assign({}, this.state.notifications); | ||
delete notifications[notif]; | ||
this.setState({ notifications }) | ||
} | ||
renderNotifications () { | ||
return Object.keys(this.state.notifications).map(notif => this.state.notifications[notif]) | ||
} | ||
render() { | ||
@@ -45,6 +59,4 @@ return ( | ||
<NotificationStack | ||
notifications={this.state.notifications.toArray()} | ||
onDismiss={notification => this.setState({ | ||
notifications: this.state.notifications.delete(notification) | ||
})} | ||
notifications={this.renderNotifications()} | ||
onDismiss={notif => this.removeNotification(notif.key)} | ||
/> | ||
@@ -51,0 +63,0 @@ </div> |
{ | ||
"name": "react-notification", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"description": "Snackbar style notification component for React.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -131,2 +131,2 @@ # react-notification | ||
Copyright 2016 Patrick Burtchaell. Licensed MIT. | ||
Copyright 2016 Patrick Burtchaell. Licensed MIT. [Gratipay](https://gratipay.com/~pburtchaell/). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355358
623