All files / header index.js

70% Statements 7/10
100% Branches 2/2
100% Functions 0/0
70% Lines 7/10
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  1x 1x 1x                                                           9x 3x 3x     3x                                              
 
import React from 'react'
import classnames from 'classnames'
import Icon from '../icon/'
 
/**
 * Header component
 */
export default class Header extends React.Component {
 
  state = {
    hasShadow: false
  }
 
  static propTypes = {
    title: React.PropTypes.string,
    subtitle: React.PropTypes.string
  }
 
  componentDidMount () {
    window.addEventListener('scroll', this.onScroll)
  }
 
  componentWillUnmount () {
    window.removeEventListener('scroll', this.onScroll)
  }
 
  onScroll = () => {
    this.setState({
      hasShadow: window.scrollY > 0
    })
  }
 
  render () {
    const {title, subtitle, children} = this.props
    const klass = classnames({
      'Header--shadow': this.state.hasShadow
    })
    return (
      <header className={klass}>
        <div className='Header'>
          <div className='Header-block'>
            <span className='Header-title'>
              {title}
            </span>
            {subtitle &&
              <span className='Header-subtitle'>
                <Icon.ChevronRight className='Header-chevron' />
                {subtitle}
              </span>
            }
          </div>
          <div className='Header-block'>
            {children}
          </div>
        </div>
      </header>
    )
  }
 
}