import { Box, Tab, Tabs } from '@mui/material'; import { FC } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { ITabListProps, ITabPanel } from './Types'; import { useStyles } from './style'; const TabPanel = (props: ITabPanel) => { const { children, value, index, className = '', ...other } = props; return ( ); }; const a11yProps = (index: number) => { return { id: `tab-${index}`, 'aria-controls': `tabpanel-${index}`, }; }; const RouteTabList: FC = props => { const { tabs, activeIndex = 0, wrapperClass = '' } = props; const classes = useStyles(); const navigate = useNavigate(); const location = useLocation(); const handleChange = (event: any, newValue: any) => { const newPath = location.pathname.split('/').slice(0, -1).join('/') + '/' + tabs[newValue].path; navigate(newPath); }; return (
}} value={activeIndex} onChange={handleChange} aria-label="tabs" > {tabs.map((tab, index) => ( ))} {tabs.map((tab, index) => ( {tab.component} ))}
); }; export default RouteTabList;