All files / app/components/TabBar TabBar.tsx

100% Statements 12/12
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10

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 4911x 11x 11x   30x                             11x         62x 62x 7x   62x                   209x                    
import { Tab } from "@material-ui/core";
import { TabList } from "@material-ui/lab";
import makeStyles from "utils/makeStyles";
 
export const useStyles = makeStyles((theme) => ({
  messagesTab: {
    [theme.breakpoints.down("sm")]: {
      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 classes = useStyles();
  const handleChange = (event: unknown, newValue: keyof T) => {
    setValue(newValue);
  };
  return (
    <TabList
      aria-label={ariaLabel}
      onChange={handleChange}
      indicatorColor="primary"
      textColor="primary"
      scrollButtons="auto"
      variant="scrollable"
    >
      {Object.entries(labels).map(([value, label]) => (
        <Tab
          key={value}
          label={label}
          value={value}
          className={classes.messagesTab}
        />
      ))}
    </TabList>
  );
}