{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stat-cards-kpi","type":"registry:component","title":"Stat cards · KPI","description":"Headline figure that counts up with its delta, and a breakdown that springs open into a stacked bar.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/stat-cards/kpi.tsx","type":"registry:component","target":"components/examples/stat-cards/kpi.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { ArrowDownRight, ArrowUpRight, ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface KpiSegment {\n  label: string;\n  value: number;\n}\n\nexport interface KpiCardProps {\n  label?: string;\n  /** Period caption, e.g. \"October 2026\". */\n  period?: string;\n  value?: number;\n  /** Value for the previous period, used for the delta. */\n  previous?: number;\n  /** Label for the previous period, e.g. \"Sep\". */\n  previousLabel?: string;\n  format?: \"currency\" | \"number\";\n  currency?: string;\n  /** Parts that add up to `value`, shown in the breakdown. */\n  segments?: KpiSegment[];\n  /** When true a drop is the good direction (e.g. churn). */\n  invert?: boolean;\n  className?: string;\n}\n\nconst focus = \"outline-none focus-visible:shadow-[var(--focus-ring)]\";\nconst shades = [\"bg-ink\", \"bg-ink/55\", \"bg-ink/25\"];\n\n/** Headline KPI that counts up on mount, shows its delta with direction and word, and springs open a stacked breakdown. */\nexport function KpiCard({\n  label = \"Net revenue\",\n  period = \"October 2026\",\n  value = 84250,\n  previous = 74960,\n  previousLabel = \"Sep\",\n  format = \"currency\",\n  currency = \"USD\",\n  segments = [\n    { label: \"Subscriptions\", value: 61400 },\n    { label: \"Add-ons\", value: 15900 },\n    { label: \"Services\", value: 6950 },\n  ],\n  invert = false,\n  className,\n}: KpiCardProps) {\n  const reduce = useReducedMotion() ?? false;\n  const [open, setOpen] = React.useState(false);\n  const panelId = React.useId();\n\n  const fmt = React.useMemo(\n    () => (format === \"currency\" ? new Intl.NumberFormat(\"en-US\", { style: \"currency\", currency, maximumFractionDigits: 0 }) : new Intl.NumberFormat(\"en-US\")),\n    [format, currency],\n  );\n  const mv = useSpring(reduce ? value : 0, { stiffness: 55, damping: 18 });\n  const text = useTransform(mv, (v) => fmt.format(Math.round(v)));\n  React.useEffect(() => {\n    if (reduce) mv.jump(value);\n    else mv.set(value);\n  }, [value, reduce, mv]);\n\n  const change = previous ? (value - previous) / previous : 0;\n  const up = change >= 0;\n  const good = invert ? !up : up;\n  const total = segments.reduce((a, s) => a + s.value, 0) || 1;\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-center justify-between gap-3\">\n        <p className=\"text-[13px] font-medium text-ink-muted\">{label}</p>\n        <p className=\"font-mono text-[11px] text-ink-subtle\">{period}</p>\n      </div>\n      <p className=\"mt-2 font-display text-[38px] font-semibold leading-none tracking-[-1.2px] text-ink tabular-nums\">\n        <motion.span aria-hidden>{text}</motion.span>\n        <span className=\"sr-only\">{fmt.format(value)}</span>\n      </p>\n      <div className=\"mt-3 flex flex-wrap items-center gap-2\">\n        <motion.span\n          initial={reduce ? false : { opacity: 0, y: 6 }}\n          animate={{ opacity: 1, y: 0 }}\n          transition={{ type: \"spring\", stiffness: 300, damping: 24, delay: reduce ? 0 : 0.5 }}\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          <span className=\"sr-only\">{up ? \"Up\" : \"Down\"}</span>\n          {Math.abs(change * 100).toFixed(1)}%\n        </motion.span>\n        <span className=\"text-xs text-ink-subtle\">\n          vs {fmt.format(previous)} in {previousLabel}\n        </span>\n      </div>\n\n      <div className=\"mt-5 border-t border-border pt-3\">\n        <button\n          type=\"button\"\n          aria-expanded={open}\n          aria-controls={panelId}\n          onClick={() => setOpen((o) => !o)}\n          className={cn(\"flex w-full items-center justify-between rounded-xs py-1 text-[13px] font-medium text-ink\", focus)}\n        >\n          {open ? \"Hide breakdown\" : \"Show breakdown\"}\n          <ChevronDown aria-hidden className={cn(\"size-4 text-ink-muted transition-transform duration-300 ease-spring\", open && \"rotate-180\")} />\n        </button>\n        <AnimatePresence initial={false}>\n          {open && (\n            <motion.div\n              id={panelId}\n              initial={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n              animate={reduce ? { opacity: 1 } : { height: \"auto\", opacity: 1 }}\n              exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n              transition={{ type: \"spring\", stiffness: 320, damping: 32 }}\n              className=\"overflow-hidden\"\n            >\n              <div className=\"mt-3 flex h-2.5 gap-0.5 overflow-hidden rounded-full\">\n                {segments.map((s, i) => (\n                  <motion.span\n                    key={s.label}\n                    className={cn(\"h-full origin-left first:rounded-l-full last:rounded-r-full\", shades[i % shades.length])}\n                    style={{ width: `${(s.value / total) * 100}%` }}\n                    initial={reduce ? false : { scaleX: 0 }}\n                    animate={{ scaleX: 1 }}\n                    transition={{ type: \"spring\", stiffness: 160, damping: 22, delay: reduce ? 0 : 0.08 + i * 0.08 }}\n                  />\n                ))}\n              </div>\n              <ul className=\"mt-3 space-y-1.5 pb-1\">\n                {segments.map((s, i) => (\n                  <li key={s.label} className=\"flex items-center gap-2 text-[13px]\">\n                    <span aria-hidden className={cn(\"size-2 rounded-full\", shades[i % shades.length])} />\n                    <span className=\"flex-1 text-ink-muted\">{s.label}</span>\n                    <span className=\"font-medium tabular-nums text-ink\">{fmt.format(s.value)}</span>\n                    <span className=\"w-10 text-right font-mono text-[11px] text-ink-subtle\">{Math.round((s.value / total) * 100)}%</span>\n                  </li>\n                ))}\n              </ul>\n            </motion.div>\n          )}\n        </AnimatePresence>\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#kpi"}}