Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { PropTypes } from 'react';
- class WaitButton extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- loading: false,
- };
- this.handleOnClick = this.handleOnClick.bind(this);
- // this.startLoading = this.startLoading.bind(this);
- this.stopLoading = this.stopLoading.bind(this);
- }
- stopLoading() {
- console.log('stopLoad')
- this.setState({
- loading: false,
- });
- }
- handleOnClick(event) {
- this.setState({
- loading: true,
- });
- this.props.onClick(event, this.stopLoading)
- // setTimeout(() => this.stopLoading(), 2000)
- }
- render() {
- const { text, btnClass } = this.props;
- const buttonClass = `btn btn-${btnClass}`;
- return (
- <a className={buttonClass} onClick={this.handleOnClick}>
- { text }
- {this.state.loading ?
- <i ref="spinner" className="fa fa-spinner fa-spin fa-fw" />
- : null}
- </a>
- );
- }
- }
- WaitButton.propTypes = {
- onClick: PropTypes.func.isRequired,
- text: PropTypes.string.isRequired,
- btnClass: PropTypes.string,
- };
- WaitButton.defaultProps = {
- btnClass: 'primary',
- };
- export { WaitButton };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement