Javi Velasco 2016-11-18 18:35:20 +01:00
parent e40c77442e
commit 9cd7fba6b5
1 changed files with 16 additions and 5 deletions

View File

@ -33,13 +33,15 @@ const factory = (Overlay, Button) => {
type: PropTypes.oneOf([ 'accept', 'cancel', 'warning' ])
};
componentDidMount () {
if (this.props.active && this.props.timeout) {
this.scheduleTimeout(this.props);
}
}
componentWillReceiveProps (nextProps) {
if (nextProps.active && nextProps.timeout) {
if (this.curTimeout) clearTimeout(this.curTimeout);
this.curTimeout = setTimeout(() => {
nextProps.onTimeout();
this.curTimeout = null;
}, nextProps.timeout);
this.scheduleTimeout(nextProps);
}
}
@ -47,6 +49,15 @@ const factory = (Overlay, Button) => {
clearTimeout(this.curTimeout);
}
scheduleTimeout = props => {
const { onTimeout, timeout } = props;
if (this.curTimeout) clearTimeout(this.curTimeout);
this.curTimeout = setTimeout(() => {
if (onTimeout) onTimeout();
this.curTimeout = null;
}, timeout);
}
render () {
const {action, active, children, label, onClick, theme, type } = this.props;
const className = classnames([theme.snackbar, theme[type]], {