{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "usage-limit-slider-card",
  "title": "Usage Limit Slider Card",
  "description": "A spending limit card for usage-based billing: a slider that shows what's spent (split by service), the month's forecast and the limit handle together, presets and a forecast + 20% shortcut, a live message saying whether and when you'll hit the limit, alert thresholds with amounts, what happens at the limit, and save.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/usage-limit-slider-card/usage-limit-slider-card.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 UsageLimitValue {\n  limit: number;\n  alerts: number[];\n  atLimit: \"pause\" | \"notify\";\n}\n\nexport interface UsageLimitSliderCardProps {\n  spent?: number;\n  forecast?: number;\n  max?: number;\n  day?: number;\n  daysInMonth?: number;\n  breakdown?: { label: string; amount: number; color: string }[];\n  defaultValue?: UsageLimitValue;\n  onSave?: (value: UsageLimitValue) => Promise<void> | void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", border: \"rgba(255,255,255,0.09)\", track: \"rgba(255,255,255,0.07)\", well: \"rgba(255,255,255,0.035)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#60A5FA\", green: \"#4ADE80\", amber: \"#FBBF24\", red: \"#F87171\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", track: \"rgba(10,10,10,0.07)\", well: \"rgba(10,10,10,0.03)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#2563EB\", green: \"#15803D\", amber: \"#B45309\", red: \"#DC2626\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst BREAKDOWN = [\n  { label: \"Compute\", amount: 388, color: \"#60A5FA\" },\n  { label: \"Storage\", amount: 142, color: \"#A78BFA\" },\n  { label: \"Bandwidth\", amount: 74, color: \"#34D399\" },\n  { label: \"AI credits\", amount: 38, color: \"#FBBF24\" },\n];\nconst PRESETS = [500, 1000, 1500, 2000];\nconst money = (n: number) => `$${Math.round(n).toLocaleString(\"en-US\")}`;\n\nexport function UsageLimitSliderCard({ spent = 642, forecast = 1180, max = 2500, day = 12, daysInMonth = 30, breakdown = BREAKDOWN, defaultValue = { limit: 1000, alerts: [50, 90], atLimit: \"notify\" }, onSave, theme = \"dark\", className }: UsageLimitSliderCardProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [saved, setSaved] = React.useState(defaultValue);\n  const [v, setV] = React.useState(defaultValue);\n  const [dragging, setDragging] = React.useState(false);\n  const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"saved\">(\"idle\");\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  const mv = useMotionValue(defaultValue.limit);\n  const shown = useTransform(mv, (x) => money(x));\n  React.useEffect(() => {\n    const c = animate(mv, v.limit, { duration: dragging || reduce ? 0 : 0.35, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [v.limit, mv, dragging, reduce]);\n  React.useEffect(() => {\n    if (status !== \"saved\") return;\n    const t = setTimeout(() => setStatus(\"idle\"), 1800);\n    return () => clearTimeout(t);\n  }, [status]);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const dirty = JSON.stringify(v) !== JSON.stringify(saved);\n  const pct = (x: number) => `${Math.min(100, (x / max) * 100)}%`;\n  const perDay = spent / day;\n  const hitDay = v.limit > spent ? Math.ceil(v.limit / perDay) : day;\n  const hits = v.limit < forecast;\n  const usedOfLimit = v.limit ? spent / v.limit : 1;\n  const tone = usedOfLimit >= 0.9 || v.limit <= spent ? p.red : hits ? p.amber : p.green;\n  const save = () => {\n    if (!dirty || status === \"saving\") return;\n    setStatus(\"saving\");\n    const snap = v;\n    const done = () => {\n      setSaved(snap);\n      setStatus(\"saved\");\n    };\n    const r = onSave?.(snap);\n    if (r instanceof Promise) r.then(done, () => setStatus(\"idle\"));\n    else timer.current = setTimeout(done, reduce ? 0 : 700);\n  };\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\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-2xl px-4 py-10 @[640px]:px-6\">\n        <div className=\"rounded-2xl border p-5 @[560px]:p-6\" style={{ background: p.card, borderColor: p.border }}>\n          <div className=\"flex flex-wrap items-start justify-between gap-3\">\n            <div>\n              <h2 id={`${uid}-t`} className=\"m-0 text-[17px] font-semibold\">\n                Monthly spending limit\n              </h2>\n              <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }}>\n                Day {day} of {daysInMonth} · {money(spent)} spent so far · on track for {money(forecast)}\n              </p>\n            </div>\n            <div className=\"flex items-baseline gap-1.5 @[480px]:block @[480px]:text-right\">\n              <motion.p className=\"m-0 text-[28px] font-semibold tabular-nums tracking-[-0.02em]\" aria-hidden=\"true\">\n                {shown}\n              </motion.p>\n              <p className=\"m-0 text-[12px]\" style={{ color: p.faint }}>\n                limit\n              </p>\n            </div>\n          </div>\n\n          {/* Slider */}\n          <div className=\"relative mt-8 pt-6 pb-8\">\n            <div className=\"relative h-3 rounded-full\" style={{ background: p.track }}>\n              <div className=\"absolute inset-y-0 left-0 flex overflow-hidden rounded-full\" style={{ width: pct(spent) }}>\n                {breakdown.map((b) => (\n                  <span key={b.label} className=\"h-full\" style={{ width: `${(b.amount / spent) * 100}%`, background: b.color }} />\n                ))}\n              </div>\n              <motion.div className=\"absolute inset-y-0 rounded-r-full\" style={{ left: pct(spent), background: `repeating-linear-gradient(90deg, ${p.faint} 0 4px, transparent 4px 8px)`, opacity: 0.6 }} initial={false} animate={{ width: `calc(${pct(forecast)} - ${pct(spent)})` }} aria-hidden=\"true\" />\n              <motion.div className=\"absolute inset-y-0 left-0 rounded-full\" style={{ boxShadow: `inset 0 0 0 1.5px ${tone}` }} initial={false} animate={{ width: pct(v.limit) }} transition={{ duration: dragging || reduce ? 0 : 0.3 }} aria-hidden=\"true\" />\n            </div>\n            {/* markers */}\n            <span className=\"absolute top-0 -translate-x-1/2 text-[11px] whitespace-nowrap tabular-nums\" style={{ left: pct(spent), color: p.muted }} aria-hidden=\"true\">\n              {money(spent)} now\n            </span>\n            <span className=\"absolute -translate-x-1/2 text-[11px] whitespace-nowrap tabular-nums\" style={{ left: pct(forecast), top: 44, color: p.faint }} aria-hidden=\"true\">\n              ↑ {money(forecast)} forecast\n            </span>\n            <motion.span className=\"pointer-events-none absolute top-[18px] h-7 w-7 -translate-x-1/2 rounded-full border-[3px] shadow-lg\" style={{ background: p.on, borderColor: tone }} initial={false} animate={{ left: pct(v.limit), scale: dragging ? 1.15 : 1 }} transition={{ left: { duration: dragging || reduce ? 0 : 0.3 }, scale: { duration: 0.15 } }} aria-hidden=\"true\" />\n            <input\n              type=\"range\"\n              min={0}\n              max={max}\n              step={50}\n              value={v.limit}\n              onChange={(e) => setV((s) => ({ ...s, limit: Number(e.target.value) }))}\n              onPointerDown={() => setDragging(true)}\n              onPointerUp={() => setDragging(false)}\n              onBlur={() => setDragging(false)}\n              aria-labelledby={`${uid}-t`}\n              aria-valuetext={`${money(v.limit)} a month${hits ? `, below the ${money(forecast)} forecast` : \"\"}`}\n              className={cn(\"absolute inset-x-0 top-[14px] h-9 w-full cursor-grab appearance-none bg-transparent opacity-0 active:cursor-grabbing\", focus)}\n              style={ring}\n            />\n          </div>\n\n          <div className=\"flex flex-wrap items-center gap-1.5\">\n            {PRESETS.map((x) => (\n              <button key={x} type=\"button\" aria-pressed={v.limit === x} onClick={() => setV((s) => ({ ...s, limit: x }))} className={cn(\"h-7 cursor-pointer rounded-full border px-3 text-[12px] tabular-nums\", focus)} style={{ borderColor: v.limit === x ? p.on : p.border, background: \"transparent\", color: v.limit === x ? p.text : p.muted, ...ring }}>\n                {money(x)}\n              </button>\n            ))}\n            <button type=\"button\" onClick={() => setV((s) => ({ ...s, limit: Math.ceil((forecast * 1.2) / 50) * 50 }))} className={cn(\"h-7 cursor-pointer rounded-full border-0 px-3 text-[12px] font-medium\", focus)} style={{ background: `${p.accent}22`, color: p.accent, ...ring }}>\n              Forecast + 20%\n            </button>\n          </div>\n\n          <AnimatePresence mode=\"wait\" initial={false}>\n            <motion.p key={hits ? (v.limit <= spent ? \"over\" : \"hit\") : \"ok\"} initial={reduce ? false : { opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} className=\"m-0 mt-4 flex items-start gap-2 rounded-xl p-3 text-[13px] leading-[1.5]\" style={{ background: `${tone}14`, color: tone }} role=\"status\">\n              <span aria-hidden=\"true\">{hits ? \"⚠\" : \"✓\"}</span>\n              <span>\n                {v.limit <= spent\n                  ? `You've already spent ${money(spent)}. A ${money(v.limit)} limit would ${v.atLimit === \"pause\" ? \"pause services right away\" : \"trigger an alert right away\"}.`\n                  : hits\n                    ? `At this pace you'll reach ${money(v.limit)} around Nov ${hitDay}, ${daysInMonth - hitDay} days before the month ends.`\n                    : `Room to spare: the forecast is ${money(forecast)}, ${Math.round((1 - forecast / v.limit) * 100)}% under your limit.`}\n              </span>\n            </motion.p>\n          </AnimatePresence>\n\n          <div className=\"mt-6 grid grid-cols-1 gap-5 gap-x-10 border-t pt-5 @[560px]:grid-cols-[auto_minmax(0,1fr)]\" style={{ borderColor: p.border }}>\n            <fieldset className=\"m-0 border-0 p-0\">\n              <legend className=\"p-0 text-[13px] font-medium\">Email me at</legend>\n              <div className=\"mt-2.5 flex flex-wrap gap-1.5\">\n                {[50, 75, 90].map((a) => {\n                  const on = v.alerts.includes(a);\n                  return (\n                    <label key={a} className=\"flex cursor-pointer items-center gap-1.5 rounded-lg border px-2.5 py-1.5 text-[12.5px] tabular-nums has-[:focus-visible]:ring-2\" style={{ borderColor: on ? p.accent : p.border, background: on ? `${p.accent}14` : \"transparent\", ...ring }}>\n                      <input type=\"checkbox\" checked={on} onChange={() => setV((s) => ({ ...s, alerts: on ? s.alerts.filter((x) => x !== a) : [...s.alerts, a].sort((x, y) => x - y) }))} className=\"h-3.5 w-3.5 cursor-pointer\" style={{ accentColor: p.accent }} />\n                      {a}%\n                      <span style={{ color: p.faint }}>{money((v.limit * a) / 100)}</span>\n                    </label>\n                  );\n                })}\n              </div>\n            </fieldset>\n            <fieldset className=\"m-0 border-0 p-0\">\n              <legend className=\"p-0 text-[13px] font-medium\">When the limit is reached</legend>\n              <div className=\"mt-2.5 flex flex-col gap-1.5\">\n                {(\n                  [\n                    [\"notify\", \"Notify me, keep things running\"],\n                    [\"pause\", \"Pause paid services until next month\"],\n                  ] as const\n                ).map(([k, label]) => (\n                  <label key={k} className=\"flex cursor-pointer items-center gap-2 text-[13px] has-[:focus-visible]:underline\" style={{ color: v.atLimit === k ? p.text : p.muted }}>\n                    <input type=\"radio\" name={`${uid}-at`} checked={v.atLimit === k} onChange={() => setV((s) => ({ ...s, atLimit: k }))} className=\"h-4 w-4 cursor-pointer\" style={{ accentColor: k === \"pause\" ? p.red : p.on }} />\n                    {label}\n                  </label>\n                ))}\n              </div>\n            </fieldset>\n          </div>\n\n          <div className=\"mt-5 rounded-xl p-3\" style={{ background: p.well }}>\n            <p className=\"m-0 text-[12px]\" style={{ color: p.faint }}>\n              This month so far\n            </p>\n            <ul className=\"m-0 mt-2 grid list-none grid-cols-2 gap-x-4 gap-y-1.5 p-0 @[480px]:grid-cols-4\">\n              {breakdown.map((b) => (\n                <li key={b.label} className=\"flex items-center gap-2 text-[12.5px]\">\n                  <span className=\"h-2 w-2 shrink-0 rounded-sm\" style={{ background: b.color }} />\n                  <span className=\"truncate\" style={{ color: p.muted }}>\n                    {b.label}\n                  </span>\n                  <span className=\"ml-auto tabular-nums\">{money(b.amount)}</span>\n                </li>\n              ))}\n            </ul>\n          </div>\n\n          <div className=\"mt-5 flex items-center justify-end gap-2\">\n            <AnimatePresence>\n              {status === \"saved\" && !dirty && (\n                <motion.span key=\"ok\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} className=\"mr-auto text-[12.5px]\" style={{ color: p.green }} role=\"status\">\n                  ✓ Limit saved\n                </motion.span>\n              )}\n            </AnimatePresence>\n            <button type=\"button\" disabled={!dirty} onClick={() => setV(saved)} className={cn(\"h-9 cursor-pointer rounded-lg border bg-transparent px-3.5 text-[13px] disabled:opacity-40\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n              Reset\n            </button>\n            <button type=\"button\" disabled={!dirty || status === \"saving\"} onClick={save} className={cn(\"h-9 min-w-[96px] cursor-pointer rounded-lg border-0 px-3.5 text-[13px] font-medium disabled:opacity-40\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n              {status === \"saving\" ? \"Saving…\" : \"Save limit\"}\n            </button>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default UsageLimitSliderCard;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}