All files / components/box box-tool.jsx

60% Statements 9/15
100% Branches 3/3
50% Functions 2/4
60% Lines 9/15
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          9x 9x 9x                         9x 9x 9x   3x   3x   3x            
import React from 'react';
import * as commonFuncs from '../../services/common-functions';
 
class BoxTool extends React.Component {
  constructor(props){
    super(props);
    this.toggleCollapse = this.toggleCollapse.bind(this);
    this.removeBox = this.removeBox.bind(this);
  }
  toggleCollapse(e) {
    let box = commonFuncs.findClosestElement(e.currentTarget, this.props.containerClass);
    let boxBody = box.children[1];
    let icon = e.currentTarget.children[0];
    commonFuncs.toggleBoxCollapse(box, boxBody, icon);
  }
  removeBox(e) {
    let box = commonFuncs.findClosestElement(e.currentTarget, this.props.containerClass);
    commonFuncs.removeBox(box);
  }
  render() {
    let button = '';
    let self = this;
    switch(this.props.toolType){
      case('expand'):
        return (<button className="btn btn-box-tool" data-widget="expand" onClick={self.toggleCollapse}><i className="fa fa-plus"></i></button>);
      case('collapse'):
        return (<button className="btn btn-box-tool" data-widget="collapse" onClick={self.toggleCollapse}><i className="fa fa-minus"></i></button>);
      case('remove'):
        return (<button className="btn btn-box-tool" data-widget="remove" onClick={self.removeBox}><i className="fa fa-times"></i></button>);
    }
  }
}
 
export default BoxTool;