All files / components/stat-tile stat-tile.jsx

61.54% Statements 8/13
40% Branches 4/10
33.33% Functions 1/3
61.54% Lines 8/13
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78          1x   1x   1x 1x                           1x                         1x                               1x                             1x                  
import React from 'react';
import PropTypes from 'prop-types';
 
class StatTile extends React.Component {
  render() {
    let link = '';
    let stats = (
      <h3>{this.props.stats}</h3>
    );
    Eif(this.props.link) {
      link = (
        <a
          href={this.props.link}
          onClick={this.props.onClick ? e => {
             e.preventDefault();
             e.stopPropagation();
             this.props.onClick();
           } : () => {}}
          className="small-box-footer"
        >
          More info <i className="fa fa-arrow-circle-right"></i>
        </a>
      );
    }
    Iif(this.props.stats instanceof String && this.props.stats.indexOf('%') !== -1) {
      let style = {
        fontSize: '20px'
      };
      stats = (
        <h3>
          {this.props.stats.replace(/%/g,'')}
          <sup style={style}>
            {this.props.stats.indexOf('%') >= 0 ? '%' : ''}
          </sup>
        </h3>
      );
    }
    return (
      <div className={`col-md-${this.props.width} col-sm-6 col-xs-12`}>
        <div className={`small-box ${this.props.theme}`}>
          <div className="inner">
            {stats}
            <p>{this.props.subject}</p>
          </div>
          <div className="icon">
            <i className={`fa ${this.props.icon}`}></i>
          </div>
          {link}
        </div>
      </div>
    );
  }
}
StatTile.propTypes = {
  width: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.string
  ]),
  theme: PropTypes.string,
  icon: PropTypes.string,
  subject: PropTypes.string,
  stats: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.string
  ]),
  link: PropTypes.string,
  onClick: PropTypes.func
};
StatTile.defaultProps = {
  width: 3,
  theme: 'bg-yellow',
  icon: 'fa-user-plus',
  subject: '',
  stats: 0
};
 
export default StatTile;