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 | import React, { memo } from "react";
import { Box, styled } from "@mui/material";
import { Text } from "@common/Text";
import { palette } from "@palette";
import Figure from "@common/Figure";
import { ITextProps } from "@common/Text/Text";
export type valuePropsType = ITextProps & {
sup?: boolean;
color?: string;
fontSize?: number;
};
export type StatProps = {
title: string | React.ReactNode;
value: string | number;
isAmount?: boolean;
percent?: boolean;
valueProps?: valuePropsType;
isTotal?: boolean;
ratio?: number | string | undefined;
hidden?: boolean;
};
const Stat = ({
title,
value,
isAmount,
percent,
valueProps,
ratio,
}: StatProps) => {
const { fontSize = 32, color, ...otherValueProps } = valueProps || {};
return (
<StyledRoot>
<Figure
value={value}
percent={percent}
fontSize={fontSize}
color={color}
lineHeight={"43.2px"}
isAmount={isAmount}
ratio={ratio}
{...otherValueProps}
/>
<TitleText variant="h3">
{title}
{isAmount && " (USD)"}
{percent && " (%)"}
</TitleText>
</StyledRoot>
);
};
const StyledRoot = styled(Box)(() => ({
display: "flex",
flexDirection: "column",
gap: 2,
overflow: "hidden",
}));
const TitleText = styled(Text)(() => ({
fontSize: 12,
fontWeight: 400,
lineHeight: "16px",
color: palette.gray[300],
flexGrow: 0,
whiteSpace: "nowrap",
}));
export default memo(Stat);
|