Spaces:
Runtime error
Runtime error
File size: 1,746 Bytes
2a60e5d | 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 | import React from 'react';
import { formatCurrency, formatPercent, getChangeColor } from '../utils/helpers';
import { TrendingUp, TrendingDown } from 'lucide-react';
const StatCard = ({
title,
value,
change,
changePercent,
icon: Icon,
isCurrency = true,
prefix = '',
suffix = ''
}) => {
const isPositive = change >= 0;
const TrendIcon = isPositive ? TrendingUp : TrendingDown;
return (
<div className="glass-card p-6 animate-fade-in">
<div className="flex items-start justify-between">
<div>
<p className="text-sm text-gray-400 mb-1">{title}</p>
<p className="text-2xl font-bold">
{prefix}
{isCurrency ? formatCurrency(value) : value}
{suffix}
</p>
</div>
{Icon && (
<div className="p-3 rounded-xl bg-primary-500/20">
<Icon className="w-6 h-6 text-primary-400" />
</div>
)}
</div>
{(change !== undefined || changePercent !== undefined) && (
<div className="flex items-center gap-2 mt-4">
<div className={`flex items-center gap-1 px-2 py-1 rounded-lg ${
isPositive ? 'bg-success-500/20' : 'bg-danger-500/20'
}`}>
<TrendIcon className={`w-4 h-4 ${getChangeColor(change)}`} />
<span className={`text-sm font-medium ${getChangeColor(change)}`}>
{formatPercent(changePercent)}
</span>
</div>
{change !== undefined && (
<span className={`text-sm ${getChangeColor(change)}`}>
{change >= 0 ? '+' : ''}{formatCurrency(change)}
</span>
)}
</div>
)}
</div>
);
};
export default StatCard;
|