Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import React, { PropTypes } from 'react';
  2.  
  3. class WaitButton extends React.Component {
  4. constructor(props) {
  5. super(props);
  6.  
  7. this.state = {
  8. loading: false,
  9. };
  10.  
  11. this.handleOnClick = this.handleOnClick.bind(this);
  12. // this.startLoading = this.startLoading.bind(this);
  13. this.stopLoading = this.stopLoading.bind(this);
  14. }
  15.  
  16. stopLoading() {
  17. console.log('stopLoad')
  18. this.setState({
  19. loading: false,
  20. });
  21. }
  22.  
  23. handleOnClick(event) {
  24. this.setState({
  25. loading: true,
  26. });
  27.  
  28. this.props.onClick(event, this.stopLoading)
  29. // setTimeout(() => this.stopLoading(), 2000)
  30. }
  31.  
  32. render() {
  33. const { text, btnClass } = this.props;
  34. const buttonClass = `btn btn-${btnClass}`;
  35.  
  36. return (
  37. <a className={buttonClass} onClick={this.handleOnClick}>
  38. { text }
  39. {this.state.loading ?
  40. <i ref="spinner" className="fa fa-spinner fa-spin fa-fw" />
  41. : null}
  42. </a>
  43. );
  44. }
  45. }
  46.  
  47. WaitButton.propTypes = {
  48. onClick: PropTypes.func.isRequired,
  49. text: PropTypes.string.isRequired,
  50. btnClass: PropTypes.string,
  51. };
  52.  
  53. WaitButton.defaultProps = {
  54. btnClass: 'primary',
  55. };
  56.  
  57. export { WaitButton };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement