import { Children, Component } from 'react'; import PropTypes from 'prop-types'; import { observer } from 'mobx-react'; import classnames from 'classnames'; import { oneOrManyChildElements } from '../../../prop-types'; @observer class Tab extends Component { constructor(props) { super(props); this.state = { active: this.props.active }; } static propTypes = { children: oneOrManyChildElements.isRequired, active: PropTypes.number, }; static defaultProps = { active: 0, }; switchTab(index) { this.setState({ active: index }); } render() { const { children: childElements } = this.props; const children = childElements.filter(c => !!c); if (children.length === 1) { return
{children}
; } return (
{Children.map(children, (child, i) => ( ))}
{Children.map(children, (child, i) => (
{child}
))}
); } } export default Tab;