File size: 4,897 Bytes
8db04af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { LucideIcon, TrendingUp, TrendingDown, Minus } from "lucide-react";
import { cn } from "../utils/cn";

interface StatCardProps {
  title: string;
  value: string | number;
  icon: LucideIcon;
  iconColor?: "indigo" | "emerald" | "amber" | "rose" | "teal" | "blue" | "purple";
  change?: {
    value: string;
    isPositive?: boolean | null;
    period?: string;
  };
  subtitle?: string;
  progress?: number; // 0 to 100
  className?: string;
}

const colorMap = {
  indigo: {
    bg: "bg-indigo-500/10",
    border: "border-indigo-500/20",
    text: "text-indigo-400",
    glow: "group-hover:border-indigo-500/40",
  },
  emerald: {
    bg: "bg-emerald-500/10",
    border: "border-emerald-500/20",
    text: "text-emerald-400",
    glow: "group-hover:border-emerald-500/40",
  },
  amber: {
    bg: "bg-amber-500/10",
    border: "border-amber-500/20",
    text: "text-amber-400",
    glow: "group-hover:border-amber-500/40",
  },
  rose: {
    bg: "bg-rose-500/10",
    border: "border-rose-500/20",
    text: "text-rose-400",
    glow: "group-hover:border-rose-500/40",
  },
  teal: {
    bg: "bg-teal-500/10",
    border: "border-teal-500/20",
    text: "text-teal-400",
    glow: "group-hover:border-teal-500/40",
  },
  blue: {
    bg: "bg-blue-500/10",
    border: "border-blue-500/20",
    text: "text-blue-400",
    glow: "group-hover:border-blue-500/40",
  },
  purple: {
    bg: "bg-purple-500/10",
    border: "border-purple-500/20",
    text: "text-purple-400",
    glow: "group-hover:border-purple-500/40",
  },
};

export default function StatCard({

  title,

  value,

  icon: Icon,

  iconColor = "indigo",

  change,

  subtitle,

  progress,

  className,

}: StatCardProps) {
  const c = colorMap[iconColor];

  return (
    <div

      className={cn(

        "group relative bg-white/5 hover:bg-white/10 backdrop-blur-md border border-white/10 rounded-xl p-5 transition-all duration-300 shadow-[0_8px_32px_-8px_rgba(0,0,0,0.5)] overflow-hidden",

        className

      )}

    >

      <div className="absolute inset-0 bg-gradient-to-br from-white/[0.03] to-transparent pointer-events-none" />

      <div className="relative z-10 flex justify-between items-start">

        <div>

          <p className="text-xs font-semibold uppercase tracking-wider text-zinc-400 font-sans">

            {title}

          </p>

          <h3 className="text-2xl font-bold text-zinc-100 mt-2 tracking-tight font-mono">

            {value}

          </h3>

          {subtitle && (

            <p className="text-xs text-zinc-500 mt-1 font-sans">{subtitle}</p>

          )}

        </div>

        <div

          className={cn(

            "p-2.5 rounded-xl border transition-transform duration-300 group-hover:scale-110 shadow-[inset_0_1px_1px_rgba(255,255,255,0.1)]",

            c.bg,

            c.border

          )}

        >

          <Icon className={cn("w-5 h-5 drop-shadow-[0_0_8px_currentColor]", c.text)} />

        </div>

      </div>



      {progress !== undefined && (

        <div className="relative z-10 mt-4 space-y-1.5">

          <div className="flex justify-between text-[11px] text-zinc-400 font-sans font-medium">

            <span>Capacity</span>

            <span className="font-mono">{Math.round(progress)}%</span>

          </div>

          <div className="w-full h-1.5 bg-black/50 border border-white/5 rounded-full overflow-hidden">

            <div

              className={cn("h-full rounded-full transition-all duration-500", c.text.replace("text-", "bg-"))}

              style={{ width: `${Math.min(100, Math.max(0, progress))}%`, boxShadow: '0 0 10px currentColor' }}

            />

          </div>

        </div>

      )}



      {change && (

        <div className="relative z-10 mt-3.5 flex items-center text-xs font-medium font-sans">

          {change.isPositive === true && (

            <span className="flex items-center text-emerald-400 mr-1.5">

              <TrendingUp className="w-3.5 h-3.5 mr-0.5" />

              <span className="font-mono">{change.value}</span>

            </span>

          )}

          {change.isPositive === false && (

            <span className="flex items-center text-rose-400 mr-1.5">

              <TrendingDown className="w-3.5 h-3.5 mr-0.5" />

              <span className="font-mono">{change.value}</span>

            </span>

          )}

          {change.isPositive === null && (

            <span className="flex items-center text-zinc-400 mr-1.5">

              <Minus className="w-3.5 h-3.5 mr-0.5" />

              <span className="font-mono">{change.value}</span>

            </span>

          )}

          <span className="text-zinc-500 font-normal">

            {change.period || "vs last month"}

          </span>

        </div>

      )}

    </div>
  );
}