react-toolbox/components/snackbar/index.jsx

58 lines
1.6 KiB
React
Raw Normal View History

2015-10-20 06:25:35 +03:00
import React from 'react';
2015-10-20 18:27:22 +03:00
import Button from '../button';
2015-10-20 06:25:35 +03:00
import FontIcon from '../font_icon';
import Overlay from '../overlay';
import style from './style';
2015-10-20 06:25:35 +03:00
2015-10-22 02:59:20 +03:00
class Snackbar extends React.Component {
2015-10-21 05:58:11 +03:00
static propTypes = {
action: React.PropTypes.string,
active: React.PropTypes.bool,
2015-11-01 17:19:45 +03:00
className: React.PropTypes.string,
2015-10-20 06:25:35 +03:00
icon: React.PropTypes.string,
2015-11-01 17:19:45 +03:00
label: React.PropTypes.string.isRequired,
onClick: React.PropTypes.func,
2015-11-12 07:25:14 +03:00
onTimeout: React.PropTypes.func,
2015-10-20 06:25:35 +03:00
timeout: React.PropTypes.number,
type: React.PropTypes.string
2015-10-21 05:58:11 +03:00
};
2015-10-20 06:25:35 +03:00
2015-11-12 07:25:14 +03:00
componentDidUpdate () {
if (this.props.active && this.props.timeout) {
setTimeout(() => {
this.props.onTimeout(event, this);
}, this.props.timeout * 1000);
}
2015-11-12 07:25:14 +03:00
}
2015-10-20 06:25:35 +03:00
renderButton () {
if (this.props.action) {
return (
<Button
className={style.button}
2015-10-21 01:48:24 +03:00
label={this.props.action}
onClick={this.props.onClick}
/>
);
}
2015-10-21 05:58:11 +03:00
}
2015-10-20 18:27:22 +03:00
2015-10-20 06:25:35 +03:00
render () {
let className = `${style.root} ${style[this.props.type]}`;
2015-11-12 07:25:14 +03:00
if (this.props.active) className += ` ${style.active}`;
2015-10-20 06:25:35 +03:00
if (this.props.className) className += ` ${this.props.className}`;
return (
2015-11-15 16:42:16 +03:00
<Overlay active={this.props.active} opacity={0}>
<div data-react-toolbox='snackbar' className={className}>
{ this.props.icon ? <FontIcon value={this.props.icon} className={style.icon} /> : null }
<span className={style.label}>{this.props.label}</span>
{ this.renderButton() }
</div>
</Overlay>
2015-10-20 06:25:35 +03:00
);
2015-10-21 05:58:11 +03:00
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2015-10-22 02:59:20 +03:00
export default Snackbar;