Created
April 6, 2017 04:09
-
-
Save grantsheppard/9404c96f13f8761a228c9cc86b31ca67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tabs extends React.Component { | |
static propTypes = { | |
data: React.PropTypes.array.isRequired | |
} | |
state = { | |
activeTabIndex: 0 | |
} | |
handleTabClick(activeTabIndex) { | |
this.setState({ activeTabIndex }) | |
} | |
renderTabs() { | |
return this.props.data.map((tab, index) => { | |
return ( | |
<div onClick={() => this.handleTabClick(index)}>{tab.name}</div> | |
) | |
}) | |
} | |
renderPanel() { | |
const tab = this.props.data[this.state.activeTabIndex] | |
return ( | |
<div><p>{tab.description}</p></div> | |
) | |
} | |
render() { | |
return ( | |
<div> | |
<div> | |
{this.renderTabs()} | |
</div> | |
<div> | |
{this.renderPanel()} | |
</div> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment