perplexity-hackathon-LawMitra / perplexity_hackathon / legal-chat-pwa / src / components / shared / StatsCard.tsx
StatsCard.tsx
Raw
'use client';

import React from 'react';
import { IconType } from 'react-icons';

interface StatsCardProps {
  title: string;
  value: number;
  icon: IconType;
  color: 'blue' | 'green' | 'yellow' | 'red';
  trend?: {
    value: number;
    isPositive: boolean;
  };
}

const colorClasses = {
  blue: 'bg-blue-50 text-blue-500',
  green: 'bg-green-50 text-green-500',
  yellow: 'bg-yellow-50 text-yellow-500',
  red: 'bg-red-50 text-red-500',
};

export function StatsCard({ title, value, icon: Icon, color, trend }: StatsCardProps) {
  return (
    <div className="relative overflow-hidden rounded-xl bg-white p-6 shadow-lg transition-all hover:shadow-xl">
      <div className="flex items-center justify-between">
        <div>
          <p className="text-sm font-medium text-gray-500">{title}</p>
          <div className="mt-2 flex items-baseline">
            <p className="text-2xl font-semibold text-gray-900">{value}</p>
            {trend && (
              <span
                className={`ml-2 text-sm font-medium ${
                  trend.isPositive ? 'text-green-600' : 'text-red-600'
                }`}
              >
                {trend.isPositive ? '↑' : '↓'} {trend.value}%
              </span>
            )}
          </div>
        </div>
        <div className={`rounded-lg p-3 ${colorClasses[color]}`}>
          <Icon className="h-6 w-6" />
        </div>
      </div>
      <div
        className={`absolute bottom-0 left-0 h-1 w-full bg-gradient-to-r ${
          color === 'blue'
            ? 'from-blue-400 to-blue-600'
            : color === 'green'
            ? 'from-green-400 to-green-600'
            : color === 'yellow'
            ? 'from-yellow-400 to-yellow-600'
            : 'from-red-400 to-red-600'
        }`}
      />
    </div>
  );
}