{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "odometer-dashboard-demo",
  "type": "registry:block",
  "title": "Odometer: Dashboard KPIs",
  "description": "Animated Number Counter example, Dashboard KPIs: Currency with cents, a count, a percentage and milliseconds. The range switcher makes big jumps in both directions; between them the numbers drift live while the cards are on screen, and the delta chips flip color and arrow with their sign. A take on the number counter (count up). Fits stats, pricing, hero and app UI sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "stats",
    "pricing",
    "hero",
    "app-ui",
    "number-counter",
    "number",
    "data",
    "motion"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/odometer#odometer-dashboard-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/odometer.json"
  ],
  "files": [
    {
      "path": "components/odometer-dashboard-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useInView } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Odometer } from \"@/components/ui/odometer\";\n\ntype Range = \"24h\" | \"7d\" | \"30d\";\ntype Reading = { value: number; delta: number };\n\nconst ranges: { id: Range; label: string }[] = [\n  { id: \"24h\", label: \"24 hours\" },\n  { id: \"7d\", label: \"7 days\" },\n  { id: \"30d\", label: \"30 days\" },\n];\n\nconst metrics: {\n  id: string;\n  label: string;\n  format: Intl.NumberFormatOptions;\n  /** Rounds a drifting value to what the format shows. */\n  round: (n: number) => number;\n  /** How far one idle tick can drift, as a share of the value. */\n  wobble: number;\n  /** Lower is better, so a fall is shown in green. */\n  invert?: boolean;\n  data: Record<Range, Reading>;\n}[] = [\n  {\n    id: \"revenue\",\n    label: \"Revenue\",\n    format: { style: \"currency\", currency: \"USD\", minimumFractionDigits: 2 },\n    round: (n) => Math.round(n * 100) / 100,\n    wobble: 0.003,\n    data: {\n      \"24h\": { value: 48210.5, delta: 0.124 },\n      \"7d\": { value: 312904.2, delta: 0.081 },\n      \"30d\": { value: 1284377.9, delta: 0.216 },\n    },\n  },\n  {\n    id: \"users\",\n    label: \"Active users\",\n    format: {},\n    round: Math.round,\n    wobble: 0.002,\n    data: {\n      \"24h\": { value: 12842, delta: 0.038 },\n      \"7d\": { value: 86315, delta: 0.052 },\n      \"30d\": { value: 341208, delta: 0.149 },\n    },\n  },\n  {\n    id: \"conversion\",\n    label: \"Conversion\",\n    format: { style: \"percent\", minimumFractionDigits: 2, maximumFractionDigits: 2 },\n    round: (n) => Math.round(n * 10000) / 10000,\n    wobble: 0.01,\n    data: {\n      \"24h\": { value: 0.0342, delta: 0.006 },\n      \"7d\": { value: 0.0318, delta: -0.024 },\n      \"30d\": { value: 0.0296, delta: -0.012 },\n    },\n  },\n  {\n    id: \"response\",\n    label: \"Avg. response\",\n    format: { style: \"unit\", unit: \"millisecond\", unitDisplay: \"short\", maximumFractionDigits: 0 },\n    round: Math.round,\n    wobble: 0.025,\n    invert: true,\n    data: {\n      \"24h\": { value: 184, delta: -0.031 },\n      \"7d\": { value: 201, delta: 0.047 },\n      \"30d\": { value: 176, delta: -0.063 },\n    },\n  },\n];\n\nconst deltaFormat: Intl.NumberFormatOptions = {\n  style: \"percent\",\n  signDisplay: \"exceptZero\",\n  minimumFractionDigits: 1,\n  maximumFractionDigits: 1,\n};\n\nconst baseline = (range: Range) => metrics.map((m) => m.data[range]);\n\n/** One idle tick: each reading wanders a little and is pulled back toward its range's baseline. */\nfunction drift(readings: Reading[], range: Range, noise: number[][]): Reading[] {\n  return readings.map((reading, i) => {\n    const m = metrics[i];\n    const base = m.data[range];\n    const [a, b] = noise[i];\n    return {\n      value: m.round(reading.value + (base.value - reading.value) * 0.2 + base.value * m.wobble * (a * 2 - 1)),\n      delta: Math.round((reading.delta + (base.delta - reading.delta) * 0.2 + 0.006 * (b * 2 - 1)) * 1000) / 1000,\n    };\n  });\n}\n\n// The range switcher makes big jumps; between them the numbers drift every\n// couple of seconds, only while the dashboard is on screen.\nexport function OdometerDashboardDemo() {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const live = useInView(ref, { amount: 0.3 });\n  const [range, setRange] = React.useState<Range>(\"24h\");\n  const [readings, setReadings] = React.useState(() => baseline(\"24h\"));\n\n  React.useEffect(() => {\n    if (!live) return;\n    let timer = 0;\n    const tick = () => {\n      const noise = metrics.map(() => [Math.random(), Math.random()]);\n      setReadings((current) => drift(current, range, noise));\n      timer = window.setTimeout(tick, 1600 + Math.random() * 900);\n    };\n    timer = window.setTimeout(tick, 1600 + Math.random() * 900);\n    return () => window.clearTimeout(timer);\n  }, [live, range]);\n\n  const choose = (next: Range) => {\n    setRange(next);\n    setReadings(baseline(next));\n  };\n\n  const index = ranges.findIndex((r) => r.id === range);\n\n  return (\n    <div ref={ref} className=\"@container w-full max-w-5xl\">\n      <div className=\"flex flex-wrap items-center justify-between gap-4\">\n        <div className=\"flex items-center gap-3\">\n          <h3 className=\"text-lg font-semibold tracking-tight text-zinc-950 dark:text-zinc-50\">Overview</h3>\n          <span className=\"inline-flex items-center gap-1.5 text-xs text-zinc-500 dark:text-zinc-400\">\n            <span className=\"relative flex size-1.5\">\n              {live ? (\n                <span className=\"absolute inline-flex size-full animate-ping rounded-full bg-emerald-500 opacity-60\" />\n              ) : null}\n              <span className=\"relative inline-flex size-1.5 rounded-full bg-emerald-500\" />\n            </span>\n            Live\n          </span>\n        </div>\n        <div\n          role=\"radiogroup\"\n          aria-label=\"Time range\"\n          className=\"relative grid grid-cols-3 rounded-lg border border-zinc-200 bg-zinc-100 p-0.5 dark:border-zinc-800 dark:bg-zinc-900\"\n        >\n          <motion.span\n            aria-hidden\n            className=\"absolute inset-y-0.5 left-0.5 w-[calc((100%-0.25rem)/3)] rounded-md bg-white shadow-sm ring-1 shadow-zinc-950/10 ring-zinc-950/5 dark:bg-zinc-700 dark:ring-white/10\"\n            initial={false}\n            animate={{ x: `${index * 100}%` }}\n            transition={{ type: \"spring\", stiffness: 520, damping: 42 }}\n          />\n          {ranges.map((r) => (\n            <button\n              key={r.id}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={r.id === range}\n              onClick={() => choose(r.id)}\n              className={cn(\n                \"relative min-w-12 rounded-md px-3 py-1 font-mono text-xs transition-colors duration-200 outline-none focus-visible:ring-2 focus-visible:ring-zinc-400\",\n                r.id === range\n                  ? \"text-zinc-950 dark:text-zinc-50\"\n                  : \"text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200\",\n              )}\n            >\n              {r.id}\n            </button>\n          ))}\n        </div>\n      </div>\n\n      <div className=\"mt-5 grid gap-3 @lg:grid-cols-2 @4xl:grid-cols-4\">\n        {metrics.map((m, i) => {\n          const { value, delta } = readings[i];\n          const good = m.invert ? delta <= 0 : delta >= 0;\n          return (\n            <div\n              key={m.id}\n              className=\"rounded-2xl border border-zinc-200 bg-white p-5 shadow-sm shadow-zinc-950/[0.03] dark:border-zinc-800 dark:bg-zinc-900 dark:shadow-none\"\n            >\n              <div className=\"flex items-center justify-between gap-3\">\n                <p className=\"text-sm text-zinc-500 dark:text-zinc-400\">{m.label}</p>\n                <span\n                  className={cn(\n                    \"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-xs font-medium transition-colors duration-300\",\n                    good\n                      ? \"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400\"\n                      : \"bg-rose-500/10 text-rose-700 dark:text-rose-400\",\n                  )}\n                >\n                  <motion.svg\n                    aria-hidden\n                    viewBox=\"0 0 12 12\"\n                    fill=\"none\"\n                    stroke=\"currentColor\"\n                    strokeWidth=\"1.5\"\n                    strokeLinecap=\"round\"\n                    strokeLinejoin=\"round\"\n                    className=\"size-3\"\n                    initial={false}\n                    animate={{ rotate: delta < 0 ? 180 : 0 }}\n                    transition={{ type: \"spring\", stiffness: 300, damping: 22 }}\n                  >\n                    <path d=\"M6 9.5v-7M3 5.5l3-3 3 3\" />\n                  </motion.svg>\n                  <Odometer value={delta} format={deltaFormat} />\n                </span>\n              </div>\n              <p className=\"mt-4 text-[1.75rem] leading-none font-semibold tracking-[-0.03em] text-zinc-950 dark:text-zinc-50\">\n                <Odometer value={value} format={m.format} />\n              </p>\n              <p className=\"mt-3 text-xs text-zinc-500 dark:text-zinc-500\">\n                vs. previous {ranges[index].label}\n              </p>\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}