{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "savings-goal-tracker",
  "title": "Savings Goal Tracker",
  "description": "A savings goals screen: goal tabs with progress bars, a counting balance with a progress ring and an on-track finish date, a balance chart with a dashed projection to the goal line and a hover crosshair, quick and custom contributions with milestone messages, and an auto-save switch with a monthly amount slider that moves the finish date.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/savings-goal-tracker/savings-goal-tracker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface SavingsGoal {\n  id: string;\n  name: string;\n  emoji: string;\n  target: number;\n  history: number[]; // balance at the end of each past month, oldest first\n  monthly: number;\n  autoSave: boolean;\n  color: string;\n}\n\nexport interface SavingsGoalTrackerProps {\n  goals?: SavingsGoal[];\n  /** Month of the last history point, as YYYY-MM. */\n  currentMonth?: string;\n  currency?: string;\n  onContribute?: (id: string, amount: number) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.64)\", faint: \"rgba(245,244,241,0.38)\", card: \"#121212\", well: \"rgba(255,255,255,0.04)\", border: \"rgba(255,255,255,0.08)\", grid: \"rgba(255,255,255,0.06)\", track: \"rgba(255,255,255,0.08)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", good: \"#4ADE80\", warn: \"#FBBF24\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.64)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", well: \"rgba(10,10,10,0.03)\", border: \"rgba(10,10,10,0.09)\", grid: \"rgba(10,10,10,0.06)\", track: \"rgba(10,10,10,0.08)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", good: \"#15803D\", warn: \"#B45309\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst GOALS: SavingsGoal[] = [\n  { id: \"emergency\", name: \"Emergency fund\", emoji: \"🛟\", target: 6000, history: [2100, 2400, 2750, 3050, 3400, 3780], monthly: 350, autoSave: true, color: \"#3987e5\" },\n  { id: \"japan\", name: \"Japan trip\", emoji: \"🗻\", target: 3200, history: [300, 520, 700, 980, 1150, 1420], monthly: 200, autoSave: true, color: \"#d95926\" },\n  { id: \"laptop\", name: \"New laptop\", emoji: \"💻\", target: 1800, history: [0, 0, 150, 260, 420, 610], monthly: 120, autoSave: false, color: \"#199e70\" },\n];\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\nconst addMonths = (ym: string, n: number) => {\n  const [y, m] = ym.split(\"-\").map(Number);\n  const t = y * 12 + (m - 1) + n;\n  return { y: Math.floor(t / 12), m: t % 12 };\n};\nconst label = (ym: string, n: number, withYear = false) => {\n  const { y, m } = addMonths(ym, n);\n  return withYear ? `${MONTHS[m]} ${y}` : MONTHS[m];\n};\n\nfunction Counter({ value, currency, reduce }: { value: number; currency: string; reduce: boolean }) {\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, (v) => `${currency}${Math.round(v).toLocaleString(\"en-US\")}`);\n  React.useEffect(() => {\n    if (reduce) {\n      mv.set(value);\n      return;\n    }\n    const c = animate(mv, value, { duration: 0.6, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [value, reduce, mv]);\n  return <motion.span>{text}</motion.span>;\n}\n\nexport function SavingsGoalTracker({ goals: initial = GOALS, currentMonth = \"2026-11\", currency = \"€\", onContribute, theme = \"dark\", className }: SavingsGoalTrackerProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [goals, setGoals] = React.useState(initial);\n  const [active, setActive] = React.useState(initial[0]?.id ?? \"\");\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [custom, setCustom] = React.useState(\"\");\n  const [cheer, setCheer] = React.useState<string | null>(null);\n  const [chartW, setChartW] = React.useState(560);\n  const chartRef = React.useRef<HTMLDivElement>(null);\n\n  // Draw the chart at its real pixel width so labels stay readable on phones.\n  React.useEffect(() => {\n    const el = chartRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([e]) => setChartW(Math.max(280, Math.round(e.contentRect.width))));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!cheer) return;\n    const t = setTimeout(() => setCheer(null), 2600);\n    return () => clearTimeout(t);\n  }, [cheer]);\n\n  const g = goals.find((x) => x.id === active) ?? goals[0];\n  const saved = g.history[g.history.length - 1];\n  const pct = Math.min(1, saved / g.target);\n  const left = Math.max(0, g.target - saved);\n  const rate = g.autoSave ? g.monthly : 0;\n  const monthsLeft = left === 0 ? 0 : rate > 0 ? Math.ceil(left / rate) : null;\n  const money = (n: number) => `${currency}${Math.round(n).toLocaleString(\"en-US\")}`;\n\n  // Chart: past balances + projection to the target, one y-axis.\n  const past = g.history.length;\n  const futureN = monthsLeft === null ? 6 : Math.min(Math.max(monthsLeft, 1), 18);\n  const proj = Array.from({ length: futureN }, (_, i) => Math.min(g.target, saved + rate * (i + 1)));\n  const series = [...g.history, ...proj];\n  const W = chartW;\n  const H = chartW < 420 ? 180 : 200;\n  const PAD = { l: 44, r: 12, t: 14, b: 26 };\n  const maxY = Math.max(g.target * 1.08, ...series);\n  const x = (i: number) => PAD.l + (i / (series.length - 1)) * (W - PAD.l - PAD.r);\n  const y = (v: number) => PAD.t + (1 - v / maxY) * (H - PAD.t - PAD.b);\n  const pastPath = g.history.map((v, i) => `${i ? \"L\" : \"M\"}${x(i).toFixed(1)},${y(v).toFixed(1)}`).join(\" \");\n  const projPath = [saved, ...proj].map((v, i) => `${i ? \"L\" : \"M\"}${x(past - 1 + i).toFixed(1)},${y(v).toFixed(1)}`).join(\" \");\n  const area = `${pastPath} L${x(past - 1).toFixed(1)},${y(0)} L${x(0)},${y(0)} Z`;\n  const ticks = [0, 0.5, 1].map((f) => Math.round((g.target * f) / 100) * 100);\n  const step = Math.ceil(series.length / 7);\n\n  const contribute = (amount: number) => {\n    if (amount <= 0) return;\n    const before = saved / g.target;\n    setGoals((list) => list.map((x) => (x.id === g.id ? { ...x, history: [...x.history.slice(0, -1), x.history[x.history.length - 1] + amount] } : x)));\n    onContribute?.(g.id, amount);\n    const after = (saved + amount) / g.target;\n    if (before < 1 && after >= 1) setCheer(`🎉 ${g.name} is fully funded!`);\n    else if (before < 0.5 && after >= 0.5) setCheer(`Halfway there on ${g.name}`);\n    else setCheer(`+${money(amount)} added to ${g.name}`);\n  };\n  const update = (patch: Partial<SavingsGoal>) => setGoals((list) => list.map((x) => (x.id === g.id ? { ...x, ...patch } : x)));\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const onTrack = monthsLeft !== null;\n  const hv = hover !== null ? (series[hover] ?? null) : null;\n\n  return (\n    <section className={cn(\"@container relative w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-5xl px-4 py-10 @[640px]:px-6\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em]\">Savings goals</h2>\n            <p className=\"m-0 mt-1 text-[13.5px]\" style={{ color: p.muted }}>\n              {money(goals.reduce((a, x) => a + x.history[x.history.length - 1], 0))} saved across {goals.length} goals\n            </p>\n          </div>\n        </div>\n\n        <div className=\"mt-5 grid grid-cols-1 gap-4 @[780px]:grid-cols-[260px_minmax(0,1fr)]\">\n          {/* Goal list */}\n          <div role=\"tablist\" aria-label=\"Goals\" aria-orientation=\"vertical\" className=\"flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] @[780px]:flex-col @[780px]:overflow-visible\">\n            {goals.map((x) => {\n              const s = x.history[x.history.length - 1];\n              const f = Math.min(1, s / x.target);\n              const sel = x.id === g.id;\n              return (\n                <button key={x.id} type=\"button\" role=\"tab\" aria-selected={sel} aria-controls={`${uid}-panel`} onClick={() => (setActive(x.id), setHover(null))} className={cn(\"min-w-[200px] shrink-0 cursor-pointer rounded-xl border p-3 text-left @[780px]:min-w-0\", focus)} style={{ borderColor: sel ? p.ring.replace(/[\\d.]+\\)$/, \"0.4)\") : p.border, background: sel ? p.well : p.card, color: p.text, ...ring }}>\n                  <span className=\"flex items-center gap-2.5\">\n                    <span className=\"grid h-8 w-8 place-items-center rounded-lg text-[16px]\" style={{ background: `${x.color}26` }} aria-hidden=\"true\">\n                      {x.emoji}\n                    </span>\n                    <span className=\"min-w-0 flex-1\">\n                      <span className=\"block truncate text-[13px] font-medium\">{x.name}</span>\n                      <span className=\"block text-[11.5px] tabular-nums\" style={{ color: p.faint }}>\n                        {money(s)} of {money(x.target)}\n                      </span>\n                    </span>\n                    <span className=\"text-[12px] font-medium tabular-nums\">{Math.round(f * 100)}%</span>\n                  </span>\n                  <span className=\"mt-2.5 block h-1.5 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                    <motion.span className=\"block h-full rounded-full\" initial={false} animate={{ width: `${f * 100}%` }} transition={{ duration: reduce ? 0 : 0.6, ease: [0.22, 1, 0.36, 1] }} style={{ background: x.color }} />\n                  </span>\n                </button>\n              );\n            })}\n          </div>\n\n          {/* Detail */}\n          <div id={`${uid}-panel`} role=\"tabpanel\" className=\"rounded-2xl border p-5\" style={{ background: p.card, borderColor: p.border }}>\n            <div className=\"flex items-start justify-between gap-4\">\n              <div className=\"min-w-0\">\n                <p className=\"m-0 flex items-center gap-2 text-[13px]\" style={{ color: p.muted }}>\n                  <span aria-hidden=\"true\">{g.emoji}</span> {g.name}\n                </p>\n                <p className=\"m-0 mt-1.5 text-[30px] leading-none font-semibold tracking-[-0.02em] tabular-nums\">\n                  <Counter value={saved} currency={currency} reduce={reduce} />\n                  <span className=\"ml-1.5 text-[14px] font-normal\" style={{ color: p.faint }}>\n                    of {money(g.target)}\n                  </span>\n                </p>\n                <p className=\"m-0 mt-2 flex items-baseline gap-1.5 text-[12.5px]\" style={{ color: left === 0 ? p.good : onTrack ? p.text : p.warn }} aria-live=\"polite\">\n                  <span aria-hidden=\"true\">{left === 0 ? \"✓\" : onTrack ? \"●\" : \"▲\"}</span>\n                  {left === 0 ? \"Goal reached\" : onTrack ? `On track for ${label(currentMonth, monthsLeft!, true)} · ${monthsLeft} ${monthsLeft === 1 ? \"month\" : \"months\"} to go` : \"No auto-save · turn it on to see a finish date\"}\n                </p>\n              </div>\n              <svg width=\"64\" height=\"64\" viewBox=\"0 0 64 64\" className=\"shrink-0\" role=\"img\" aria-label={`${Math.round(pct * 100)}% funded`}>\n                <circle cx=\"32\" cy=\"32\" r=\"27\" fill=\"none\" stroke={p.track} strokeWidth=\"6\" />\n                <motion.circle cx=\"32\" cy=\"32\" r=\"27\" fill=\"none\" stroke={g.color} strokeWidth=\"6\" strokeLinecap=\"round\" transform=\"rotate(-90 32 32)\" initial={false} animate={{ pathLength: pct }} transition={{ duration: reduce ? 0 : 0.7, ease: [0.22, 1, 0.36, 1] }} />\n                <text x=\"32\" y=\"36\" textAnchor=\"middle\" fontSize=\"13\" fontWeight=\"600\" fill={p.text}>\n                  {Math.round(pct * 100)}%\n                </text>\n              </svg>\n            </div>\n\n            {/* Chart */}\n            <div ref={chartRef} className=\"relative mt-4\">\n              <svg viewBox={`0 0 ${W} ${H}`} className=\"block h-auto w-full touch-none\" role=\"img\" aria-label={`Balance from ${label(currentMonth, -(past - 1))} to ${label(currentMonth, 0)}, projected to reach ${money(g.target)}${onTrack ? ` in ${label(currentMonth, monthsLeft!, true)}` : \"\"}`} onPointerMove={(e) => {\n                const r = e.currentTarget.getBoundingClientRect();\n                const px = ((e.clientX - r.left) / r.width) * W;\n                const i = Math.round(((px - PAD.l) / (W - PAD.l - PAD.r)) * (series.length - 1));\n                setHover(i >= 0 && i < series.length ? i : null);\n              }} onPointerLeave={() => setHover(null)}>\n                {ticks.map((v) => (\n                  <g key={v}>\n                    <line x1={PAD.l} x2={W - PAD.r} y1={y(v)} y2={y(v)} stroke={p.grid} />\n                    <text x={PAD.l - 8} y={y(v) + 3.5} textAnchor=\"end\" fontSize=\"10\" fill={p.faint}>\n                      {v >= 1000 ? `${currency}${(v / 1000).toFixed(v % 1000 ? 1 : 0)}k` : `${currency}${v}`}\n                    </text>\n                  </g>\n                ))}\n                <line x1={PAD.l} x2={W - PAD.r} y1={y(g.target)} y2={y(g.target)} stroke={p.text} strokeOpacity=\"0.5\" strokeDasharray=\"2 4\" />\n                <text x={W - PAD.r} y={y(g.target) - 5} textAnchor=\"end\" fontSize=\"10\" fill={p.muted}>\n                  Goal {money(g.target)}\n                </text>\n                <motion.path key={`a-${g.id}`} d={area} fill={g.color} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 0.12 }} transition={{ duration: 0.5 }} />\n                <motion.path key={`p-${g.id}`} d={pastPath} fill=\"none\" stroke={g.color} strokeWidth=\"2\" strokeLinejoin=\"round\" initial={reduce ? false : { pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.7, ease: [0.22, 1, 0.36, 1] }} />\n                <path d={projPath} fill=\"none\" stroke={g.color} strokeWidth=\"2\" strokeDasharray=\"5 5\" strokeOpacity={rate ? 0.8 : 0.3} />\n                <circle cx={x(past - 1)} cy={y(saved)} r=\"4.5\" fill={g.color} stroke={p.card} strokeWidth=\"2\" />\n                {series.map((_, i) =>\n                  (i % step === 0 && Math.abs(i - (past - 1)) >= Math.min(step, 2)) || i === past - 1 ? (\n                    <text key={i} x={x(i)} y={H - 8} textAnchor=\"middle\" fontSize=\"10\" fill={i === past - 1 ? p.text : p.faint}>\n                      {i === past - 1 ? \"Now\" : label(currentMonth, i - (past - 1))}\n                    </text>\n                  ) : null,\n                )}\n                {hover !== null && hv !== null && (\n                  <g pointerEvents=\"none\">\n                    <line x1={x(hover)} x2={x(hover)} y1={PAD.t} y2={H - PAD.b} stroke={p.text} strokeOpacity=\"0.3\" />\n                    <circle cx={x(hover)} cy={y(hv)} r=\"4\" fill={p.card} stroke={g.color} strokeWidth=\"2\" />\n                  </g>\n                )}\n              </svg>\n              {hover !== null && hv !== null && (\n                <div className=\"pointer-events-none absolute top-0 rounded-lg border px-2.5 py-1.5 text-[11.5px] whitespace-nowrap shadow-lg\" style={{ left: `${(x(hover) / W) * 100}%`, transform: `translateX(${hover > series.length / 2 ? \"-105%\" : \"5%\"})`, background: p.card, borderColor: p.border }}>\n                  <span style={{ color: p.faint }}>{label(currentMonth, hover - (past - 1), true)}</span>\n                  <span className=\"ml-2 font-semibold tabular-nums\">{money(hv)}</span>\n                  <span className=\"ml-1.5\" style={{ color: p.faint }}>\n                    {hover >= past ? \"projected\" : hover === past - 1 ? \"now\" : \"\"}\n                  </span>\n                </div>\n              )}\n              <div className=\"mt-1 flex gap-4 text-[11px]\" style={{ color: p.faint }}>\n                <span className=\"flex items-center gap-1.5\">\n                  <span className=\"h-0.5 w-4 rounded\" style={{ background: g.color }} /> Saved\n                </span>\n                <span className=\"flex items-center gap-1.5\">\n                  <span className=\"w-4 border-t-2 border-dashed\" style={{ borderColor: g.color }} /> Projected\n                </span>\n              </div>\n            </div>\n\n            {/* Actions */}\n            <div className=\"mt-5 grid grid-cols-1 gap-4 border-t pt-4 @[560px]:grid-cols-2\" style={{ borderColor: p.border }}>\n              <div>\n                <p className=\"m-0 text-[12.5px] font-medium\">Add money</p>\n                <div className=\"mt-2 flex flex-wrap gap-1.5\">\n                  {[50, 100, 250].map((n) => (\n                    <button key={n} type=\"button\" onClick={() => contribute(n)} className={cn(\"h-8 cursor-pointer rounded-lg border px-3 text-[12.5px] font-medium tabular-nums\", focus)} style={{ borderColor: p.border, background: \"transparent\", color: p.text, ...ring }}>\n                      +{money(n)}\n                    </button>\n                  ))}\n                  <form\n                    className=\"flex min-w-[130px] flex-1 items-center rounded-lg border focus-within:ring-2\"\n                    style={{ borderColor: p.border, ...ring }}\n                    onSubmit={(e) => {\n                      e.preventDefault();\n                      contribute(Number(custom) || 0);\n                      setCustom(\"\");\n                    }}\n                  >\n                    <input value={custom} onChange={(e) => setCustom(e.target.value.replace(/\\D/g, \"\").slice(0, 6))} inputMode=\"numeric\" placeholder=\"Other\" aria-label=\"Other amount\" className=\"h-8 min-w-0 flex-1 border-0 bg-transparent px-2.5 text-[12.5px] outline-none\" style={{ color: p.text }} />\n                    <button type=\"submit\" disabled={!custom} className={cn(\"h-8 cursor-pointer rounded-r-lg border-0 bg-transparent px-2.5 text-[12px] font-medium disabled:opacity-30\", focus)} style={{ color: p.text, ...ring }}>\n                      Add\n                    </button>\n                  </form>\n                </div>\n              </div>\n              <div>\n                <div className=\"flex items-center justify-between gap-3\">\n                  <span id={`${uid}-auto`} className=\"text-[12.5px] font-medium\">\n                    Auto-save on the 1st\n                  </span>\n                  <button type=\"button\" role=\"switch\" aria-checked={g.autoSave} aria-labelledby={`${uid}-auto`} onClick={() => update({ autoSave: !g.autoSave })} className={cn(\"relative h-6 w-11 shrink-0 cursor-pointer rounded-full border-0 transition-colors\", focus)} style={{ background: g.autoSave ? p.good : p.track, ...ring }}>\n                    <motion.span className=\"absolute top-0.5 h-5 w-5 rounded-full bg-white shadow\" initial={false} animate={{ left: g.autoSave ? 22 : 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 34 }} />\n                  </button>\n                </div>\n                <div className=\"mt-2.5 flex items-center gap-3\" style={{ opacity: g.autoSave ? 1 : 0.4 }}>\n                  <input type=\"range\" min={25} max={1000} step={25} value={g.monthly} disabled={!g.autoSave} onChange={(e) => update({ monthly: Number(e.target.value) })} aria-label=\"Monthly amount\" aria-valuetext={`${money(g.monthly)} a month`} className=\"h-1 min-w-0 flex-1 cursor-pointer disabled:cursor-not-allowed\" style={{ accentColor: g.color }} />\n                  <span className=\"w-[86px] text-right text-[12.5px] tabular-nums\">{money(g.monthly)}/mo</span>\n                </div>\n              </div>\n            </div>\n          </div>\n        </div>\n      </div>\n      <AnimatePresence>\n        {cheer && (\n          <motion.div key={cheer} role=\"status\" initial={reduce ? false : { opacity: 0, y: 10, scale: 0.96 }} animate={{ opacity: 1, y: 0, scale: 1 }} exit={reduce ? undefined : { opacity: 0 }} className=\"pointer-events-none absolute bottom-5 left-1/2 z-10 -translate-x-1/2 rounded-full border px-3.5 py-1.5 text-[12.5px] whitespace-nowrap shadow-xl\" style={{ background: p.card, borderColor: p.border }}>\n            {cheer}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default SavingsGoalTracker;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}