import React from 'react'; import { Tabs as MuiTabs, TabsActions, TabsClasses, TabScrollButtonProps } from '@mui/material'; import { Tab, TabProps } from './tab'; import { TabContext, TabsContext } from '../types/tabs.type'; import { TabPanel } from './panel'; import { PanelsContainer, TabsContainer } from './style'; export interface TabsProps { style?: React.CSSProperties, action?: React.Ref; allowScrollButtonsMobile?: boolean; centered?: boolean; classes?: Partial; indicatorColor?: 'secondary' | 'primary'; onChange?: (index: number) => void; orientation?: 'horizontal' | 'vertical'; ScrollButtonComponent?: React.ElementType; scrollButtons?: 'auto' | true | false; selectionFollowsFocus?: boolean; TabIndicatorProps?: React.HTMLAttributes; TabScrollButtonProps?: Partial; textColor?: 'secondary' | 'primary' | 'inherit'; value?: number; variant?: 'standard' | 'scrollable' | 'fullWidth'; visibleScrollbar?: boolean; children?: React.ReactElement[] | React.ReactElement, } export const Tabs: React.FC = ({ style, value, onChange, children, ...props }) => { const header = React.useRef(); const [selected, setSelected] = React.useState(value ? value : 0); const [context] = React.useState({ tabs: [] }); const [forceUpdate, setForceUpdate] = React.useState(false); React.useEffect(() => { if (children) { const tabs: TabContext[] = []; React.Children.map(children, child => { if (child.type === Tab) { tabs.push({ selector: child, content: child.props.children }) } }) context.tabs = tabs; setForceUpdate(!forceUpdate); } }, [children]) const handleSelectionChange = (event: React.SyntheticEvent, newValue: number) => { setSelected(newValue); if (onChange) { onChange(newValue); } }; return ( {children} { context.tabs.map((tab, index) => ( {tab.content} )) } ) }