StatCard
SM, under 950B gzippedA single KPI figure with an optional trend line.
- Category
- Data display
- Budget
- sm, single-purpose control
- Runtime deps
- None
Preview
Revenue$12,400+4% vs last week
This is the exact fixture the conformance suite renders in CI. Switch the language to see the component mirror and reformat.
Install
npx shadcn@latest add https://kata-ui-rho.vercel.app/r/stat-card.jsonCopies the source into your project. Pulls in 1 primitive: cn.
Source
import { cn } from "../lib/cn";
export interface StatCardProps {
label: string;
value: string;
/** e.g. "+12% vs last week" — plain text, since colour alone cannot carry direction. */
change?: string;
changeTone?: "positive" | "negative" | "neutral";
className?: string;
}
const TONES = {
positive: "text-green-700 dark:text-green-400",
negative: "text-red-700 dark:text-red-400",
neutral: "text-neutral-500 dark:text-neutral-400",
} as const;
/** A single KPI figure with an optional trend line. */
export function StatCard({ label, value, change, changeTone = "neutral", className }: StatCardProps) {
return (
<div className={cn("flex flex-col gap-1 rounded-xl border border-neutral-200 p-4 text-start dark:border-neutral-800", className)}>
<span className="text-sm text-neutral-600 dark:text-neutral-400">{label}</span>
<span className="text-2xl font-semibold tracking-tight">{value}</span>
{change && <span className={cn("text-sm", TONES[changeTone])}>{change}</span>}
</div>
);
}
What CI checks
- Bundled, minified and gzipped against its tier budget
- Audited by axe in the state previewed above
- Rendered through react-dom/server with no browser globals
- Scanned for network calls, dangerous sinks, and unguarded animation