{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-list",
  "title": "Metric List",
  "description": "Compact rows of label, sparkline, value, and delta.",
  "dependencies": [
    "recharts",
    "lucide-react"
  ],
  "registryDependencies": [
    "tooltip"
  ],
  "files": [
    {
      "path": "registry/dashboardcn/ui/metric-list.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport { DeltaBadge, getDeltaDirection } from \"@/registry/dashboardcn/ui/delta-badge\"\nimport { Sparkline } from \"@/registry/dashboardcn/ui/sparkline\"\nimport { MetricValue } from \"@/registry/dashboardcn/ui/metric-value\"\n\nexport interface MetricListItem {\n  label: string\n  value: number | string\n  delta?: number\n  trend?: number[]\n  format?: NumberFormat\n  currency?: string\n  invertDelta?: boolean\n  icon?: React.ReactNode\n  key?: string\n}\n\nexport interface MetricListProps extends React.ComponentProps<\"div\"> {\n  items: MetricListItem[]\n  /** Sparkline variant. */\n  variant?: \"area\" | \"line\"\n  /** Sparkline area fill. */\n  fill?: \"gradient\" | \"dots\"\n  showDivider?: boolean\n}\n\n/** Compact rows of label, sparkline, value, and delta. */\nfunction MetricList({\n  items,\n  variant = \"line\",\n  fill,\n  showDivider = true,\n  className,\n  ...props\n}: MetricListProps) {\n  return (\n    <div\n      data-slot=\"metric-list\"\n      className={cn(\"flex flex-col\", showDivider && \"divide-y\", className)}\n      {...props}\n    >\n      {items.map((item) => {\n        const direction = getDeltaDirection(item.delta)\n        const positive =\n          direction === \"flat\" ? null : (direction === \"up\") !== Boolean(item.invertDelta)\n        const color =\n          positive === true\n            ? \"var(--color-emerald-500)\"\n            : positive === false\n              ? \"var(--color-red-500)\"\n              : \"var(--muted-foreground)\"\n        return (\n          <div\n            key={item.key ?? item.label}\n            data-slot=\"metric-list-row\"\n            className=\"flex items-center gap-4 py-2.5 text-sm first:pt-0 last:pb-0\"\n          >\n            <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n              {item.icon ? (\n                <span className=\"text-muted-foreground shrink-0 [&>svg]:size-4\">\n                  {item.icon}\n                </span>\n              ) : null}\n              <span className=\"truncate\">{item.label}</span>\n            </div>\n            {item.trend && item.trend.length > 1 ? (\n              <Sparkline\n                data={item.trend}\n                variant={variant}\n                fill={fill}\n                color={color}\n                className=\"h-6 w-20 shrink-0\"\n              />\n            ) : null}\n            <div className=\"flex w-28 shrink-0 items-center justify-end gap-2 tabular-nums\">\n              <MetricValue\n                value={item.value}\n                format={item.format}\n                currency={item.currency}\n                className=\"font-medium\"\n              />\n              {item.delta !== undefined ? (\n                <DeltaBadge\n                  delta={item.delta}\n                  invert={item.invertDelta}\n                  variant=\"text\"\n                  showIcon={false}\n                />\n              ) : null}\n            </div>\n          </div>\n        )\n      })}\n    </div>\n  )\n}\n\nexport { MetricList }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/delta-badge.tsx",
      "content": "import * as React from \"react\"\nimport { Minus, TrendingDown, TrendingUp } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatDelta } from \"@/registry/dashboardcn/lib/format\"\n\nexport type DeltaDirection = \"up\" | \"down\" | \"flat\"\n\nexport function getDeltaDirection(delta: number | undefined): DeltaDirection {\n  if (delta === undefined || delta === 0 || !Number.isFinite(delta)) return \"flat\"\n  return delta > 0 ? \"up\" : \"down\"\n}\n\nconst directionIcon: Record<DeltaDirection, React.ElementType> = {\n  up: TrendingUp,\n  down: TrendingDown,\n  flat: Minus,\n}\n\nexport interface DeltaBadgeProps extends React.ComponentProps<\"span\"> {\n  /** Fractional change, e.g. 0.124 for +12.4%. */\n  delta: number\n  /** Treat a decrease as good and an increase as bad (churn, latency, errors). */\n  invert?: boolean\n  variant?: \"outline\" | \"soft\" | \"text\"\n  showIcon?: boolean\n}\n\nfunction DeltaBadge({\n  delta,\n  invert = false,\n  variant = \"outline\",\n  showIcon = true,\n  className,\n  children,\n  ...props\n}: DeltaBadgeProps) {\n  const direction = getDeltaDirection(delta)\n  const positive = direction === \"flat\" ? null : (direction === \"up\") !== invert\n  const Icon = directionIcon[direction]\n\n  return (\n    <span\n      data-slot=\"delta-badge\"\n      data-direction={direction}\n      data-positive={positive}\n      className={cn(\n        \"inline-flex items-center gap-1 text-xs font-medium tabular-nums\",\n        variant === \"outline\" && \"rounded-md border px-1.5 py-0.5\",\n        variant === \"soft\" && \"rounded-md px-1.5 py-0.5\",\n        variant === \"soft\" && positive === true && \"bg-emerald-500/10\",\n        variant === \"soft\" && positive === false && \"bg-red-500/10\",\n        variant === \"soft\" && positive === null && \"bg-muted\",\n        positive === true && \"text-emerald-600 dark:text-emerald-400\",\n        positive === false && \"text-red-600 dark:text-red-400\",\n        positive === null && \"text-muted-foreground\",\n        className\n      )}\n      {...props}\n    >\n      {showIcon ? <Icon className=\"size-3\" aria-hidden=\"true\" /> : null}\n      {children ?? formatDelta(delta)}\n    </span>\n  )\n}\n\nexport { DeltaBadge }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/sparkline.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  Area,\n  AreaChart,\n  AreaRevealShape,\n  Line,\n  LineChart,\n  ResponsiveContainer,\n  type AreaRevealShapeProps,\n} from \"recharts\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface SparklineProps extends React.ComponentProps<\"div\"> {\n  /** Series to plot, oldest first. */\n  data: number[]\n  variant?: \"area\" | \"line\"\n  /** Area fill: a plain gradient, or a dot grid that fades out toward the line. */\n  fill?: \"gradient\" | \"dots\"\n  /** Any CSS color. Defaults to the theme primary. */\n  color?: string\n  curve?: \"monotone\" | \"linear\" | \"step\"\n  strokeWidth?: number\n  /** Animate after hydration and when data changes. Respects reduced motion. */\n  animate?: boolean\n  animationDuration?: number\n}\n\nconst reducedMotionQuery = \"(prefers-reduced-motion: reduce)\"\n\nfunction subscribeToReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(reducedMotionQuery)\n  query.addEventListener(\"change\", onChange)\n  return () => query.removeEventListener(\"change\", onChange)\n}\n\nfunction getReducedMotionSnapshot() {\n  return window.matchMedia(reducedMotionQuery).matches\n}\n\nfunction getReducedMotionServerSnapshot() {\n  return true\n}\n\n/** Area shape that masks the fill to a dot grid while keeping the stroke solid. */\nfunction DotGridAreaShape({\n  maskId,\n  ...props\n}: AreaRevealShapeProps & { maskId: string }) {\n  return (\n    <>\n      <g mask={`url(#${maskId})`}>\n        <AreaRevealShape {...props} stroke=\"none\" />\n      </g>\n      <AreaRevealShape {...props} id={undefined} fill=\"none\" />\n    </>\n  )\n}\n\nfunction Sparkline({\n  data,\n  variant = \"area\",\n  fill = \"gradient\",\n  color = \"var(--primary)\",\n  curve = \"monotone\",\n  strokeWidth = 1.5,\n  animate = true,\n  animationDuration = 500,\n  className,\n  ...props\n}: SparklineProps) {\n  const id = React.useId()\n  const reducedMotion = React.useSyncExternalStore(\n    subscribeToReducedMotion,\n    getReducedMotionSnapshot,\n    getReducedMotionServerSnapshot\n  )\n  const animationActive = animate && !reducedMotion\n  const dots = variant === \"area\" && fill === \"dots\"\n  const points = React.useMemo(() => data.map((y, i) => ({ i, y })), [data])\n  const margin = { top: 2, right: 0, bottom: 0, left: 0 }\n\n  return (\n    <div\n      data-slot=\"sparkline\"\n      aria-hidden=\"true\"\n      className={cn(\"h-10 w-full\", className)}\n      {...props}\n    >\n      <ResponsiveContainer width=\"100%\" height=\"100%\">\n        {variant === \"line\" ? (\n          <LineChart data={points} margin={margin}>\n            <Line\n              type={curve}\n              dataKey=\"y\"\n              stroke={color}\n              strokeWidth={strokeWidth}\n              dot={false}\n              isAnimationActive={animationActive}\n              animationDuration={animationDuration}\n              animationEasing=\"ease-out\"\n            />\n          </LineChart>\n        ) : (\n          <AreaChart data={points} margin={margin}>\n            <defs>\n              <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                <stop offset=\"0%\" stopColor={color} stopOpacity={dots ? 0.08 : 0.3} />\n                <stop offset=\"100%\" stopColor={color} stopOpacity={dots ? 0.9 : 0} />\n              </linearGradient>\n              {dots ? (\n                <>\n                  <pattern\n                    id={`${id}-dots`}\n                    patternUnits=\"userSpaceOnUse\"\n                    width={4}\n                    height={4}\n                  >\n                    <circle cx={2} cy={2} r={0.9} fill=\"#fff\" />\n                  </pattern>\n                  <mask\n                    id={`${id}-mask`}\n                    maskUnits=\"userSpaceOnUse\"\n                    x={0}\n                    y={0}\n                    width=\"100%\"\n                    height=\"100%\"\n                  >\n                    <rect width=\"100%\" height=\"100%\" fill={`url(#${id}-dots)`} />\n                  </mask>\n                </>\n              ) : null}\n            </defs>\n            <Area\n              type={curve}\n              dataKey=\"y\"\n              stroke={color}\n              strokeWidth={strokeWidth}\n              fill={`url(#${id})`}\n              fillOpacity={dots ? 1 : undefined}\n              dot={false}\n              isAnimationActive={animationActive}\n              animationDuration={animationDuration}\n              animationEasing=\"ease-out\"\n              shape={\n                dots\n                  ? (shapeProps: AreaRevealShapeProps) => (\n                      <DotGridAreaShape {...shapeProps} maskId={`${id}-mask`} />\n                    )\n                  : undefined\n              }\n            />\n          </AreaChart>\n        )}\n      </ResponsiveContainer>\n    </div>\n  )\n}\n\nexport { Sparkline }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/metric-value.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatNumber, type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n/** Values at or above this are abbreviated by default. */\nexport const DEFAULT_COMPACT_FROM = 100_000\n\nexport interface MetricValueProps extends Omit<React.ComponentProps<\"span\">, \"children\"> {\n  /** Strings render as-is. */\n  value: number | string\n  format?: NumberFormat\n  currency?: string\n  maximumFractionDigits?: number\n  /** Values at or above this are abbreviated (e.g. $158K) with the full value in a tooltip. Set to Infinity to always show the full value. */\n  compactFrom?: number\n  /** Text after the number, e.g. a unit. */\n  suffix?: React.ReactNode\n}\n\n/** A formatted number. Large values are abbreviated and reveal the full value on hover. */\nfunction MetricValue({\n  value,\n  format,\n  currency,\n  maximumFractionDigits,\n  compactFrom = DEFAULT_COMPACT_FROM,\n  suffix,\n  className,\n  ...props\n}: MetricValueProps) {\n  const classes = cn(\"tabular-nums\", className)\n\n  if (typeof value !== \"number\") {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {value}\n        {suffix}\n      </span>\n    )\n  }\n\n  const full = formatNumber(value, { format, currency, maximumFractionDigits })\n  const abbreviate = format !== \"percent\" && Math.abs(value) >= compactFrom\n  if (!abbreviate) {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {full}\n        {suffix}\n      </span>\n    )\n  }\n\n  return (\n    <TooltipProvider>\n      <Tooltip>\n        <TooltipTrigger asChild>\n          <span\n            data-slot=\"metric-value\"\n            data-compact=\"\"\n            className={cn(classes, \"cursor-default\")}\n            {...props}\n          >\n            {formatNumber(value, { format, currency, compact: true })}\n            {suffix}\n          </span>\n        </TooltipTrigger>\n        <TooltipContent className=\"tabular-nums\">\n          {full}\n          {suffix}\n        </TooltipContent>\n      </Tooltip>\n    </TooltipProvider>\n  )\n}\n\nexport { MetricValue }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/lib/format.ts",
      "content": "export type NumberFormat = \"number\" | \"compact\" | \"currency\" | \"percent\"\n\nexport interface FormatNumberOptions {\n  format?: NumberFormat\n  /** ISO 4217 code, used when format is \"currency\". Defaults to USD. */\n  currency?: string\n  locale?: string\n  maximumFractionDigits?: number\n  /** Abbreviate large values, e.g. \"$158K\" instead of \"$158,143\". */\n  compact?: boolean\n}\n\nconst formatterCache = new Map<string, Intl.NumberFormat>()\n\nfunction getFormatter(locale: string, options: Intl.NumberFormatOptions) {\n  const key = locale + JSON.stringify(options)\n  let formatter = formatterCache.get(key)\n  if (!formatter) {\n    formatter = new Intl.NumberFormat(locale, options)\n    formatterCache.set(key, formatter)\n  }\n  return formatter\n}\n\n/**\n * Format a metric value for display.\n *\n * formatNumber(1234567)                          -> \"1,234,567\"\n * formatNumber(1234567, { format: \"compact\" })   -> \"1.2M\"\n * formatNumber(48.2, { format: \"currency\" })     -> \"$48.20\"\n * formatNumber(158143, { format: \"currency\", compact: true }) -> \"$158K\"\n * formatNumber(0.124, { format: \"percent\" })     -> \"12.4%\"\n */\nexport function formatNumber(\n  value: number,\n  {\n    format = \"number\",\n    currency = \"USD\",\n    locale = \"en-US\",\n    maximumFractionDigits,\n    compact = false,\n  }: FormatNumberOptions = {}\n): string {\n  if (!Number.isFinite(value)) return \"—\"\n\n  // Compact values keep three significant digits: $158K, $1.23M, 41.2K.\n  const compactOptions: Intl.NumberFormatOptions = compact\n    ? maximumFractionDigits === undefined\n      ? { notation: \"compact\", maximumSignificantDigits: 3 }\n      : { notation: \"compact\", maximumFractionDigits }\n    : {}\n  switch (format) {\n    case \"compact\":\n      return getFormatter(locale, {\n        notation: \"compact\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value)\n    case \"currency\":\n      return getFormatter(locale, {\n        style: \"currency\",\n        currency,\n        maximumFractionDigits: maximumFractionDigits ?? 2,\n        ...compactOptions,\n      }).format(value)\n    case \"percent\":\n      return getFormatter(locale, {\n        style: \"percent\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value)\n    default:\n      return getFormatter(locale, {\n        maximumFractionDigits: maximumFractionDigits ?? 0,\n        ...compactOptions,\n      }).format(value)\n  }\n}\n\n/**\n * Format a fractional change as a signed percentage.\n *\n * formatDelta(0.124)  -> \"+12.4%\"\n * formatDelta(-0.03)  -> \"-3.0%\"\n * formatDelta(0)      -> \"0.0%\"\n */\nexport function formatDelta(delta: number, locale = \"en-US\"): string {\n  if (!Number.isFinite(delta)) return \"—\"\n  return getFormatter(locale, {\n    style: \"percent\",\n    signDisplay: \"exceptZero\",\n    maximumFractionDigits: 1,\n    minimumFractionDigits: 1,\n  }).format(delta)\n}\n\n/**\n * Fractional change between two values. Returns 0 when there is no baseline.\n */\nexport function computeDelta(current: number, previous: number): number {\n  if (!previous) return 0\n  return (current - previous) / Math.abs(previous)\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:ui"
}