All files / src/components/common/StatCard NewMobileStatCard.tsx

0% Statements 0/11
0% Branches 0/12
0% Functions 0/6
0% Lines 0/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 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                                                                                                                                                                                                             
import { Box, Stack, styled } from "@mui/material";
import { Text } from "@common/Text";
import { palette } from "@palette";
import Grid from "@mui/material/Grid";
import NewStatsTitle from "@common/NewStats/NewStatsTitle";
import { ViewAnalyticsLink } from "./ViewAnalyticsLink";
import { StatCardProps } from "./types";
import { parseAmount } from "@utils/index";
 
const NewMobileStatCard = ({
  mainStat,
  stats,
  actions,
  onOpenAnalytics,
  AnalyticsIcon,
  mainStatTitleProps,
  statTextProps,
  statValueProps,
  labelProps,
  color,
}: StatCardProps) => {
  return (
    <Stack gap={2} alignItems="stretch">
      <StyledContainer>
        <NewStatsTitle
          margin="auto"
          value={mainStat.value}
          isAmount={mainStat.isAmount}
          fontSize={32}
          labelStyle={{ fontSize: 24 }}
          isMainTitle
          color={color}
          currencyVisible={false}
        ></NewStatsTitle>
        <MainStatTitle {...mainStatTitleProps}>
          {mainStat.title}
          {mainStat.isAmount && <span> (USD)</span>}
        </MainStatTitle>
      </StyledContainer>
      {onOpenAnalytics && (
        <ViewAnalyticsLink
          labelProps={labelProps}
          onClick={onOpenAnalytics}
          Icon={AnalyticsIcon}
        />
      )}
      <Stack spacing={1}>
        {stats.map(({ isAmount, title, value, percent }, index) => {
          return (
            <Grid
              key={index}
              container
              spacing={1}
              justifyContent="space-between"
              sx={{ m: 0, pr: 1 }}
            >
              <StatText {...statTextProps}>
                {title}
                {percent && ` (\u0025)`}
                {isAmount && " (USD)"}
              </StatText>
              <StatValue {...statValueProps}>
                {isAmount || percent ? parseAmount(value) : value}
              </StatValue>
            </Grid>
          );
        })}
      </Stack>
      {actions}
    </Stack>
  );
};
 
export default NewMobileStatCard;
 
const StatText = styled(Text)(() => ({
  fontSize: 14,
  fontWeight: 350,
  lineHeight: "16.8px",
  color: palette.neutral[70],
}));
 
const StatValue = styled(Text)(() => ({
  fontSize: 18,
  fontWeight: 300,
  lineHeight: "16.8px",
  color: palette.neutral[80],
}));
 
const MainStatTitle = styled(Text)(() => ({
  fontSize: 18,
  fontWeight: 400,
  lineHeight: "16.8px",
  textAlign: "center",
  color: palette.neutral[80],
}));
 
const StyledContainer = styled(Box)(() => ({
  display: "flex",
  flexDirection: "column",
  justifyContent: "space-between",
}));