import React from 'react'; import classNames from 'classnames'; interface ITab { label: string; render(): JSX.Element; } interface ITabsProps { tabs: Array; active: number; } interface ITabsState { active: number; } export class NavTabs extends React.Component { static propTypes: any; static defaultProps: any; constructor(props) { super(props); this.state = {active: props.active || 0}; this.selectTab = this.selectTab.bind(this); } selectTab(index: number) { this.setState({active: index}); } render() { const tabs = this.props.tabs.map((tab, i) => { const className = classNames('nav-tabs__tab', { 'nav-tabs__tab--active': this.state.active === i, }); return (
  • ); }); return (
      {tabs}
    {this.props.tabs[this.state.active].render()}
    ); } }