All files / app/components/TabBar TabBar.tsx

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 7/7

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 4210x 10x   199x                         29x         29x 3x                           106x          
import { TabList } from "@mui/lab";
import { styled, Tab } from "@mui/material";
 
const StyledTab = styled(Tab)(({ theme }) => ({
  [theme.breakpoints.down("md")]: {
    overflow: "visible",
    margin: `0 ${theme.spacing(2)}`,
  },
}));
 
export interface TabBarProps<T extends Record<string, React.ReactNode>> {
  ariaLabel: string;
  labels: T;
  setValue: (value: keyof T) => void;
}
 
export default function TabBar<T extends Record<string, React.ReactNode>>({
  ariaLabel,
  setValue,
  labels,
}: TabBarProps<T>) {
  const handleChange = (event: React.SyntheticEvent, newValue: keyof T) => {
    setValue(newValue);
  };
 
  return (
    <TabList
      aria-label={ariaLabel}
      onChange={handleChange}
      indicatorColor="primary"
      textColor="primary"
      scrollButtons="auto"
      allowScrollButtonsMobile
      variant="scrollable"
    >
      {Object.entries(labels).map(([value, label]) => (
        <StyledTab key={value} label={label} value={value} />
      ))}
    </TabList>
  );
}