import classnames from 'classnames'; import { observer } from 'mobx-react'; import { Children, Component, type ReactElement, type ReactPortal, } from 'react'; import type { IProps as TabItemProps } from './TabItem'; interface IProps { children: | ReactElement | (boolean | ReactElement)[]; active?: number; } interface IState { active: number; } @observer class Tab extends Component { constructor(props: IProps) { super(props); this.state = { active: this.props.active || 0, }; } switchTab(index: number): void { this.setState({ active: index }); } render(): ReactElement { const { children: childElements } = this.props; const children = Children.toArray(childElements); // removes all null values if (children.length === 1) { return
{children}
; } return (
{Children.map(children, (child, i) => ( ))}
{Children.map(children, (child, i) => (
{child}
))}
); } } export default Tab;