inogen/app/components/ui/metric-card.tsx
2026-10-18 18:12:59 +03:30

49 lines
1.8 KiB
TypeScript

import { formatNumber } from "~/lib/utils";
import { BaseCard } from "./base-card";
interface MetricCardProps {
title: string;
value: string | number;
percentValue?: string | number;
valueLabel?: string;
percentLabel?: string;
}
export function MetricCard({
title,
value,
percentValue,
valueLabel = "میلیون ریال",
percentLabel = "درصد به کل",
}: MetricCardProps) {
return (
<BaseCard title={title} className="h-full">
<div className="flex min-w-0 items-center justify-center flex-col">
<div className={`grid w-full min-w-0 items-center gap-2 h-full ${percentValue !== undefined ? "grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)]" : "grid-cols-1"}`}>
<div className="min-w-0 text-center">
<p dir="ltr" title={String(formatNumber(value))} className="max-w-full break-all text-[clamp(1.15rem,2.3vw,1.875rem)] leading-tight tabular-nums font-bold text-green-400">
{formatNumber(value)}
</p>
<div className="mt-1 break-words text-xs leading-5 text-gray-400 font-persian">
{valueLabel}
</div>
</div>
{percentValue !== undefined && (
<>
<span className="text-3xl font-thin text-gray-600">/</span>
<div className="min-w-0 text-center">
<p dir="ltr" title={`${formatNumber(percentValue)}%`} className="max-w-full break-all text-[clamp(1.15rem,2.3vw,1.875rem)] leading-tight tabular-nums font-bold text-green-400">
{formatNumber(percentValue)}%
</p>
<div className="mt-1 break-words text-xs leading-5 text-gray-400 font-persian">
{percentLabel}
</div>
</div>
</>
)}
</div>
</div>
</BaseCard>
);
}