All files / components/tabs index.js

0% Statements 0/60
0% Branches 0/35
0% Functions 0/14
0% Lines 0/2
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                                                                                                   
import React, { Component } from 'react'
import PropTypes from 'prop-types'
 
import Header from './header'
 
import StyledTabs from './tabs.styled'
 
class Tabs extends Component {
  state = {
    active: 0
  }
 
  componentWillMount () {
    const { children } = this.props
    const panes = React.Children.toArray(children)
    panes.map((pane, key) => {
      pane.props.active && this.setState({ active: key })
    })
  }
 
  changeActive = (key) => {
    this.setState({ active: key })
  }
 
  render () {
    const { active } = this.state
    const { children, full } = this.props
    const panes = React.Children.toArray(children)
 
    return (
      <StyledTabs>
        <Header
          tabs={panes}
          activeTab={active}
          onChangeTab={this.changeActive}
          full={full}
        />
        {panes[active]}
      </StyledTabs>
    )
  }
}
 
Tabs.propTypes = {
  children: PropTypes.node.isRequired
}
 
export { TabPane } from './tab-pane'
export { Tabs }