import { isElement } from 'react-is'; import cn from 'classnames'; import { Children } from 'react'; import isNil from '../utils/isNil'; import noop from '../utils/noop'; import LazyMount from '../utils/component/LazyMount'; import { IVerticalInnerTab, IVerticalTabsProps, IVerticalTab, ITabPanelProps, IVerticalTabPanelProps, } from './types'; import VerticalTabsNav from './components/tabs-nav/VerticalTabsNav'; import BaseTabs from './components/base/BaseTabs'; import { getTabDataFromChild } from './utils'; import TabDivide from './components/TabDivide'; import TabPanel from './components/TabPanel'; export class VerticalTabs extends BaseTabs< Id, IVerticalInnerTab, IVerticalTabPanelProps, IVerticalTabsProps > { static TabPanel = TabPanel; static Divide = TabDivide; static defaultProps: Partial> = { activeId: '', onChange: noop, unmountPanelOnHide: false, }; get tabsCls() { const { className } = this.props; return cn('zent-tabs', `zent-tabs-type__vertical`, className); } getTabDataListFromTabs( tabs: NonNullable>> ): Array> { const { activeId } = this.props; return tabs.map>(tab => { if ('divide' in tab) { return tab; } else { return { ...tab, actived: tab.key === activeId, }; } }); } getTabDataListFromChildren( children: NonNullable['children']> ): Array> { const { activeId } = this.props; return Children.map( children, ( child: React.ReactElement< React.PropsWithChildren> > ) => { if (!isElement(child)) { return null; } if ('divide' in child.props) { return { divide: true as const }; } return getTabDataFromChild( child as React.ReactElement< React.PropsWithChildren> >, activeId ); } ).filter(v => !isNil(v)); } renderNav(tabDataList: Array>) { const { onChange, scrollHeight } = this.props; return ( ); } renderTabPanel(tabItem: IVerticalInnerTab) { if ('divide' in tabItem) { return null; } const { unmountPanelOnHide } = this.props; return ( {tabItem.panelChildren} ); } } export default VerticalTabs;