{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric",
  "title": "Metric & Delta",
  "description": "Display KPI with count-up on twos, directional marker delta badge, note, and optional ToneSpark.",
  "registryDependencies": [
    "https://frame12.dev/r/frame12-styles.json",
    "https://frame12.dev/r/use-on-twos.json",
    "https://frame12.dev/r/use-tempo.json"
  ],
  "files": [
    {
      "path": "ui/metric.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { type MotionMode, useCountUp } from '@/hooks/use-on-twos';\n\nexport const fmtPct = (v: number): string => (Math.abs(v) * 100).toFixed(1) + '%';\nexport const fmtPPAbs = (v: number): string => Math.abs(v).toFixed(2) + ' pp';\nexport const fmtMoney = (v: number): string => '$' + Math.round(v).toLocaleString('en-US');\n\nexport interface DeltaProps {\n  value: number;\n  kind?: 'pct' | 'pp';\n  comparisonLabel?: string;\n  range?: number | string;\n}\n\nexport function Delta({ value, kind = 'pct', comparisonLabel, range }: DeltaProps) {\n  const flat = kind === 'pp' ? Math.abs(value) < 0.005 : Math.abs(value) < 0.0005;\n  const up = value > 0;\n  const text = flat\n    ? kind === 'pp'\n      ? '0.00 pp change'\n      : '0.0% change'\n    : kind === 'pp'\n      ? fmtPPAbs(value)\n      : fmtPct(value);\n  const dir = flat ? 'flat' : up ? 'up' : 'down';\n  const sym = flat ? '=' : up ? '▲' : '▼';\n  const refLabel = comparisonLabel ?? (range != null ? `vs prior ${range} days` : undefined);\n\n  return (\n    <p className={`f12-delta ${dir}`}>\n      <span className=\"f12-delta-sym\" aria-hidden=\"true\">\n        {sym}\n      </span>\n      <span className=\"f12-sr-only\">{flat ? '' : up ? 'Up ' : 'Down '}</span>\n      {text}\n      {refLabel && <span className=\"f12-delta-ref\"> {refLabel}</span>}\n    </p>\n  );\n}\n\nexport type MetricHeadingLevel = 'h2' | 'h3' | 'h4' | 'div' | 'p';\nexport type MetricVariant = 'expressive' | 'quiet';\n\nexport interface MetricProps {\n  label: string;\n  value: number;\n  format?: (value: number) => string;\n  delta?: number;\n  deltaKind?: 'pct' | 'pp';\n  comparisonLabel?: string;\n  range?: number | string;\n  note?: string;\n  big?: boolean;\n  variant?: MetricVariant;\n  motion?: MotionMode;\n  spark?: React.ReactNode;\n  headingLevel?: MetricHeadingLevel;\n  className?: string;\n}\n\nexport function Metric({\n  label,\n  value,\n  format = fmtMoney,\n  delta,\n  deltaKind = 'pct',\n  comparisonLabel,\n  range,\n  note,\n  big = false,\n  variant = 'expressive',\n  motion,\n  spark,\n  headingLevel: HeadingTag = 'h2',\n  className = '',\n}: MetricProps) {\n  const effectiveMotion: MotionMode = motion ?? (variant === 'quiet' ? 'cut' : 'stepped');\n  const shown = useCountUp(value, effectiveMotion);\n  const variantClass = variant === 'quiet' ? ' f12-metric-quiet' : '';\n  const finalText = format(value);\n  const shownText = format(shown);\n  // Hero values size themselves to their column from the glyph count. Counting up, the settled\n  // value is the longest string, so the size holds still; counting down (e.g. to 0) the frame in\n  // flight can be longer, so it wins until the animation settles and the value never overflows.\n  const heroStyle = big\n    ? ({\n        '--f12-m-chars': Math.max(finalText.length, shownText.length, 4),\n      } as React.CSSProperties)\n    : undefined;\n\n  return (\n    <div\n      className={`f12-metric${big ? ' big' : ''}${variantClass}${className ? ` ${className}` : ''}`}\n      data-variant={variant === 'quiet' ? 'quiet' : undefined}\n      style={heroStyle}\n    >\n      <HeadingTag className=\"f12-m-label\">{label}</HeadingTag>\n      <p className=\"f12-m-value\" aria-live=\"polite\">\n        <span className=\"f12-sr-only\">{finalText}</span>\n        <span aria-hidden=\"true\">{shownText}</span>\n      </p>\n      {delta != null && (\n        <Delta value={delta} kind={deltaKind} comparisonLabel={comparisonLabel} range={range} />\n      )}\n      {note && <p className=\"f12-m-note\">{note}</p>}\n      {spark}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/frame12/metric.tsx"
    }
  ],
  "type": "registry:ui"
}