{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "commerce-kpi-row",
  "title": "Commerce KPI Row",
  "description": "A responsive metric strip with dotted sparklines, semantic deltas, and registration-mark corners.",
  "dependencies": [
    "lucide-react",
    "recharts"
  ],
  "registryDependencies": [
    "tooltip"
  ],
  "files": [
    {
      "path": "registry/dashboardcn/blocks/commerce-kpi-row.tsx",
      "content": "import * as React from \"react\"\nimport { TrendingDown, TrendingUp } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport { CornerFrame } from \"@/registry/dashboardcn/ui/corner-frame\"\nimport { MetricValue } from \"@/registry/dashboardcn/ui/metric-value\"\nimport { Sparkline } from \"@/registry/dashboardcn/ui/sparkline\"\n\nexport interface CommerceKpiMetric {\n  label: string\n  value: number\n  format?: NumberFormat\n  currency?: string\n  delta?: number\n  deltaLabel?: string\n  invertDelta?: boolean\n  trend?: number[]\n  icon?: React.ReactNode\n}\n\nexport interface CommerceKpiRowProps extends React.ComponentProps<\"div\"> {\n  metrics: CommerceKpiMetric[]\n  cornerColor?: string\n}\n\n/** A responsive row of compact commerce metrics with sparklines and registration-mark corners. */\nfunction CommerceKpiRow({ metrics, cornerColor, className, ...props }: CommerceKpiRowProps) {\n  return (\n    <div\n      data-slot=\"commerce-kpi-row\"\n      className={cn(\"grid gap-3 sm:grid-cols-2\", className)}\n      {...props}\n    >\n      {metrics.map((metric) => {\n        const positive = metric.delta === undefined\n          ? null\n          : (metric.delta >= 0) !== Boolean(metric.invertDelta)\n        const DeltaIcon = metric.delta !== undefined && metric.delta < 0 ? TrendingDown : TrendingUp\n        const accent = positive === false ? \"var(--color-rose-500)\" : \"var(--color-emerald-500)\"\n\n        return (\n          <CornerFrame\n            key={metric.label}\n            cornerColor={cornerColor ?? \"var(--muted-foreground)\"}\n            className=\"bg-card min-w-0 p-5\"\n          >\n            <div className=\"flex min-w-0 items-center gap-2\">\n              <span className=\"text-muted-foreground flex min-w-0 items-center gap-1.5 truncate text-sm [&>svg]:size-3.5\">\n                {metric.icon}\n                {metric.label}\n              </span>\n            </div>\n            <div className=\"mt-2 flex items-end justify-between gap-4\">\n              <div className=\"min-w-0\">\n                <MetricValue\n                  value={metric.value}\n                  format={metric.format}\n                  currency={metric.currency}\n                  className=\"block truncate text-3xl font-semibold tracking-tight\"\n                />\n                {metric.delta !== undefined ? (\n                  <div className=\"text-muted-foreground mt-2 text-xs\">\n                    <span className=\"flex items-center gap-1\">\n                      <DeltaIcon className=\"size-3.5\" style={{ color: accent }} />\n                      <span className=\"font-medium tabular-nums\" style={{ color: accent }}>\n                        {Math.abs(metric.delta * 100).toFixed(1)}%\n                      </span>\n                    </span>\n                    {metric.deltaLabel ? (\n                      <span className=\"mt-0.5 block truncate\">{metric.deltaLabel}</span>\n                    ) : null}\n                  </div>\n                ) : null}\n              </div>\n              {metric.trend && metric.trend.length > 1 ? (\n                <Sparkline\n                  data={metric.trend}\n                  variant=\"area\"\n                  fill=\"dots\"\n                  color=\"var(--muted-foreground)\"\n                  className=\"h-12 w-20 shrink-0 opacity-60\"\n                />\n              ) : null}\n            </div>\n          </CornerFrame>\n        )\n      })}\n    </div>\n  )\n}\n\nexport { CommerceKpiRow }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/dashboardcn/ui/corner-frame.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface CornerFrameProps extends React.ComponentProps<\"div\"> {\n  /** Length of each registration mark, in pixels. */\n  cornerSize?: number\n  /** Any CSS color used for the corner marks. */\n  cornerColor?: string\n  /** Show a quiet hairline around the framed content. */\n  bordered?: boolean\n}\n\n/** A content frame with small registration marks at every corner. */\nfunction CornerFrame({\n  cornerSize = 10,\n  cornerColor = \"var(--muted-foreground)\",\n  bordered = true,\n  className,\n  children,\n  style,\n  ...props\n}: CornerFrameProps) {\n  const cornerStyle = {\n    \"--corner-size\": `${cornerSize}px`,\n    \"--corner-color\": cornerColor,\n    ...style,\n  } as React.CSSProperties\n\n  return (\n    <div\n      data-slot=\"corner-frame\"\n      className={cn(\"relative\", bordered && \"border\", className)}\n      style={cornerStyle}\n      {...props}\n    >\n      {children}\n      {([\"top-left\", \"top-right\", \"bottom-right\", \"bottom-left\"] as const).map(\n        (corner) => (\n          <span\n            key={corner}\n            data-corner={corner}\n            aria-hidden=\"true\"\n            className={cn(\n              \"pointer-events-none absolute z-10 size-(--corner-size)\",\n              \"before:absolute before:bg-(--corner-color) after:absolute after:bg-(--corner-color)\",\n              \"before:top-1/2 before:h-px before:w-full before:-translate-y-1/2 after:left-1/2 after:h-full after:w-px after:-translate-x-1/2\",\n              corner === \"top-left\" &&\n                \"top-0 left-0 -translate-x-1/2 -translate-y-1/2\",\n              corner === \"top-right\" &&\n                \"top-0 right-0 translate-x-1/2 -translate-y-1/2\",\n              corner === \"bottom-right\" &&\n                \"right-0 bottom-0 translate-x-1/2 translate-y-1/2\",\n              corner === \"bottom-left\" &&\n                \"bottom-0 left-0 -translate-x-1/2 translate-y-1/2\"\n            )}\n          />\n        )\n      )}\n    </div>\n  )\n}\n\nexport { CornerFrame }\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"
    }
  ],
  "categories": [
    "dashboard",
    "charts"
  ],
  "type": "registry:block"
}