import * as React from "react"; import { cn } from "../lib/utils"; import { Card } from "./card"; export interface StatCardProps extends React.HTMLAttributes { variant?: "default" | "sandbox"; title: string; value: string | number; subtitle?: string; icon?: React.ReactNode; trend?: { value: number; label?: string; }; } const StatCard = React.forwardRef( ( { className, variant = "default", title, value, subtitle, icon, trend, ...props }, ref, ) => { const iconColors = { default: "text-muted-foreground", sandbox: "text-[var(--accent-text)]", }; const trendColors = { positive: "text-[var(--surface-success-text)]", negative: "text-[var(--surface-danger-text)]", neutral: "text-muted-foreground", }; const trendStatus = trend ? trend.value > 0 ? "positive" : trend.value < 0 ? "negative" : "neutral" : null; return (

{title}

{value}

{/* A token, never `opacity-70` over the muted tone: a translucent foreground renders as the token COMPOSITED over whatever plane sits behind it, so the same class lands a different colour — and a different contrast ratio — on a card than on the canvas. */} {subtitle && (

{subtitle}

)} {trend && trendStatus && (
{trend.value > 0 ? "↑" : trend.value < 0 ? "↓" : "→"} {Math.abs(trend.value)}% {trend.label && ( {trend.label} )}
)}
{icon && (
{icon}
)}
); }, ); StatCard.displayName = "StatCard"; export { StatCard };