all files / src/SqlLab/components/ TabStatusIcon.jsx

94.12% Statements 16/17
75% Branches 3/4
75% Functions 3/4
94.12% Lines 16/17
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                                                      
import React from 'react';
import PropTypes from 'prop-types';
 
const propTypes = {
  onClose: PropTypes.func.isRequired,
  tabState: PropTypes.string.isRequired,
};
 
class TabStatusIcon extends React.Component {
  constructor(props) {
    super(props);
    this.onMouseOver = this.onMouseOver.bind(this);
    this.onMouseOut = this.onMouseOut.bind(this);
 
    this.state = { isHovered: false };
  }
 
  onMouseOver() {
    this.setState({ isHovered: true });
  }
 
  onMouseOut() {
    this.setState({ isHovered: false });
  }
 
  render() {
    return (
      <span
        onMouseOver={this.onMouseOver}
        onMouseOut={this.onMouseOut}
        onClick={this.props.onClose}
      >
        <div className={'circle ' + this.props.tabState}>
          {this.state.isHovered ? '×' : null}
        </div>
      </span>
    );
  }
}
 
TabStatusIcon.propTypes = propTypes;
export default TabStatusIcon;