import React, { useState } from 'react' import styles from './index.module.css' interface TabProps { titles: Array children: any, showIndex?: number, changeHandle?: Function } function Tab({ children, titles, showIndex = 1, changeHandle }: TabProps) { let [index, setIndex] = useState(showIndex - 1) if (!(children instanceof Array)) { children = [children] } if (titles.length < children.length) { let less = children.length - titles.length for (let i = 0; i < less; i++) { titles.push('Tab') } } const clickHandle = (i: number) => { setIndex(i) changeHandle && changeHandle(i + 1) } return (
{titles.map((title: string, i: number) => ( clickHandle(i)}> {title} ))}
{children.map((Fn: any, i: number) => (
{Fn}
))}
) } export default Tab