-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStatsBox.tsx
More file actions
76 lines (71 loc) · 2.04 KB
/
Copy pathStatsBox.tsx
File metadata and controls
76 lines (71 loc) · 2.04 KB
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 React from 'react';
export type ColorVariant = 'green' | 'gray' | 'red' | 'default';
export interface StatsBoxProps {
icon: string;
alt: string;
stats: string | number;
description: string;
className?: string;
variant?: ColorVariant;
}
const getVariantStyles = (variant: ColorVariant) => {
const iconBgMap: Record<ColorVariant, string> = {
green: 'bg-[rgba(34,197,94,0.1)]',
gray: 'bg-[rgba(107,114,128,0.1)]',
red: 'bg-[rgba(246,59,59,0.1)]',
default: 'bg-[rgba(0,0,0,0.04)]',
};
const statColorMap: Record<ColorVariant, string> = {
green: 'text-[#16a34a]',
gray: 'text-[#4b5563]',
red: 'text-[#eb2525]',
default: 'text-[#111827]',
};
return {
iconBg: iconBgMap[variant],
statColor: statColorMap[variant],
};
};
const StatsBox: React.FC<StatsBoxProps> = ({
icon,
alt,
stats,
description,
className = '',
variant = 'default',
}) => {
const { iconBg, statColor } = getVariantStyles(variant);
return (
<div
className={`flex items-center p-5 px-6 min-w-45 bg-white rounded-lg transition-all duration-200 ${className}`}
>
<div className="flex items-center justify-center mr-4 shrink-0">
{icon ? (
<div
className={`rounded-full w-10 h-10 flex items-center justify-center ${iconBg} transition-all duration-200`}
>
<img
className="w-6 h-6 object-contain"
src={icon}
alt={alt}
width={40}
height={40}
/>
</div>
) : (
<div
className={`rounded-full w-10 h-10 flex items-center justify-center ${iconBg} transition-all duration-200`}
aria-hidden="true"
/>
)}
</div>
<div className="flex flex-col items-center text-center w-full">
<p className={`text-2xl font-semibold m-0 leading-tight ${statColor}`}>
{stats}
</p>
<p className="text-sm text-[#6b7280] m-0 mt-1">{description}</p>
</div>
</div>
);
};
export default StatsBox;