react-notification
Advanced tools
Comparing version 6.1.1 to 6.2.0
@@ -17,3 +17,3 @@ 'use strict'; | ||
activeBarStyle: _react.PropTypes.object, | ||
dismissAfter: _react.PropTypes.number, | ||
dismissAfter: _react.PropTypes.oneOfType([_react.PropTypes.bool, _react.PropTypes.number]), | ||
onDismiss: _react.PropTypes.func, | ||
@@ -20,0 +20,0 @@ className: _react.PropTypes.string, |
@@ -33,3 +33,3 @@ 'use strict'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Notification).call(this, props)); | ||
var _this = _possibleConstructorReturn(this, (Notification.__proto__ || Object.getPrototypeOf(Notification)).call(this, props)); | ||
@@ -50,2 +50,3 @@ _this.getBarStyle = _this.getBarStyle.bind(_this); | ||
value: function componentWillReceiveProps(nextProps) { | ||
if (this.props.dismissAfter === false) return; | ||
if (!nextProps.hasOwnProperty('isLast')) clearTimeout(this.dismissTimeout); | ||
@@ -59,3 +60,3 @@ if (nextProps.onDismiss && nextProps.isActive && !this.props.isActive) { | ||
value: function componentWillUnmount() { | ||
clearTimeout(this.dismissTimeout); | ||
if (this.props.dismissAfter) clearTimeout(this.dismissTimeout); | ||
} | ||
@@ -62,0 +63,0 @@ |
@@ -33,3 +33,3 @@ 'use strict'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(StackedNotification).call(this, props)); | ||
var _this = _possibleConstructorReturn(this, (StackedNotification.__proto__ || Object.getPrototypeOf(StackedNotification)).call(this, props)); | ||
@@ -49,5 +49,7 @@ _this.state = { | ||
this.dismissTimeout = setTimeout(this.setState.bind(this, { | ||
isActive: false | ||
}), this.props.dismissAfter); | ||
if (this.props.dismissAfter) { | ||
this.dismissTimeout = setTimeout(this.setState.bind(this, { | ||
isActive: false | ||
}), this.props.dismissAfter); | ||
} | ||
} | ||
@@ -54,0 +56,0 @@ }, { |
{ | ||
"name": "react-notification", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"description": "Snackbar style notification component for React.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -98,3 +98,3 @@ # react-notification | ||
| activeClassName | string | Custom class to apply to the top-level component when active| | `'notification-bar-active'`| | ||
| dismissAfter | number | Timeout for onDismiss event | | `2000` | | ||
| dismissAfter | number or false | Timeout for onDismiss event | | `2000` | | ||
@@ -101,0 +101,0 @@ The `style` prop useful if you are not using React inline styles and would like to use CSS instead. See [styles](#styles) for more. |
@@ -35,3 +35,3 @@ import { Notification, NotificationStack } from '../src/index'; | ||
it('has custom class name', () => { | ||
it('has custom class name', () => { | ||
let classNameComponent = shallow( | ||
@@ -77,3 +77,2 @@ <Notification | ||
it('should render message element', () => { | ||
@@ -211,5 +210,4 @@ expect(wrapper).to.have.descendants(messageClassName); | ||
it('onDismiss fires correctly without prop change', done => { | ||
it('onDismiss fires once when dismissAfter is passed', done => { | ||
const handleDismiss = spy(); | ||
const wrapper = mount( | ||
@@ -220,6 +218,7 @@ <Notification | ||
onDismiss={handleDismiss} | ||
isActive | ||
/> | ||
); | ||
wrapper.setProps({ isActive: true }); | ||
setTimeout(() => { | ||
@@ -233,3 +232,17 @@ try { | ||
}, mockNotification.dismissAfter); | ||
}) | ||
}); | ||
it('onDismiss does not get fired when dismissAfter is false', () => { | ||
const handleDismiss = spy(); | ||
const wrapper = shallow( | ||
<Notification | ||
message={mockNotification.message} | ||
dismissAfter={false} | ||
onDismiss={handleDismiss} | ||
/> | ||
); | ||
expect(handleDismiss.calledOnce).to.equal(false); | ||
}); | ||
}); |
@@ -25,2 +25,3 @@ import { Notification, NotificationStack } from '../src/index'; | ||
wrapper.update(); | ||
setTimeout(() => { | ||
@@ -27,0 +28,0 @@ try { |
import chai from 'chai'; | ||
import chaiEnzyme from 'chai-enzyme'; | ||
// Include stack on error | ||
chai.config.includeStack = true; | ||
/** | ||
@@ -5,0 +8,0 @@ * Add commonly used functions in tests to global |
364603
853