all files / components/ Button.js

88.89% Statements 32/36
62.16% Branches 23/37
100% Functions 11/11
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                  
import React from 'react';IEE
import PropTypes from 'prop-types';
import Loader from 'halogen/PulseLoader';EIII
 
class Button extends React.Component {
  componentDidMount() {
    // some logic here - we only test if the method is called
  }
  render() {
    const spinner = (<Loader id="spinner" color="#FFFFFF" size="8px" margin="0px" />);
    return (
      <button
        className={`btn btn--primary btn--${this.props.size}`}
        id={this.props.id}
        aria-label={this.props.ariaLabel}
        onClick={this.props.loading ? null : this.props.onClick}
        type={this.props.type}
      >
        {this.props.loading ? spinner : this.props.text}
      </button>
    );
  }
}
 
Button.defaultProps = {
  loading: false,
  onClick: null,
};
 
Button.propTypes = {
  id: PropTypes.string.isRequired,
  text: PropTypes.string.isRequired, // This can be just text, or a spinner etc.
  onClick: PropTypes.func,
  ariaLabel: PropTypes.string.isRequired,
  type: PropTypes.string.isRequired,
  size: PropTypes.string.isRequired, // wide or thin
  loading: PropTypes.bool,
};
 
export default Button;