2015-11-22 23:41:28 +03:00
|
|
|
import React from 'react';
|
2016-05-25 01:41:26 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2016-04-10 18:43:46 +03:00
|
|
|
import ActivableRenderer from '../hoc/ActivableRenderer';
|
2015-11-22 23:41:28 +03:00
|
|
|
import Button from '../button';
|
|
|
|
import FontIcon from '../font_icon';
|
|
|
|
import Overlay from '../overlay';
|
|
|
|
|
|
|
|
class Snackbar extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
action: React.PropTypes.string,
|
|
|
|
active: React.PropTypes.bool,
|
|
|
|
className: React.PropTypes.string,
|
2016-04-07 04:24:31 +03:00
|
|
|
icon: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.element
|
|
|
|
]),
|
2015-11-22 23:41:28 +03:00
|
|
|
label: React.PropTypes.string.isRequired,
|
|
|
|
onClick: React.PropTypes.func,
|
|
|
|
onTimeout: React.PropTypes.func,
|
2016-05-25 01:41:26 +03:00
|
|
|
theme: React.PropTypes.shape({
|
|
|
|
accept: React.PropTypes.string,
|
|
|
|
active: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
cancel: React.PropTypes.string,
|
|
|
|
icon: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
snackbar: React.PropTypes.string,
|
|
|
|
warning: React.PropTypes.string
|
|
|
|
}),
|
2015-11-22 23:41:28 +03:00
|
|
|
timeout: React.PropTypes.number,
|
2016-05-25 01:41:26 +03:00
|
|
|
type: React.PropTypes.oneOf([ 'accept', 'cancel', 'warning' ])
|
2015-11-22 23:41:28 +03:00
|
|
|
};
|
|
|
|
|
2016-03-28 02:29:08 +03:00
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (nextProps.active && nextProps.timeout) {
|
2016-04-10 18:43:46 +03:00
|
|
|
if (this.curTimeout) clearTimeout(this.curTimeout);
|
|
|
|
this.curTimeout = setTimeout(() => {
|
2016-03-28 02:29:08 +03:00
|
|
|
nextProps.onTimeout();
|
2016-04-10 18:43:46 +03:00
|
|
|
this.curTimeout = null;
|
2016-03-28 02:29:08 +03:00
|
|
|
}, nextProps.timeout);
|
2015-11-22 23:41:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-05-25 01:41:26 +03:00
|
|
|
const {action, active, icon, label, onClick, theme, type } = this.props;
|
|
|
|
const className = classnames([theme.snackbar, theme[type]], {
|
|
|
|
[theme.active]: active
|
2015-11-28 22:15:26 +03:00
|
|
|
}, this.props.className);
|
2015-11-22 23:41:28 +03:00
|
|
|
|
|
|
|
return (
|
2015-12-11 20:01:24 +03:00
|
|
|
<Overlay invisible>
|
2015-11-22 23:41:28 +03:00
|
|
|
<div data-react-toolbox='snackbar' className={className}>
|
2016-05-25 01:41:26 +03:00
|
|
|
{icon ? <FontIcon value={icon} className={theme.icon} /> : null}
|
|
|
|
<span className={theme.label}>{label}</span>
|
|
|
|
{action ? <Button className={theme.button} label={action} onClick={onClick}/> : null}
|
2015-11-22 23:41:28 +03:00
|
|
|
</div>
|
|
|
|
</Overlay>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:41:26 +03:00
|
|
|
export default themr('ToolboxSnackbar')(ActivableRenderer()(Snackbar));
|