All files / src/shared GiveCircularProgress.tsx

100% Statements 6/6
80% Branches 4/5
100% Functions 2/2
100% Lines 6/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            353x           20x   20x                                                           353x               188x   188x                
import { Box, CircularProgress, CircularProgressProps } from "@mui/material";
import { useAppTheme } from "@theme/v2/Provider";
import { getJsonValue } from "@theme/v2/utils";
import { TMakePalette } from "@theme/v2/theme.builders";
 
type GradientColors = Exclude<keyof TMakePalette["gradient"], "aqua-horizon">;
const GiveGradientCircularProgress = ({
  gradient = "ocean-blue",
  ...spinnerProps
}: {
  gradient: GradientColors;
} & CircularProgressProps) => {
  const theme = useAppTheme();
 
  return (
    <Box>
      <svg width="0" height="0">
        <linearGradient id="linearSpinnerColors" x1="0" y1="0" x2="1" y2="1">
          <stop
            offset="0%"
            stopColor={getJsonValue(
              `tokens.${theme.palette.mode}.primitive.gradients.${gradient}.start`,
            )}
          />
          <stop
            offset="100%"
            stopColor={getJsonValue(
              `tokens.${theme.palette.mode}.primitive.gradients.${gradient}.end`,
            )}
          />
        </linearGradient>
      </svg>
      <CircularProgress
        sx={{
          circle: {
            stroke: "url(#linearSpinnerColors)",
          },
        }}
        {...spinnerProps}
      />
    </Box>
  );
};
 
const GiveCircularProgress = ({
  color,
  gradient,
  ...spinnerProps
}: CircularProgressProps & {
  color?: string;
  gradient?: GradientColors;
}) => {
  const isGradient = !color && gradient;
 
  return isGradient ? (
    <GiveGradientCircularProgress gradient={gradient} {...spinnerProps} />
  ) : (
    <CircularProgress sx={{ color }} {...spinnerProps} />
  );
};
 
export default GiveCircularProgress;