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 | import { Text, TruncateText } from "@common/Text";
import { Stack } from "@mui/material";
import { palette } from "@palette";
type DonationKeyValueProps = {
title: string;
value?: string | number | React.ReactNode;
isAmount?: boolean;
highlight?: boolean;
};
const DonationKeyValue = ({
title,
value,
highlight,
isAmount = false,
}: DonationKeyValueProps) => {
return (
<Stack
direction="column"
gap="4px"
sx={{
...boxStyle,
backgroundColor: highlight
? palette.liftedWhite.main
: "inherit",
}}
>
<Text
color={palette.gray[300]}
variant="body"
lineHeight="17px"
fontWeight="light"
>
{title}
</Text>
<TruncateText
color={palette.black[100]}
variant="body"
lineHeight="17px"
fontWeight="book"
lineClamp={1}
>
{isAmount && typeof value === "number"
? getFormattedAmount(value)
: value
}
</TruncateText>
</Stack>
);
};
const getFormattedAmount = (amount: number) => {
const [dollars, cents] = `${amount.toFixed(2)}`.split(".");
return (
<span>
{Number(dollars).toLocaleString("en-US")}
<sup style={supStyle}>.{cents}</sup>
</span>
)
}
const supStyle = {
fontSize: "9px",
lineHeight: "12px",
verticalAlign: "4px",
}
const boxStyle = {
padding: "8px",
borderRadius: "8px",
};
export default DonationKeyValue;
|