import * as React from 'react' import * as Styled from './index.style' interface TabsProps { defaultValue?: string | number, value?: string | number, onChange?: (key: string) => void, children: React.ReactNode[] | null, innerRef?: any, color?: string, navHeight?: number, itemHeight?: number, activeColor?: string, navStyle?: React.CSSProperties, } interface TabPaneProps { title: string | React.ReactNode, value: string | number, children: React.ReactNode, } class TabPaneComponent extends React.Component { render() { const { children } = this.props; return(
{children}
) } } class TabsComponent extends React.Component { state = { activeValue: this.props.defaultValue ?? '' } element: any handleChange = (e: React.ChangeEvent) => { this.setState({ value: e.target.value }) this.props.onChange?.(e.target.value) } componentWillReceiveProps(nextProps: Readonly, nextContext: any): void { const newValue = nextProps.value; const oldValue = this.state.activeValue; if (newValue && newValue !== oldValue) { this.setState({ activeValue: newValue, }) } } public render() { const { children, color, navHeight, itemHeight, activeColor, navStyle } = this.props; const { activeValue } = this.state; return ( { children && children.length > 1 && ( {children && children.map((item: any) => ( { this.setState({ activeValue: item.props.value }) }} activeColor={activeColor} height={itemHeight} navHeight={navHeight} total={children.length} selected={activeValue === item.props.value} > { item.props.title } ))} ) } {children && children.map((child: any) => { if (child.props.value !== activeValue) return undefined; return child.props.children; })} ) } } const TabPane = React.memo(TabPaneComponent); const Tabs = React.forwardRef((props: TabsProps, ref: any) => { return }); export { Tabs, TabPane, }