{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stat-cards-sparkline","type":"registry:component","title":"Stat cards · Sparkline","description":"Period tabs redraw the line; pointer or arrow keys scrub to any point and the figure crossfades.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/stat-cards/sparkline.tsx","type":"registry:component","target":"components/examples/stat-cards/sparkline.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { TrendingDown, TrendingUp } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SparkSeries {\n  /** Tab label, e.g. \"7D\". */\n  key: string;\n  /** Word used in the caption, e.g. \"past 7 days\". */\n  caption: string;\n  points: number[];\n  /** Label per point, same length as points. */\n  labels: string[];\n}\n\nexport interface SparklineStatCardProps {\n  label?: string;\n  unit?: string;\n  series?: SparkSeries[];\n  defaultKey?: string;\n  className?: string;\n}\n\nconst DAYS = [\"Sep 26\", \"Sep 27\", \"Sep 28\", \"Sep 29\", \"Sep 30\", \"Oct 1\", \"Oct 2\"];\nconst WEEKS = [\"Aug 7\", \"Aug 14\", \"Aug 21\", \"Aug 28\", \"Sep 4\", \"Sep 11\", \"Sep 18\", \"Sep 25\", \"Oct 2\"];\nconst MONTHS = [\"Nov\", \"Dec\", \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\"];\n\nconst DEFAULT_SERIES: SparkSeries[] = [\n  { key: \"7D\", caption: \"past 7 days\", points: [1840, 2120, 1980, 2410, 2290, 2630, 2754], labels: DAYS },\n  { key: \"60D\", caption: \"past 60 days\", points: [12400, 13150, 12890, 14020, 13700, 14980, 15420, 15110, 16240], labels: WEEKS },\n  { key: \"1Y\", caption: \"past year\", points: [38e3, 41e3, 39.5e3, 44e3, 47e3, 46e3, 51e3, 55e3, 53e3, 58e3, 61e3, 64.8e3], labels: MONTHS },\n];\n\nconst focus = \"outline-none focus-visible:shadow-[var(--focus-ring)]\";\nconst W = 300;\nconst H = 72;\n\nfunction coords(points: number[]) {\n  const min = Math.min(...points);\n  const span = Math.max(...points) - min || 1;\n  return points.map((p, i) => ({ x: (i / (points.length - 1)) * W, y: H - 6 - ((p - min) / span) * (H - 14) }));\n}\n\n/** Stat with a scrubbable sparkline: period tabs redraw the line, and pointer or arrow keys read out any point. */\nexport function SparklineStatCard({ label = \"Active users\", unit = \"\", series = DEFAULT_SERIES, defaultKey, className }: SparklineStatCardProps) {\n  const reduce = useReducedMotion() ?? false;\n  const baseId = React.useId();\n  const [key, setKey] = React.useState(defaultKey ?? series[0]?.key);\n  const [hover, setHover] = React.useState<number | null>(null);\n  const s = series.find((x) => x.key === key) ?? series[0];\n  const pts = coords(s.points);\n  const d = pts.map((p, i) => `${i ? \"L\" : \"M\"}${p.x.toFixed(1)} ${p.y.toFixed(1)}`).join(\" \");\n  const idx = hover ?? s.points.length - 1;\n  const value = s.points[idx];\n  const change = (s.points[s.points.length - 1] - s.points[0]) / s.points[0];\n  const up = change >= 0;\n  const fmt = (n: number) => n.toLocaleString(\"en-US\") + unit;\n\n  function onMove(e: React.PointerEvent<SVGSVGElement>) {\n    const r = e.currentTarget.getBoundingClientRect();\n    const t = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));\n    setHover(Math.round(t * (s.points.length - 1)));\n  }\n\n  function onKey(e: React.KeyboardEvent) {\n    if (e.key !== \"ArrowLeft\" && e.key !== \"ArrowRight\") return;\n    e.preventDefault();\n    const d2 = e.key === \"ArrowRight\" ? 1 : -1;\n    setHover(Math.min(s.points.length - 1, Math.max(0, idx + d2)));\n  }\n\n  return (\n    <section aria-label={label} className={cn(\"w-full max-w-[360px] rounded-xl border border-border bg-surface-raised p-5 shadow-sm\", className)}>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <p className=\"text-[13px] font-medium text-ink-muted\">{label}</p>\n          <div className=\"relative mt-1.5 h-9\">\n            <AnimatePresence mode=\"popLayout\" initial={false}>\n              <motion.p\n                key={`${s.key}-${idx}`}\n                initial={{ opacity: 0, filter: \"blur(6px)\", y: 4 }}\n                animate={{ opacity: 1, filter: \"blur(0px)\", y: 0 }}\n                exit={{ opacity: 0, filter: \"blur(6px)\", y: -4 }}\n                transition={{ duration: 0.18 }}\n                className=\"font-display text-[32px] font-semibold leading-9 tracking-[-1px] text-ink tabular-nums\"\n              >\n                {fmt(value)}\n              </motion.p>\n            </AnimatePresence>\n          </div>\n          <p className=\"mt-1 text-xs text-ink-subtle\" aria-live=\"polite\">\n            {hover === null ? (\n              <span className={cn(\"inline-flex items-center gap-1 font-medium\", up ? \"text-success\" : \"text-danger\")}>\n                {up ? <TrendingUp aria-hidden className=\"size-3.5\" /> : <TrendingDown aria-hidden className=\"size-3.5\" />}\n                {up ? \"Up\" : \"Down\"} {Math.abs(change * 100).toFixed(1)}%<span className=\"font-normal text-ink-subtle\">{s.caption}</span>\n              </span>\n            ) : (\n              <span>{s.labels[idx]}</span>\n            )}\n          </p>\n        </div>\n        <div role=\"group\" aria-label=\"Period\" className=\"flex shrink-0 gap-0.5 rounded-full bg-surface-sunken p-0.5\">\n          {series.map((x) => {\n            const on = x.key === s.key;\n            return (\n              <button\n                key={x.key}\n                type=\"button\"\n                aria-pressed={on}\n                onClick={() => {\n                  setKey(x.key);\n                  setHover(null);\n                }}\n                className={cn(\"relative h-7 rounded-full px-2.5 font-mono text-[11px] transition-colors\", on ? \"text-ink\" : \"text-ink-subtle hover:text-ink\", focus)}\n              >\n                {on && <motion.span layoutId={`${baseId}-tab`} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 32 }} className=\"absolute inset-0 rounded-full bg-surface-raised shadow-sm\" />}\n                <span className=\"relative\">{x.key}</span>\n              </button>\n            );\n          })}\n        </div>\n      </div>\n\n      <svg\n        viewBox={`0 0 ${W} ${H}`}\n        preserveAspectRatio=\"none\"\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={`${label} over the ${s.caption}`}\n        aria-valuemin={0}\n        aria-valuemax={s.points.length - 1}\n        aria-valuenow={idx}\n        aria-valuetext={`${s.labels[idx]}: ${fmt(value)}`}\n        onPointerMove={onMove}\n        onPointerLeave={() => setHover(null)}\n        onKeyDown={onKey}\n        onBlur={() => setHover(null)}\n        className={cn(\"mt-4 h-[72px] w-full touch-none overflow-visible rounded-xs text-ink\", focus)}\n      >\n        <defs>\n          <linearGradient id={`${baseId}-g`} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n            <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity={0.14} />\n            <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity={0} />\n          </linearGradient>\n        </defs>\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          <motion.g key={s.key} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0, transition: { duration: 0.12 } }}>\n            <path d={`${d} L${W} ${H} L0 ${H} Z`} fill={`url(#${baseId}-g)`} />\n            <motion.path\n              d={d}\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth={2}\n              strokeLinejoin=\"round\"\n              strokeLinecap=\"round\"\n              vectorEffect=\"non-scaling-stroke\"\n              initial={{ pathLength: reduce ? 1 : 0 }}\n              animate={{ pathLength: 1 }}\n              transition={{ duration: 0.8, ease: [0.22, 1, 0.36, 1] }}\n            />\n          </motion.g>\n        </AnimatePresence>\n        <line x1={pts[idx].x} x2={pts[idx].x} y1={0} y2={H} stroke=\"currentColor\" strokeOpacity={hover === null ? 0 : 0.18} strokeDasharray=\"3 3\" vectorEffect=\"non-scaling-stroke\" />\n      </svg>\n      <div className=\"pointer-events-none relative -mt-[72px] h-[72px]\" aria-hidden>\n        <motion.span\n          className=\"absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-surface-raised bg-volt shadow-sm\"\n          animate={{ left: `${(pts[idx].x / W) * 100}%`, top: pts[idx].y }}\n          transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 36 }}\n        />\n      </div>\n      <div className=\"mt-2 flex justify-between font-mono text-[10.5px] text-ink-subtle\">\n        <span>{s.labels[0]}</span>\n        <span>{s.labels[s.labels.length - 1]}</span>\n      </div>\n    </section>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["examples","stats","kpi","metric","dashboard","sparkline","progress","goal","comparison","analytics"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/stat-cards#sparkline"}}