{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "free-shipping-progress-bar",
  "title": "Free Shipping Progress Bar",
  "description": "A tiered cart reward bar: free shipping, a free gift and free express milestones on one striped progress track, a message that says exactly how much more to add, milestone icons that pop when reached, an unlocked toast and 'close the gap' add-ons that pick the cheapest item that gets you there.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/free-shipping-progress-bar/free-shipping-progress-bar.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 ShippingTier {\n  at: number;\n  label: string;\n  icon: \"truck\" | \"gift\" | \"bolt\";\n}\n\nexport interface FreeShippingProgressBarProps {\n  subtotal?: number;\n  tiers?: ShippingTier[];\n  /** Small add-ons that close the gap, shown until the last tier is reached. */\n  suggestions?: { id: string; title: string; price: number; image?: string }[];\n  currency?: string;\n  onAdd?: (id: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.62)\", line: \"rgba(255,255,255,0.12)\", card: \"#141414\", photo: \"#F1F1F1\", track: \"rgba(255,255,255,0.1)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", ring: \"rgba(255,255,255,0.5)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.62)\", line: \"rgba(0,0,0,0.1)\", card: \"#F7F7F6\", photo: \"#F1F1F1\", track: \"rgba(0,0,0,0.08)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst TIERS: ShippingTier[] = [\n  { at: 50, label: \"Free shipping\", icon: \"truck\" },\n  { at: 100, label: \"Free gift\", icon: \"gift\" },\n  { at: 150, label: \"Free express\", icon: \"bolt\" },\n];\nconst SUGGESTIONS = [\n  { id: \"notebook\", title: \"Premium Notebook\", price: 24, image: \"/demo/notebook.webp\" },\n  { id: \"bottle\", title: \"Insulated Water Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\" },\n  { id: \"stand\", title: \"Laptop Stand\", price: 49, image: \"/demo/laptop-stand.webp\" },\n];\nconst ICON: Record<ShippingTier[\"icon\"], string> = {\n  truck: \"M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM17 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4z\",\n  gift: \"M4 10h16v10H4zM3 7h18v3H3zM12 7v13M12 7c-2-3-6-3-6 0M12 7c2-3 6-3 6 0\",\n  bolt: \"M13 3 5 14h6l-1 7 8-11h-6z\",\n};\n\nexport function FreeShippingProgressBar({ subtotal: start = 38, tiers = TIERS, suggestions = SUGGESTIONS, currency = \"$\", onAdd, theme = \"dark\", className }: FreeShippingProgressBarProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const [subtotal, setSubtotal] = React.useState(start);\n  const [added, setAdded] = React.useState<string[]>([]);\n  const [celebrate, setCelebrate] = React.useState<string | null>(null);\n  const max = tiers[tiers.length - 1].at;\n  const fill = useMotionValue(Math.min(1, start / max));\n  const width = useTransform(fill, (v) => `${v * 100}%`);\n  const shown = useMotionValue(start);\n  const shownText = useTransform(shown, (v) => `${currency}${v.toFixed(2)}`);\n\n  const reached = tiers.filter((t) => subtotal >= t.at).length;\n  const next = tiers.find((t) => subtotal < t.at);\n  const left = next ? next.at - subtotal : 0;\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n\n  React.useEffect(() => {\n    const a = animate(fill, Math.min(1, subtotal / max), reduce ? { duration: 0 } : { duration: 0.8, ease: [0.22, 1, 0.36, 1] });\n    const b = animate(shown, subtotal, reduce ? { duration: 0 } : { duration: 0.6 });\n    return () => {\n      a.stop();\n      b.stop();\n    };\n  }, [subtotal, max, reduce, fill, shown]);\n  React.useEffect(() => {\n    if (!celebrate) return;\n    const t = setTimeout(() => setCelebrate(null), 2600);\n    return () => clearTimeout(t);\n  }, [celebrate]);\n\n  const add = (s: (typeof suggestions)[number]) => {\n    const after = subtotal + s.price;\n    const nowReached = tiers.filter((t) => after >= t.at).length;\n    if (nowReached > reached) setCelebrate(tiers[nowReached - 1].label);\n    setSubtotal(after);\n    setAdded((a) => [...a, s.id]);\n    onAdd?.(s.id);\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 pool = suggestions.filter((s) => !added.includes(s.id));\n  const best = next ? [...pool.filter((s) => s.price >= left).sort((a, b) => a.price - b.price), ...pool.filter((s) => s.price < left).sort((a, b) => b.price - a.price)] : [];\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto max-w-[620px] px-4 py-10\">\n        <div className=\"relative overflow-hidden rounded-3xl border p-5 @[480px]:p-6\" style={{ background: p.card, borderColor: p.line }}>\n          <div className=\"flex items-start justify-between gap-4\">\n            <div aria-live=\"polite\">\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                <motion.p key={next ? `n-${next.at}-${left}` : \"done\"} initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -8 }} transition={{ duration: 0.25 }} className=\"m-0 text-[17px] leading-snug font-semibold\">\n                  {next ? (\n                    <>\n                      You&apos;re <span style={{ color: p.accent }}>{money(left)}</span> away from {next.label.toLowerCase()}\n                    </>\n                  ) : (\n                    <>🎉 You&apos;ve unlocked everything</>\n                  )}\n                </motion.p>\n              </AnimatePresence>\n              <p className=\"m-0 mt-1 text-[12.5px]\" style={{ color: p.muted }}>\n                {reached ? `${tiers\n                  .slice(0, reached)\n                  .map((t) => t.label)\n                  .join(\" + \")} included` : \"Free shipping starts at \" + money(tiers[0].at)}\n              </p>\n            </div>\n            <span className=\"text-right\">\n              <span className=\"block text-[11.5px]\" style={{ color: p.muted }}>\n                Bag\n              </span>\n              <motion.span className=\"block text-[18px] font-semibold tabular-nums\">{shownText}</motion.span>\n            </span>\n          </div>\n\n          {/* Track with milestones */}\n          <div className=\"relative mt-7 mb-16 h-2.5\">\n            <span className=\"absolute inset-0 rounded-full\" style={{ background: p.track }} />\n            <motion.span className=\"absolute inset-y-0 left-0 overflow-hidden rounded-full\" style={{ width, background: p.accent }}>\n              {!reduce && <motion.span className=\"absolute inset-0\" style={{ background: \"repeating-linear-gradient(-45deg, rgba(255,255,255,0.25) 0 6px, transparent 6px 12px)\" }} animate={{ x: [0, 17] }} transition={{ repeat: Infinity, duration: 0.8, ease: \"linear\" }} />}\n            </motion.span>\n            <span className=\"absolute inset-y-0 right-[18px] left-[18px]\">\n              {tiers.map((t, i) => {\n                const on = subtotal >= t.at;\n                const last = i === tiers.length - 1;\n                return (\n                  <span key={t.at} className=\"absolute top-1/2 -translate-x-1/2 -translate-y-1/2\" style={{ left: `${(t.at / max) * 100}%` }}>\n                    <motion.span className=\"grid h-9 w-9 place-items-center rounded-full border-2\" animate={{ backgroundColor: on ? p.accent : p.card, borderColor: on ? p.accent : p.line, scale: on && !reduce ? [1, 1.25, 1] : 1, color: on ? \"#0A0A0A\" : p.muted }} transition={{ duration: 0.45 }}>\n                      <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d={ICON[t.icon]} />\n                      </svg>\n                    </motion.span>\n                    <span className={cn(\"absolute top-11 text-[11.5px] whitespace-nowrap\", last ? \"right-0 text-right\" : \"left-1/2 -translate-x-1/2 text-center\")} style={{ color: on ? p.title : p.muted }}>\n                      <span className=\"block font-medium\">{t.label}</span>\n                      <span className=\"tabular-nums\">{money(t.at)}</span>\n                    </span>\n                  </span>\n                );\n              })}\n            </span>\n          </div>\n\n          <AnimatePresence initial={false}>\n            {next && best.length > 0 && (\n              <motion.div key=\"sug\" initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden\">\n                <p className=\"m-0 mt-2 text-[12px] font-medium tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n                  Close the gap\n                </p>\n                <ul className=\"m-0 mt-2.5 grid list-none grid-cols-1 gap-2 p-0 @[520px]:grid-cols-2\">\n                  {best.slice(0, 2).map((s) => {\n                    const unlocks = s.price >= left;\n                    return (\n                      <motion.li key={s.id} layout={!reduce} className=\"flex items-center gap-3 rounded-2xl border p-2.5\" style={{ borderColor: unlocks ? `${p.accent}66` : p.line }}>\n                        <span className=\"h-12 w-12 shrink-0 overflow-hidden rounded-xl\" style={{ background: p.photo }}>\n                          {/* eslint-disable-next-line @next/next/no-img-element */}\n                          {s.image && <img src={s.image} alt=\"\" className=\"h-full w-full object-cover\" />}\n                        </span>\n                        <span className=\"min-w-0 flex-1\">\n                          <span className=\"block truncate text-[13px] font-medium\">{s.title}</span>\n                          <span className=\"block text-[11.5px]\" style={{ color: unlocks ? p.accent : p.muted }}>\n                            {money(s.price)}\n                            {unlocks ? ` · unlocks ${next.label.toLowerCase()}` : \"\"}\n                          </span>\n                        </span>\n                        <button type=\"button\" onClick={() => add(s)} aria-label={`Add ${s.title}`} className={cn(\"h-8 shrink-0 cursor-pointer rounded-full border-0 px-3 text-[12px] font-semibold\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                          + Add\n                        </button>\n                      </motion.li>\n                    );\n                  })}\n                </ul>\n              </motion.div>\n            )}\n          </AnimatePresence>\n\n          <AnimatePresence>\n            {celebrate && (\n              <motion.div key={celebrate} role=\"status\" initial={reduce ? false : { opacity: 0, y: 12, scale: 0.95 }} animate={{ opacity: 1, y: 0, scale: 1 }} exit={reduce ? undefined : { opacity: 0, y: -6 }} className=\"absolute bottom-4 left-1/2 z-10 -translate-x-1/2 rounded-full px-4 py-2 text-[13px] font-semibold whitespace-nowrap text-[#0A0A0A] shadow-lg\" style={{ background: p.accent }}>\n                ✓ {celebrate} unlocked\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default FreeShippingProgressBar;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}