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-22 02:31:17 +03:00
|
|
|
class Slider extends React.Component {
|
2015-10-21 05:58:11 +03:00
|
|
|
static propTypes = {
|
2015-10-20 19:08:12 +03:00
|
|
|
action: React.PropTypes.string,
|
2015-10-20 06:25:35 +03:00
|
|
|
icon: React.PropTypes.string,
|
2015-10-20 19:08:12 +03:00
|
|
|
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
|
|
|
|
2015-10-22 02:31:17 +03:00
|
|
|
handleClick = (event) => {
|
2015-10-20 19:08:12 +03:00
|
|
|
this.setState({active: false});
|
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick(event, this);
|
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
};
|
2015-10-20 06:25:35 +03:00
|
|
|
|
2015-10-20 19:08:12 +03:00
|
|
|
renderButton () {
|
|
|
|
if (this.props.action) {
|
|
|
|
return (
|
|
|
|
<Button
|
2015-10-21 01:48:24 +03:00
|
|
|
kind='flat'
|
2015-10-20 19:08:12 +03:00
|
|
|
className={style.button}
|
2015-10-21 01:48:24 +03:00
|
|
|
label={this.props.action}
|
2015-10-21 09:13:24 +03:00
|
|
|
onClick={this.handleClick}
|
2015-10-20 19:08:12 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
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-10-20 19:08:12 +03:00
|
|
|
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>
|
2015-10-20 19:08:12 +03:00
|
|
|
{ this.renderButton() }
|
2015-10-20 06:25:35 +03:00
|
|
|
</div>
|
|
|
|
);
|
2015-10-21 05:58:11 +03:00
|
|
|
}
|
2015-10-20 19:08:12 +03:00
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.setState({active: false});
|
2015-10-21 05:58:11 +03:00
|
|
|
}
|
2015-10-20 19:08:12 +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 13:25:07 +03:00
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
|
|
|
|
export default Slider;
|