{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stat-cards-comparison","type":"registry:component","title":"Stat cards · Comparison","description":"Metric tabs swap two period bars that spring to new lengths while the delta crossfades.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/stat-cards/comparison.tsx","type":"registry:component","target":"components/examples/stat-cards/comparison.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { ArrowDownRight, ArrowUpRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ComparisonMetric {\n  key: string;\n  label: string;\n  current: number;\n  previous: number;\n  /** Prefix such as \"$\". */\n  prefix?: string;\n  suffix?: string;\n  /** A drop is good (e.g. refund rate). */\n  invert?: boolean;\n}\n\nexport interface ComparisonStatCardProps {\n  title?: string;\n  currentLabel?: string;\n  previousLabel?: string;\n  metrics?: ComparisonMetric[];\n  defaultKey?: string;\n  className?: string;\n}\n\nconst DEFAULT_METRICS: ComparisonMetric[] = [\n  { key: \"revenue\", label: \"Revenue\", current: 48210, previous: 39870, prefix: \"$\" },\n  { key: \"orders\", label: \"Orders\", current: 1284, previous: 1342 },\n  { key: \"aov\", label: \"Avg. order\", current: 37.55, previous: 29.71, prefix: \"$\" },\n  { key: \"refunds\", label: \"Refunds\", current: 1.8, previous: 2.6, suffix: \"%\", invert: true },\n];\n\nconst focus = \"outline-none focus-visible:shadow-[var(--focus-ring)]\";\n\nfunction format(m: ComparisonMetric, n: number) {\n  const digits = n % 1 ? 2 : 0;\n  return `${m.prefix ?? \"\"}${n.toLocaleString(\"en-US\", { minimumFractionDigits: digits, maximumFractionDigits: digits })}${m.suffix ?? \"\"}`;\n}\n\n/** Two-period comparison: pick a metric and both bars spring to their new lengths while the delta crossfades. */\nexport function ComparisonStatCard({\n  title = \"This month vs last\",\n  currentLabel = \"Oct 1 – 31\",\n  previousLabel = \"Sep 1 – 30\",\n  metrics = DEFAULT_METRICS,\n  defaultKey,\n  className,\n}: ComparisonStatCardProps) {\n  const reduce = useReducedMotion() ?? false;\n  const baseId = React.useId();\n  const [key, setKey] = React.useState(defaultKey ?? metrics[0]?.key);\n  const m = metrics.find((x) => x.key === key) ?? metrics[0];\n  const max = Math.max(m.current, m.previous) || 1;\n  const change = m.previous ? (m.current - m.previous) / m.previous : 0;\n  const up = change >= 0;\n  const good = m.invert ? !up : up;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 170, damping: 22 };\n\n  const rows = [\n    { label: currentLabel, value: m.current, bar: \"bg-volt\", text: \"text-ink\" },\n    { label: previousLabel, value: m.previous, bar: \"bg-ink-subtle/45\", text: \"text-ink-muted\" },\n  ];\n\n  return (\n    <section aria-label={title} className={cn(\"w-full max-w-[400px] rounded-xl border border-border bg-surface-raised p-5 shadow-sm\", className)}>\n      <div className=\"flex items-center justify-between gap-3\">\n        <h3 className=\"text-[13px] font-medium text-ink-muted\">{title}</h3>\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          <motion.span\n            key={m.key}\n            initial={{ opacity: 0, filter: \"blur(6px)\", scale: 0.9 }}\n            animate={{ opacity: 1, filter: \"blur(0px)\", scale: 1 }}\n            exit={{ opacity: 0, filter: \"blur(6px)\", scale: 0.9 }}\n            transition={{ duration: 0.2 }}\n            className={cn(\"inline-flex items-center gap-0.5 rounded-full px-2 py-0.5 text-xs font-semibold\", good ? \"bg-success/12 text-success\" : \"bg-danger/12 text-danger\")}\n          >\n            {up ? <ArrowUpRight aria-hidden className=\"size-3.5\" /> : <ArrowDownRight aria-hidden className=\"size-3.5\" />}\n            {up ? \"+\" : \"−\"}\n            {Math.abs(change * 100).toFixed(1)}%<span className=\"sr-only\">{good ? \", better\" : \", worse\"}</span>\n          </motion.span>\n        </AnimatePresence>\n      </div>\n\n      <div role=\"tablist\" aria-label=\"Metric\" className=\"mt-3 flex gap-1 overflow-x-auto [scrollbar-width:none]\">\n        {metrics.map((x) => {\n          const on = x.key === m.key;\n          return (\n            <button\n              key={x.key}\n              type=\"button\"\n              role=\"tab\"\n              aria-selected={on}\n              aria-controls={`${baseId}-panel`}\n              onClick={() => setKey(x.key)}\n              onKeyDown={(e) => {\n                if (e.key !== \"ArrowRight\" && e.key !== \"ArrowLeft\") return;\n                const i = metrics.findIndex((y) => y.key === m.key);\n                const next = metrics[(i + (e.key === \"ArrowRight\" ? 1 : -1) + metrics.length) % metrics.length];\n                setKey(next.key);\n                (e.currentTarget.parentElement?.querySelectorAll(\"button\")[metrics.indexOf(next)] as HTMLButtonElement | undefined)?.focus();\n              }}\n              tabIndex={on ? 0 : -1}\n              className={cn(\"relative h-8 shrink-0 rounded-full px-3 text-[12.5px] font-medium transition-colors\", on ? \"text-bg\" : \"text-ink-muted hover:text-ink\", focus)}\n            >\n              {on && <motion.span layoutId={`${baseId}-m`} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 32 }} className=\"absolute inset-0 rounded-full bg-ink\" />}\n              <span className=\"relative\">{x.label}</span>\n            </button>\n          );\n        })}\n      </div>\n\n      <div id={`${baseId}-panel`} role=\"tabpanel\" aria-label={m.label} className=\"mt-5 space-y-4\">\n        {rows.map((r) => (\n          <div key={r.label}>\n            <div className=\"flex items-baseline justify-between gap-3\">\n              <span className=\"text-xs text-ink-subtle\">{r.label}</span>\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                <motion.span\n                  key={`${m.key}-${r.value}`}\n                  initial={{ opacity: 0, y: 6 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  exit={{ opacity: 0, y: -6 }}\n                  transition={{ duration: 0.2 }}\n                  className={cn(\"font-display text-xl font-semibold tracking-[-0.4px] tabular-nums\", r.text)}\n                >\n                  {format(m, r.value)}\n                </motion.span>\n              </AnimatePresence>\n            </div>\n            <div className=\"mt-1.5 h-3 overflow-hidden rounded-full bg-surface-sunken\">\n              <motion.div className={cn(\"h-full origin-left rounded-full\", r.bar)} initial={reduce ? false : { scaleX: 0 }} animate={{ scaleX: r.value / max }} transition={spring} />\n            </div>\n          </div>\n        ))}\n      </div>\n      <p className=\"mt-4 text-xs text-ink-subtle\">\n        {m.label} {up ? \"rose\" : \"fell\"} by {format(m, Math.abs(Math.round((m.current - m.previous) * 100) / 100))} against the previous period.\n      </p>\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#comparison"}}