aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/tab-bar.js
blob: 0edced119236ba9be88f7242c627a54a7fdfa13d (plain) (blame)
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
const { Component } = require('react')
const h = require('react-hyperscript')
const PropTypes = require('react').PropTypes
const classnames = require('classnames')

class TabBar extends Component {
  constructor (props) {
    super(props)
    const { defaultTab, tabs } = props

    this.state = {
      subview: defaultTab || tabs[0].key,
    }
  }

  render () {
    const { tabs = [], tabSelected } = this.props
    const { subview } = this.state

    return (
      h('.tab-bar', {}, [
        tabs.map((tab) => {
          const { key, content } = tab
          return h('div', {
            className: classnames('tab-bar__tab pointer', {
              'tab-bar__tab--active': subview === key,
            }),
            onClick: () => {
              this.setState({ subview: key })
              tabSelected(key)
            },
            key,
          }, content)
        }),
        h('div.tab-bar__tab.tab-bar__grow-tab'),
      ])
    )
  }
}

TabBar.propTypes = {
  defaultTab: PropTypes.string,
  tabs: PropTypes.array,
  tabSelected: PropTypes.func,
}

module.exports = TabBar