|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import type { LucideIcon } from 'lucide-react'; |
| 4 | +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; |
| 5 | +import { cn } from '@/lib/utils'; |
| 6 | + |
| 7 | +interface StatCardProps { |
| 8 | + title: string; |
| 9 | + value: React.ReactNode; |
| 10 | + icon?: LucideIcon; |
| 11 | + trend?: { |
| 12 | + label: string; |
| 13 | + icon?: LucideIcon; |
| 14 | + color?: string; |
| 15 | + }; |
| 16 | + color?: 'amber' | 'blue' | 'emerald' | 'purple' | 'primary'; |
| 17 | + variant?: 'default' | 'destructive'; |
| 18 | + className?: string; |
| 19 | +} |
| 20 | + |
| 21 | +const colorStyles = { |
| 22 | + amber: { gradient: 'from-amber-50/60', box: 'bg-primary/20', icon: 'text-primary' }, |
| 23 | + blue: { gradient: 'from-blue-50/60', box: 'bg-blue-100', icon: 'text-blue-600' }, |
| 24 | + emerald: { gradient: 'from-emerald-50/60', box: 'bg-emerald-100', icon: 'text-emerald-600' }, |
| 25 | + purple: { gradient: 'from-purple-50/60', box: 'bg-purple-100', icon: 'text-purple-600' }, |
| 26 | + primary: { gradient: 'from-primary/5', box: 'bg-primary/10', icon: 'text-primary' }, |
| 27 | +} as const; |
| 28 | + |
| 29 | +export function StatCard({ title, value, icon: Icon, trend, color, variant = 'default', className }: StatCardProps) { |
| 30 | + const isDestructive = variant === 'destructive'; |
| 31 | + const cfg = color ? colorStyles[color] : null; |
| 32 | + |
| 33 | + return ( |
| 34 | + <Card className={cn( |
| 35 | + "relative overflow-hidden border shadow-sm hover:shadow-md transition-shadow", |
| 36 | + isDestructive ? "bg-destructive/10 border-destructive/20" : "bg-card border-border", |
| 37 | + className |
| 38 | + )}> |
| 39 | + {cfg && !isDestructive && ( |
| 40 | + <div className={cn("absolute inset-0 bg-gradient-to-br pointer-events-none", cfg.gradient, "to-transparent")} /> |
| 41 | + )} |
| 42 | + <CardHeader className="flex flex-row items-center justify-between pb-2 relative"> |
| 43 | + <CardTitle className={cn( |
| 44 | + "font-semibold", |
| 45 | + isDestructive |
| 46 | + ? "text-sm text-destructive" |
| 47 | + : "text-xs text-muted-foreground uppercase tracking-wider" |
| 48 | + )}> |
| 49 | + {title} |
| 50 | + </CardTitle> |
| 51 | + {Icon && ( |
| 52 | + isDestructive ? ( |
| 53 | + <Icon className="h-4 w-4 text-destructive" /> |
| 54 | + ) : ( |
| 55 | + <div className={cn("w-8 h-8 rounded-lg flex items-center justify-center", cfg?.box)}> |
| 56 | + <Icon className={cn("h-4 w-4", cfg?.icon)} /> |
| 57 | + </div> |
| 58 | + ) |
| 59 | + )} |
| 60 | + </CardHeader> |
| 61 | + <CardContent className="p-3 sm:p-4 relative"> |
| 62 | + <div className={cn( |
| 63 | + "text-xl sm:text-2xl font-bold", |
| 64 | + isDestructive ? "text-destructive" : "text-foreground" |
| 65 | + )}> |
| 66 | + {value} |
| 67 | + </div> |
| 68 | + {trend && ( |
| 69 | + <p className={cn( |
| 70 | + "text-xs flex items-center mt-1.5 font-medium", |
| 71 | + trend.color || (isDestructive ? "text-destructive/80" : "text-muted-foreground") |
| 72 | + )}> |
| 73 | + {trend.icon && <trend.icon className="h-3 w-3 mr-1 shrink-0" />} |
| 74 | + {trend.label} |
| 75 | + </p> |
| 76 | + )} |
| 77 | + </CardContent> |
| 78 | + </Card> |
| 79 | + ); |
| 80 | +} |
0 commit comments