react-toolbox/components/snackbar/index.jsx

68 lines
1.6 KiB
React
Raw Normal View History

2015-10-20 06:25:35 +03:00
import React from 'react';
import style from './style';
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';
2015-10-21 05:58:11 +03:00
export default class Slider extends React.Component {
static propTypes = {
action: React.PropTypes.string,
2015-10-20 06:25:35 +03:00
icon: React.PropTypes.string,
label: React.PropTypes.string,
onClick: 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-10-21 05:58:11 +03:00
state = {
active: false
};
2015-10-20 06:25:35 +03:00
handleClick (event) {
this.setState({active: false});
if (this.props.onClick) {
this.props.onClick(event, this);
}
2015-10-21 05:58:11 +03:00
}
2015-10-20 06:25:35 +03:00
renderButton () {
if (this.props.action) {
return (
<Button
2015-10-21 01:48:24 +03:00
kind='flat'
className={style.button}
2015-10-21 01:48:24 +03:00
label={this.props.action}
2015-10-21 05:58:11 +03:00
onClick={::this.handleClick}
/>
);
}
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]}`;
if (this.state.active) className += ` ${style.active}`;
2015-10-20 06:25:35 +03:00
if (this.props.className) className += ` ${this.props.className}`;
return (
<div data-react-toolbox='snackbar' className={className}>
2015-10-20 18:27:22 +03:00
{ this.props.icon ? <FontIcon value={this.props.icon} className={style.icon} /> : null }
<span className={style.label}>{this.props.label}</span>
{ this.renderButton() }
2015-10-20 06:25:35 +03:00
</div>
);
2015-10-21 05:58:11 +03:00
}
// -- Extends
hide () {
this.setState({active: false});
2015-10-21 05:58:11 +03:00
}
show () {
this.setState({active: true});
if (this.props.timeout) {
setTimeout(() => {
this.setState({ active: false });
}, this.props.timeout * 1000);
}
2015-10-20 06:25:35 +03:00
}
2015-10-21 05:58:11 +03:00
};