All files / src/shared/Tabs GiveLineTab.tsx

90.9% Statements 10/11
61.76% Branches 21/34
100% Functions 2/2
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 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140                                                736x 736x   736x 736x       736x 736x             736x                       736x                       736x                                     17x                                                                                                                
import { Stack } from "@mui/material";
import { GiveLineTabProps } from "./GiveTab.types";
import GiveText from "@shared/Text/GiveText";
import { useAppTheme } from "@theme/v2/Provider";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
 
export default function GiveLineTab({
  label,
  info,
  value,
  endItem,
  startItem,
  onClick,
  selected,
  hidden,
  disabled,
  tabSx,
  displayInfoOnHover,
  selectedTabSx,
  dataTestId,
  applyGradient = true,
  allowHoverWhenDisabled = false,
}: GiveLineTabProps) {
  const { palette } = useAppTheme();
  const { isDesktopView } = useCustomThemeV2();
 
  const defaultColor = palette.primitive?.neutral?.[100];
  const appliedColor = applyGradient
    ? palette.gradient?.["ocean-blue"]?.default
    : defaultColor;
 
  Iif (hidden) return null;
  const gradientTextStyle = {
    background: selectedTabSx?.textColor ?? appliedColor,
    WebkitBackgroundClip: "text",
    WebkitTextFillColor: "transparent",
    backgroundClip: "text",
    color: "transparent",
  };
  const gradientBorderStyle = {
    position: "relative",
    "&::after": {
      content: '""',
      position: "absolute",
      bottom: 0,
      left: 0,
      right: 0,
      height: "2px",
      background: selectedTabSx?.textColor ?? appliedColor,
    },
  };
  const hoverBorderStyle = {
    "&:hover::after": {
      content: '""',
      position: "absolute",
      bottom: 0,
      left: 0,
      right: 0,
      height: "2px",
      background: palette.border?.secondary,
    },
  };
 
  return (
    <Stack
      sx={{
        cursor: "pointer",
        ...(disabled && {
          cursor: "default",
          ...(!allowHoverWhenDisabled && { pointerEvents: "none" }),
        }),
        ...(selected
          ? gradientBorderStyle
          : {
              position: "relative",
              ...hoverBorderStyle,
            }),
        gap: "8px",
        paddingBottom: "16px",
        ...tabSx,
        ...(selected ? selectedTabSx : {}),
      }}
      onClick={() => !disabled && onClick?.(value)}
      data-testid={dataTestId}
    >
      <GiveTooltip
        width="compact"
        alignment="left"
        title={info}
        color="default"
        disableHoverListener={
          !displayInfoOnHover || (!isDesktopView && !allowHoverWhenDisabled)
        }
        placement="bottom-start"
      >
        <Stack
          direction="row"
          sx={{
            gap: "4px",
            alignItems: "center",
            justifyContent: "flex-start",
            "& p": {
              color: palette.text.secondary,
            },
            "&:hover": {
              "& p": { color: palette.text.primary },
            },
            ...(selected && {
              "& p": gradientTextStyle,
            }),
            ...(disabled && {
              "& p": {
                color: palette.text.tertiary,
              },
            }),
          }}
        >
          {startItem}
          {typeof label === "string" ? (
            <GiveText variant="bodyS" sx={{ whiteSpace: "nowrap" }}>
              {label}
            </GiveText>
          ) : (
            label
          )}
          {endItem}
        </Stack>
      </GiveTooltip>
      {info &&
        (!displayInfoOnHover ||
          (!isDesktopView && !allowHoverWhenDisabled)) && (
          <GiveText variant="bodyXS" color="secondary">
            {info}
          </GiveText>
        )}
    </Stack>
  );
}