All files / src/components/common/Tabs Tabs.tsx

83.33% Statements 5/6
75% Branches 6/8
66.66% Functions 2/3
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                        15x                                                 4x       4x 30x   30x                              
import Box, { BoxProps } from "@mui/material/Box";
import {
  Tab,
  Tabs as MuiTabs,
  TabProps as MuiTabProps,
  TabsProps as MuiTabsProps,
} from "@mui/material";
 
type TabPanelProps = BoxProps & {
  index: number;
  value: number;
};
 
type TabsProps = MuiTabsProps & {
  right?: boolean;
  size?: "medium" | "large";
  gap?: string | number;
};
 
export default function Tabs(props: TabsProps) {
  return (
    <MuiTabs
      sx={{
        ...(props.right && {
          "& .MuiTabs-flexContainer": {
            justifyContent: "flex-end",
          },
        }),
        ...(props.gap && {
          "& .MuiTabs-flexContainer": {
            gap: props.gap,
          },
        }),
        ...(props.size === "large" && {
          "& .MuiTab-root": {
            height: 44,
          },
        }),
        ...props.sx,
      }}
      {...props}
    />
  );
}
 
export const ButtonTab = ({ className, ...props }: MuiTabProps) => {
  return <Tab className={`MuiButtonTab-root ${className}`} {...props} />;
};
 
export const TabPanel = (props: TabPanelProps) => {
  const { children, value, index, sx, ...other } = props;
 
  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
    >
      {value === index && (
        <Box sx={{ py: 2, ...sx }} {...other}>
          {children}
        </Box>
      )}
    </div>
  );
};