|
|
@ -1,20 +1,91 @@ |
|
|
|
import { |
|
|
|
import { |
|
|
|
|
|
|
|
Breakpoint, |
|
|
|
|
|
|
|
tabClasses as muiTabClasses, |
|
|
|
Tabs as MUITabs, |
|
|
|
Tabs as MUITabs, |
|
|
|
tabsClasses as muiTabsClasses, |
|
|
|
tabsClasses as muiTabsClasses, |
|
|
|
TabsProps as MUITabsProps, |
|
|
|
useMediaQuery, |
|
|
|
|
|
|
|
useTheme, |
|
|
|
} from '@mui/material'; |
|
|
|
} from '@mui/material'; |
|
|
|
import { FC } from 'react'; |
|
|
|
import { FC, useCallback, useMemo } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
import { BLUE, BORDER_RADIUS } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
import { BLUE, BORDER_RADIUS } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
const Tabs: FC<MUITabsProps> = ({ |
|
|
|
const TABS_MIN_HEIGHT = '1em'; |
|
|
|
|
|
|
|
const TABS_VERTICAL_MIN_HEIGHT = '1.8em'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Tabs: FC<TabsProps> = ({ |
|
|
|
|
|
|
|
orientation: rawOrientation, |
|
|
|
variant = 'fullWidth', |
|
|
|
variant = 'fullWidth', |
|
|
|
...restTabsProps |
|
|
|
...restTabsProps |
|
|
|
}) => ( |
|
|
|
}) => { |
|
|
|
|
|
|
|
const theme = useTheme(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bp = useCallback( |
|
|
|
|
|
|
|
(breakpoint: Breakpoint) => theme.breakpoints.up(breakpoint), |
|
|
|
|
|
|
|
[theme], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bpxs = useMediaQuery(bp('xs')); |
|
|
|
|
|
|
|
const bpsm = useMediaQuery(bp('sm')); |
|
|
|
|
|
|
|
const bpmd = useMediaQuery(bp('md')); |
|
|
|
|
|
|
|
const bplg = useMediaQuery(bp('lg')); |
|
|
|
|
|
|
|
const bpxl = useMediaQuery(bp('xl')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mapToBreakpointUp: [Breakpoint, boolean][] = useMemo( |
|
|
|
|
|
|
|
() => [ |
|
|
|
|
|
|
|
['xs', bpxs], |
|
|
|
|
|
|
|
['sm', bpsm], |
|
|
|
|
|
|
|
['md', bpmd], |
|
|
|
|
|
|
|
['lg', bplg], |
|
|
|
|
|
|
|
['xl', bpxl], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[bplg, bpmd, bpsm, bpxl, bpxs], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const orientation = useMemo(() => { |
|
|
|
|
|
|
|
let result: TabsOrientation | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof rawOrientation === 'object') { |
|
|
|
|
|
|
|
mapToBreakpointUp.some(([breakpoint, isUp]) => { |
|
|
|
|
|
|
|
if (isUp && rawOrientation[breakpoint]) { |
|
|
|
|
|
|
|
result = rawOrientation[breakpoint]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return !isUp; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result = rawOrientation; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
}, [mapToBreakpointUp, rawOrientation]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
<MUITabs |
|
|
|
<MUITabs |
|
|
|
{...restTabsProps} |
|
|
|
{...restTabsProps} |
|
|
|
|
|
|
|
orientation={orientation} |
|
|
|
variant={variant} |
|
|
|
variant={variant} |
|
|
|
sx={{ |
|
|
|
sx={{ |
|
|
|
|
|
|
|
minHeight: TABS_MIN_HEIGHT, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[`&.${muiTabsClasses.vertical}`]: { |
|
|
|
|
|
|
|
minHeight: TABS_VERTICAL_MIN_HEIGHT, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[`& .${muiTabClasses.root}`]: { |
|
|
|
|
|
|
|
alignItems: 'flex-start', |
|
|
|
|
|
|
|
minHeight: TABS_VERTICAL_MIN_HEIGHT, |
|
|
|
|
|
|
|
paddingLeft: '2em', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[`& .${muiTabsClasses.indicator}`]: { |
|
|
|
|
|
|
|
right: 'initial', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[`& .${muiTabClasses.root}`]: { |
|
|
|
|
|
|
|
minHeight: TABS_MIN_HEIGHT, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
[`& .${muiTabsClasses.indicator}`]: { |
|
|
|
[`& .${muiTabsClasses.indicator}`]: { |
|
|
|
backgroundColor: BLUE, |
|
|
|
backgroundColor: BLUE, |
|
|
|
borderRadius: BORDER_RADIUS, |
|
|
|
borderRadius: BORDER_RADIUS, |
|
|
@ -22,5 +93,6 @@ const Tabs: FC<MUITabsProps> = ({ |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default Tabs; |
|
|
|
export default Tabs; |
|
|
|