import { Card, CardContent } from '@/components/ui/card'; import { TrendingUp, TrendingDown, Minus } from 'lucide-react'; import { cn } from '@/lib/utils'; /** * StatCard - 优化后的统计卡片组件 * * 优化点: * 1. 使用 dg-card 工具类替代硬编码样式 * 2. 添加 hover 效果和点击交互 * 3. 图标颜色通过主题变量映射 * 4. 趋势显示更直观 * 5. 添加 shimmer loading 效果支持 */ const colorClasses: Record = { blue: { bg: 'bg-[var(--dg-blue)]/10', icon: 'text-[var(--dg-blue)]', glow: 'shadow-[var(--dg-blue)]/10' }, emerald: { bg: 'bg-[var(--dg-green)]/10', icon: 'text-[var(--dg-green)]', glow: 'shadow-[var(--dg-green)]/10' }, amber: { bg: 'bg-[var(--dg-yellow)]/10', icon: 'text-[var(--dg-yellow)]', glow: 'shadow-[var(--dg-yellow)]/10' }, rose: { bg: 'bg-[var(--dg-red)]/10', icon: 'text-[var(--dg-red)]', glow: 'shadow-[var(--dg-red)]/10' }, purple: { bg: 'bg-[var(--dg-purple)]/10', icon: 'text-[var(--dg-purple)]', glow: 'shadow-[var(--dg-purple)]/10' }, cyan: { bg: 'bg-[var(--dg-cyan)]/10', icon: 'text-[var(--dg-cyan)]', glow: 'shadow-[var(--dg-cyan)]/10' }, orange: { bg: 'bg-[var(--dg-orange)]/10', icon: 'text-[var(--dg-orange)]', glow: 'shadow-[var(--dg-orange)]/10' }, }; interface StatCardProps { title: string; value: string | number; description?: string; icon: React.ElementType; trend?: 'up' | 'down' | 'neutral'; trendValue?: string; color: string; onClick?: () => void; loading?: boolean; } export function StatCard({ title, value, description, icon: Icon, trend, trendValue, color, onClick, loading = false, }: StatCardProps) { const colors = colorClasses[color] || colorClasses.blue; if (loading) { return (
); } const TrendIcon = trend === 'up' ? TrendingUp : trend === 'down' ? TrendingDown : Minus; const trendColor = trend === 'up' ? 'text-[var(--dg-green)]' : trend === 'down' ? 'text-[var(--dg-red)]' : 'text-[var(--dg-text-muted)]'; return (

{title}

{value}

{trend && trendValue && ( {trendValue} )}
{description && (

{description}

)}
); }