-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphContainer.tsx
56 lines (53 loc) · 1.4 KB
/
GraphContainer.tsx
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
import { T } from "@/components/ui/Typography";
import { cn } from "@/utils/cn";
import { BadgeDelta } from "@tremor/react";
type GraphContainerProps = {
title: string;
subTitle?: string;
children: React.ReactNode;
classname?: string;
badgeValue?: string;
};
const getDeltaType = (percentage: string): string => {
const percentageValue = Number.parseFloat(percentage.replace("%", ""));
if (percentageValue <= -50) {
return "decrease";
} if (-50 < percentageValue && percentageValue < 0) {
return "moderateDecrease";
} if (percentageValue === 0) {
return "unchanged";
} if (0 < percentageValue && percentageValue <= 50) {
return "moderateIncrease";
}
return "increase";
};
export function GraphContainer({
title,
subTitle,
children,
classname,
badgeValue,
}: GraphContainerProps) {
return (
<div className={cn("overflow-hidden", classname)}>
<div className="px-[18px] flex justify-between py-4 w-full ">
<div className="">
<T.H4 >{title}</T.H4>
<T.P >{subTitle}</T.P>
</div>
{badgeValue && (
<BadgeDelta
deltaType={getDeltaType(badgeValue)}
size="xs"
className="h-fit"
>
{badgeValue}
</BadgeDelta>
)}
</div>
<div className="px-5 pb-6 h-full ">
<div className="h-full ">{children}</div>
</div>
</div>
);
}