{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stat-card",
  "type": "registry:component",
  "title": "Stat card",
  "description": "A key metric with a sparkline, period comparison, and meaningful trend direction.",
  "categories": [
    "metrics"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [
    "card"
  ],
  "files": [
    {
      "path": "src/registry/overtrue/stat-card.tsx",
      "type": "registry:component",
      "target": "components/overtrue/stat-card.tsx",
      "content": "\"use client\";\nimport type { ReactNode } from \"react\";\nimport {\n  IconArrowDownRight as ArrowDownRight,\n  IconArrowUpRight as ArrowUpRight,\n  IconMinus as Minus,\n} from \"@tabler/icons-react\";\nimport { Card, CardContent } from \"@/components/ui/card\";\nimport { cn } from \"@/lib/utils\";\nimport { Sparkline } from \"./sparkline\";\n\nexport interface StatCardProps {\n  title: string;\n  value: string | number;\n  change?: string;\n  trend?: \"up\" | \"down\" | \"neutral\";\n  /** A decrease is positive for metrics such as latency or churn. */\n  positiveTrend?: \"up\" | \"down\";\n  sparkline?: number[];\n  icon?: ReactNode;\n  description?: string;\n  className?: string;\n}\n\n// Currency symbols and units sit quieter than the digits; \"Q3 2026\" stays untouched.\nconst quiet = \"font-medium tracking-normal text-current/50\";\nconst unitSize = \"text-[0.6em]\";\nconst symbolSize = \"mr-[0.04em] text-[0.62em] align-[0.4em]\";\nfunction typeset(text: string) {\n  const match =\n    /^([+\\-−]?)([^\\d\\s+\\-−]{0,3})(\\d(?:[\\d.,  ]*\\d)?[KkMBT]?)(%|\\s+\\S.*)?$/.exec(\n      text,\n    );\n  if (!match || /[a-z]/i.test(match[2].replace(/[A-Z]{1,2}(?=\\$)/, \"\")))\n    return text;\n  const [, sign, symbol, digits, unit] = match;\n  return (\n    <>\n      {sign}\n      {symbol ? <span className={cn(quiet, symbolSize)}>{symbol}</span> : null}\n      {digits}\n      {unit ? <span className={cn(quiet, unitSize)}>{unit}</span> : null}\n    </>\n  );\n}\n\n// Same tones as DeltaBadge, so a change reads the same everywhere.\nconst toneText = {\n  positive: \"text-emerald-700 dark:text-emerald-400\",\n  negative: \"text-rose-700 dark:text-rose-400\",\n  neutral: \"text-muted-foreground\",\n};\nconst tonePill = {\n  positive: \"bg-emerald-500/10 dark:bg-emerald-400/10\",\n  negative: \"bg-rose-500/10 dark:bg-rose-400/10\",\n  neutral: \"bg-muted\",\n};\nconst toneLine = {\n  positive: \"text-emerald-600 dark:text-emerald-400\",\n  negative: \"text-rose-600 dark:text-rose-400\",\n  neutral: \"text-muted-foreground\",\n};\n\nexport function StatCard({\n  title,\n  value,\n  change,\n  trend = \"neutral\",\n  positiveTrend = \"up\",\n  sparkline,\n  icon,\n  description,\n  className,\n}: StatCardProps) {\n  const Icon =\n    trend === \"up\" ? ArrowUpRight : trend === \"down\" ? ArrowDownRight : Minus;\n  const tone =\n    trend === \"neutral\"\n      ? \"neutral\"\n      : trend === positiveTrend\n        ? \"positive\"\n        : \"negative\";\n  return (\n    <Card\n      data-slot=\"stat-card\"\n      data-trend={trend}\n      data-tone={tone}\n      className={cn(\n        \"min-w-0 gap-0 rounded-2xl border border-border/70 bg-card py-0 text-card-foreground ring-0 shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.5)]\",\n        className,\n      )}\n    >\n      <CardContent className=\"p-5\">\n        <p\n          data-slot=\"stat-card-title\"\n          className=\"flex min-h-7 items-center justify-between gap-3 text-sm leading-5 font-medium text-muted-foreground\"\n        >\n          {title}\n          {icon && (\n            <span\n              aria-hidden=\"true\"\n              className=\"grid size-7 shrink-0 place-items-center rounded-lg bg-muted/60 text-muted-foreground ring-1 ring-border/60 ring-inset [&>svg]:size-4\"\n            >\n              {icon}\n            </span>\n          )}\n        </p>\n        <p\n          data-slot=\"stat-card-value\"\n          className=\"mt-2 text-3xl leading-9 font-semibold tracking-[-0.035em] wrap-anywhere text-card-foreground tabular-nums\"\n        >\n          {typeset(\n            typeof value === \"number\" ? value.toLocaleString(\"en-US\") : value,\n          )}\n        </p>\n        {sparkline && (\n          <Sparkline\n            data={sparkline}\n            label={`${title} trend`}\n            className={cn(\"mt-4\", toneLine[tone])}\n          />\n        )}\n        {(change || description) && (\n          <div className=\"mt-3 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs\">\n            {change && (\n              <span\n                data-slot=\"stat-card-change\"\n                className={cn(\n                  \"inline-flex h-5 items-center gap-0.5 rounded-full pr-1.5 pl-1 leading-none font-medium tracking-[-0.01em] tabular-nums\",\n                  toneText[tone],\n                  tonePill[tone],\n                )}\n              >\n                <Icon\n                  className=\"size-3 shrink-0\"\n                  aria-hidden=\"true\"\n                  stroke={2.5}\n                />\n                <span className=\"sr-only\">\n                  {trend === \"up\"\n                    ? \"Increase\"\n                    : trend === \"down\"\n                      ? \"Decrease\"\n                      : \"No change\"}\n                  {tone !== \"neutral\" ? ` (${tone})` : \"\"}:{\" \"}\n                </span>\n                {change}\n              </span>\n            )}\n            <span className=\"text-muted-foreground\">\n              {description ?? \"vs. last month\"}\n            </span>\n          </div>\n        )}\n      </CardContent>\n    </Card>\n  );\n}\n"
    },
    {
      "path": "src/registry/overtrue/sparkline.tsx",
      "type": "registry:component",
      "target": "components/overtrue/sparkline.tsx",
      "content": "\"use client\";\nimport { useId, type CSSProperties } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SparklineProps {\n  data: number[];\n  label: string;\n  className?: string;\n  filled?: boolean;\n  /** Mark the most recent value. */\n  endpoint?: boolean;\n  /** Any CSS color. Defaults to the current text color, which is primary. */\n  color?: string;\n  /** Draw the line in and raise the area when the sparkline mounts. Skipped under reduced motion. */\n  animate?: boolean;\n}\n\nconst WIDTH = 240;\nconst HEIGHT = 48;\nconst PAD_X = 3;\nconst PAD_Y = 5;\nconst EASE = \"ease-[cubic-bezier(0.22,1,0.36,1)]\";\n\n/** Monotone cubic path: smooth, but never overshoots the data. */\nfunction monotonePath(points: [number, number][]) {\n  const n = points.length;\n  if (n < 2) return \"\";\n  const dx: number[] = [];\n  const slope: number[] = [];\n  for (let i = 0; i < n - 1; i++) {\n    dx.push(points[i + 1][0] - points[i][0]);\n    slope.push((points[i + 1][1] - points[i][1]) / dx[i]);\n  }\n  const tangent = [slope[0]];\n  for (let i = 1; i < n - 1; i++) {\n    tangent.push(\n      slope[i - 1] * slope[i] <= 0 ? 0 : (slope[i - 1] + slope[i]) / 2,\n    );\n  }\n  tangent.push(slope[n - 2]);\n  for (let i = 0; i < n - 1; i++) {\n    if (slope[i] === 0) {\n      tangent[i] = tangent[i + 1] = 0;\n      continue;\n    }\n    const a = tangent[i] / slope[i];\n    const b = tangent[i + 1] / slope[i];\n    const h = a * a + b * b;\n    if (h > 9) {\n      const t = 3 / Math.sqrt(h);\n      tangent[i] = t * a * slope[i];\n      tangent[i + 1] = t * b * slope[i];\n    }\n  }\n  const r = (value: number) => Math.round(value * 100) / 100;\n  let d = `M${r(points[0][0])},${r(points[0][1])}`;\n  for (let i = 0; i < n - 1; i++) {\n    const [x0, y0] = points[i];\n    const [x1, y1] = points[i + 1];\n    const h = dx[i] / 3;\n    d += `C${r(x0 + h)},${r(y0 + tangent[i] * h)} ${r(x1 - h)},${r(y1 - tangent[i + 1] * h)} ${r(x1)},${r(y1)}`;\n  }\n  return d;\n}\n\n/** A compact overview. Use a full chart when individual values need inspection. */\nexport function Sparkline({\n  data,\n  label,\n  className,\n  filled = true,\n  endpoint = true,\n  color,\n  animate = true,\n}: SparklineProps) {\n  const gradient = `sparkline-${useId().replace(/:/g, \"\")}`;\n  const values = data.filter(Number.isFinite);\n  let low = Infinity,\n    high = -Infinity;\n  for (const value of values) {\n    low = Math.min(low, value);\n    high = Math.max(high, value);\n  }\n  const points = values.map((value, i): [number, number] => [\n    values.length > 1\n      ? PAD_X + (i / (values.length - 1)) * (WIDTH - PAD_X * 2)\n      : WIDTH / 2,\n    high === low\n      ? HEIGHT / 2\n      : HEIGHT - PAD_Y - ((value - low) / (high - low)) * (HEIGHT - PAD_Y * 2),\n  ]);\n  const line = monotonePath(points);\n  const last = points[points.length - 1];\n  const lastValue = values[values.length - 1];\n  const motion = animate ? \"motion-reduce:transition-none\" : \"transition-none\";\n  return (\n    <div\n      data-slot=\"sparkline\"\n      role=\"img\"\n      aria-label={`${label}: ${values.length ? values.join(\", \") : \"No data\"}`}\n      className={cn(\"relative h-12 w-full text-primary\", className)}\n      style={color ? { color } : undefined}\n    >\n      {values.length > 1 && filled && (\n        <svg\n          viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n          preserveAspectRatio=\"none\"\n          aria-hidden=\"true\"\n          data-slot=\"sparkline-area\"\n          className={cn(\n            \"absolute inset-0 size-full origin-bottom overflow-visible transition-[opacity,scale] delay-75 duration-700\",\n            EASE,\n            animate && \"starting:scale-y-0 starting:opacity-0\",\n            motion,\n          )}\n        >\n          <defs>\n            <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n              <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity=\"0.28\" />\n              <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity=\"0\" />\n            </linearGradient>\n          </defs>\n          <path\n            d={`${line}L${last[0]},${HEIGHT}L${points[0][0]},${HEIGHT}Z`}\n            fill={`url(#${gradient})`}\n            className={cn(\"transition-[d] duration-500\", EASE, motion)}\n          />\n        </svg>\n      )}\n      <svg\n        viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n        preserveAspectRatio=\"none\"\n        aria-hidden=\"true\"\n        data-slot=\"sparkline-line\"\n        className={cn(\n          // The line wipes in from the left; the inset leaves room for its glow.\n          \"absolute inset-0 size-full overflow-visible [clip-path:inset(-60%_-8%_-60%_-8%)] transition-[clip-path] duration-700\",\n          EASE,\n          animate &&\n            values.length > 1 &&\n            \"starting:[clip-path:inset(-60%_100%_-60%_-8%)]\",\n          motion,\n        )}\n      >\n        {values.length > 1 ? (\n          <path\n            d={line}\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"2\"\n            strokeLinejoin=\"round\"\n            strokeLinecap=\"round\"\n            vectorEffect=\"non-scaling-stroke\"\n            className={cn(\n              \"transition-[d] duration-500 dark:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,currentColor_50%,transparent))]\",\n              EASE,\n              motion,\n            )}\n          />\n        ) : values.length === 0 ? (\n          <path\n            d={`M${PAD_X} ${HEIGHT / 2}H${WIDTH - PAD_X}`}\n            stroke=\"currentColor\"\n            strokeDasharray=\"2 5\"\n            strokeLinecap=\"round\"\n            opacity=\"0.3\"\n            vectorEffect=\"non-scaling-stroke\"\n          />\n        ) : null}\n      </svg>\n      {/* Drawn in HTML so the marker stays round when the line stretches. */}\n      {endpoint && last && (\n        <span\n          aria-hidden=\"true\"\n          data-slot=\"sparkline-endpoint\"\n          className={cn(\n            // Moves with the line, and on mount appears once the line has drawn in.\n            \"absolute -translate-x-1/2 -translate-y-1/2 [transition:left_500ms_cubic-bezier(0.22,1,0.36,1),top_500ms_cubic-bezier(0.22,1,0.36,1),opacity_300ms_ease-out_550ms,scale_500ms_cubic-bezier(0.22,1,0.36,1)_550ms]\",\n            animate && \"starting:scale-0 starting:opacity-0\",\n            motion,\n          )}\n          style={\n            {\n              left: `${(last[0] / WIDTH) * 100}%`,\n              top: `${(last[1] / HEIGHT) * 100}%`,\n            } as CSSProperties\n          }\n        >\n          {/* Pulses once whenever the latest value changes. */}\n          <span\n            key={lastValue}\n            className={cn(\n              \"absolute inset-0 scale-[3.2] rounded-full bg-current opacity-0 transition-[opacity,scale] duration-1000 ease-out starting:scale-100 starting:opacity-40 motion-reduce:hidden\",\n              !animate && \"hidden\",\n            )}\n          />\n          <span className=\"relative block size-2 rounded-full border-[1.5px] border-card bg-current shadow-[0_0_0_3px_color-mix(in_oklab,currentColor_18%,transparent)] dark:shadow-[0_0_0_3px_color-mix(in_oklab,currentColor_24%,transparent),0_0_12px_1px_color-mix(in_oklab,currentColor_70%,transparent)]\" />\n        </span>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/stat-card. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
