DataStats.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use client';
  2. import { ArrowUp, ArrowDown, LucideIcon } from 'lucide-react';
  3. interface StatCardProps {
  4. title: string;
  5. value: string | number;
  6. icon: LucideIcon;
  7. trend?: string;
  8. trendUp?: boolean;
  9. color?: string;
  10. }
  11. export default function DataStats({ title, value, icon: Icon, trend, trendUp, color = "blue" }: StatCardProps) {
  12. const colorStyles: Record<string, string> = {
  13. blue: "bg-blue-50 text-blue-600",
  14. green: "bg-green-50 text-green-600",
  15. yellow: "bg-yellow-50 text-yellow-600",
  16. red: "bg-red-50 text-red-600",
  17. purple: "bg-purple-50 text-purple-600",
  18. };
  19. return (
  20. <div className="bg-white rounded-xl p-6 shadow-sm border border-slate-100">
  21. <div className="flex justify-between items-start">
  22. <div>
  23. <p className="text-sm font-medium text-slate-500 mb-1">{title}</p>
  24. <h3 className="text-2xl font-bold text-slate-900">{value}</h3>
  25. </div>
  26. <div className={`p-3 rounded-lg ${colorStyles[color] || colorStyles.blue}`}>
  27. <Icon size={24} />
  28. </div>
  29. </div>
  30. {trend && (
  31. <div className="mt-4 flex items-center text-sm">
  32. <span className={`flex items-center font-medium ${trendUp ? 'text-green-600' : 'text-red-600'}`}>
  33. {trendUp ? <ArrowUp size={16} className="mr-1" /> : <ArrowDown size={16} className="mr-1" />}
  34. {trend}
  35. </span>
  36. <span className="text-slate-400 ml-2">较上月</span>
  37. </div>
  38. )}
  39. </div>
  40. );
  41. }