All files / src/components/common/TableFilters DefaultSelectorOption.tsx

22.22% Statements 2/9
0% Branches 0/10
0% Functions 0/3
25% Lines 2/8

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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                                76x                                                                                               76x                                      
import { TickIcon } from "@assets/icons";
import { Image } from "@common/StyledImage/Image";
import { TruncateText } from "@common/Text";
import { Stack, styled } from "@mui/material";
import { palette } from "@palette";
import React from "react";
 
type SelectorOptionProps = {
  name: string;
  image: string;
  selected: boolean;
  handleDeselect: () => void;
  onClick?: () => void;
  customPlaceholder?: React.ReactElement;
};
 
const SelectorOption = ({
  name,
  image,
  selected,
  customPlaceholder,
  handleDeselect,
  onClick,
}: SelectorOptionProps) => {
  const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
    event.stopPropagation();
    if (selected) {
      handleDeselect();
    } else {
      onClick && onClick();
    }
  };
 
  return (
    <Container onClick={handleClick}>
      {customPlaceholder && !image ? (
        customPlaceholder
      ) : (
        <Image
          width={32}
          height={32}
          src={image}
          alt={name}
          sx={{ borderRadius: "2px" }}
        />
      )}
      <TruncateText
        lineClamp={1}
        color={palette.black[100]}
        lineHeight="16.8px"
        fontWeight="book"
        flexGrow={1}
      >
        {name}
      </TruncateText>
      {selected && (
        <Stack width={32} height={32} alignSelf="flex-end" alignItems="center">
          <TickIcon stroke={palette.black[100]} width={15} height={15} />
        </Stack>
      )}
    </Container>
  );
};
 
const Container = styled(Stack)(() => ({
  flexDirection: "row",
  justifyContent: "stretch",
  alignItems: "center",
  gap: "8px",
  padding: "4px 8px",
  borderRadius: "4px",
  background: "inherit",
 
  "&:active": {
    background: palette.liftedWhite[100],
  },
  "&:hover": {
    background: palette.liftedWhite[100],
    cursor: "pointer",
  },
}));
 
export default SelectorOption;