assets/components/Header.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 70
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 46
c 0
b 0
f 0
dl 0
loc 70
rs 10
wmc 5
mnd 1
bc 1
fnc 4
bpm 0.25
cpm 1.25
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A Header.helpControlHandler 0 4 1
A Header.globalExitHandler 0 10 2
A Header.componentDidMount 0 6 1
A Header.render 0 22 1
1
import React from 'react'
2
import ReactSVG from 'react-svg'
3
import HelpControl from './HelpControl'
4
import AccountControl from './AccountControl'
5
import branding from '../images/branding.svg'
6
7
class Header extends React.Component {
8
  state = {
9
    helpControlActive: false
10
  }
11
12
  /**
13
   * Handle a click event on the help control.
14
   */
15
  helpControlHandler = () => {
16
    this.setState({
17
      helpControlActive: !this.state.helpControlActive,
18
      settingsControlActive: false
19
    })
20
  }
21
22
  /**
23
   * Handler closes help and settings control.
24
   */
25
  globalExitHandler = event => {
26
    let resetState = () => {
27
      this.setState({
28
        helpControlActive: false
29
      })
30
    }
31
32
    !document.getElementById('header__uicontrols').contains(event.target)
33
      ? resetState()
34
      : null
35
  }
36
37
  /**
38
   * Bind the global exit handler after the component mounts.
39
   */
40
  componentDidMount() {
41
    document.body.addEventListener('click', this.globalExitHandler)
42
  }
43
44
  /**
45
   * Render component.
46
   */
47
  render() {
48
    return (
49
      <div className="Header">
50
        <div className="header__inner">
51
          <a href="https://new.library.arizona.edu" className="logo">
52
            <ReactSVG path={branding} />
53
          </a>
54
          <div className="header__uicontrols-outer">
55
            <div className="header__uicontrols" id="header__uicontrols">
56
              <AccountControl />
57
              <HelpControl
58
                handler={this.helpControlHandler}
59
                open={this.state.helpControlActive}
60
              />
61
            </div>
62
          </div>
63
        </div>
64
      </div>
65
    )
66
  }
67
}
68
69
export default Header
70