{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mini-cart-drawer",
  "title": "Mini Cart Drawer",
  "description": "A slide-in cart drawer with a store header and product row: adding a product bumps the bag count and opens the drawer, which shows a free-shipping progress bar, line items with steppers (the last one becomes a remove), a 'goes well with' upsell, an animated subtotal and checkout.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/mini-cart-drawer/mini-cart-drawer.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 DrawerProduct {\n  id: string;\n  title: string;\n  variant: string;\n  price: number;\n  image?: string;\n}\n\nexport interface MiniCartDrawerProps {\n  store?: string;\n  products?: DrawerProduct[];\n  initialCart?: { id: string; quantity: number }[];\n  freeShippingAt?: number;\n  upsell?: DrawerProduct;\n  currency?: string;\n  onCheckout?: (lines: { product: DrawerProduct; quantity: number }[]) => 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)\", panel: \"#121212\", well: \"rgba(255,255,255,0.05)\", photo: \"#F1F1F1\", scrim: \"rgba(0,0,0,0.6)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", track: \"rgba(255,255,255,0.1)\", 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)\", panel: \"#FFFFFF\", well: \"rgba(0,0,0,0.04)\", photo: \"#F1F1F1\", scrim: \"rgba(10,10,10,0.4)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", track: \"rgba(0,0,0,0.08)\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst PRODUCTS: DrawerProduct[] = [\n  { id: \"earbuds\", title: \"Wireless Earbuds\", variant: \"Black\", price: 129, image: \"/demo/wireless-earbuds.webp\" },\n  { id: \"watch\", title: \"Minimal Watch\", variant: \"Black · 40mm\", price: 79, image: \"/demo/minimal-watch.webp\" },\n  { id: \"bottle\", title: \"Insulated Water Bottle\", variant: \"750 ml\", price: 39, image: \"/demo/insulated-water-bottle.webp\" },\n  { id: \"notebook\", title: \"Premium Notebook\", variant: \"A5 · Dotted\", price: 24, image: \"/demo/notebook.webp\" },\n];\nconst UPSELL: DrawerProduct = { id: \"stand\", title: \"Laptop Stand\", variant: \"Space black\", price: 49, image: \"/demo/laptop-stand.webp\" };\n\nfunction Money({ value, currency, reduce }: { value: number; currency: string; reduce: boolean }) {\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, (v) => `${currency}${v.toFixed(2)}`);\n  React.useEffect(() => {\n    if (reduce) {\n      mv.set(value);\n      return;\n    }\n    const c = animate(mv, value, { duration: 0.4, 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 MiniCartDrawer({ store = \"Northline\", products = PRODUCTS, initialCart = [{ id: \"notebook\", quantity: 1 }], freeShippingAt = 150, upsell = UPSELL, currency = \"$\", onCheckout, theme = \"dark\", className }: MiniCartDrawerProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [cart, setCart] = React.useState(initialCart);\n  const [open, setOpen] = React.useState(false);\n  const [bump, setBump] = React.useState(0);\n  const [justAdded, setJustAdded] = React.useState<string | null>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const focusOnce = React.useCallback((el: HTMLButtonElement | null) => el?.focus({ preventScroll: true }), []);\n\n  const all = [...products, upsell];\n  const lines = cart.map((c) => ({ product: all.find((x) => x.id === c.id)!, quantity: c.quantity })).filter((l) => l.product);\n  const count = lines.reduce((a, l) => a + l.quantity, 0);\n  const subtotal = lines.reduce((a, l) => a + l.product.price * l.quantity, 0);\n  const left = Math.max(0, freeShippingAt - subtotal);\n  const pct = Math.min(1, subtotal / freeShippingAt);\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n\n  const close = React.useCallback(() => {\n    setOpen(false);\n    setTimeout(() => triggerRef.current?.focus(), 0);\n  }, []);\n  React.useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [open, close]);\n  React.useEffect(() => {\n    if (!justAdded) return;\n    const t = setTimeout(() => setJustAdded(null), 1600);\n    return () => clearTimeout(t);\n  }, [justAdded]);\n\n  const add = (id: string, openDrawer = true) => {\n    setCart((c) => (c.some((x) => x.id === id) ? c.map((x) => (x.id === id ? { ...x, quantity: x.quantity + 1 } : x)) : [...c, { id, quantity: 1 }]));\n    setBump((b) => b + 1);\n    setJustAdded(id);\n    if (openDrawer) setOpen(true);\n  };\n  const setQty = (id: string, q: number) => setCart((c) => (q <= 0 ? c.filter((x) => x.id !== id) : c.map((x) => (x.id === id ? { ...x, quantity: Math.min(9, q) } : x))));\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.panel } 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 relative min-h-[640px] w-full overflow-hidden\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto max-w-6xl px-4 pt-6 pb-12 @[640px]:px-8\">\n        {/* Store header */}\n        <header className=\"flex items-center justify-between border-b pb-4\" style={{ borderColor: p.line }}>\n          <span className=\"text-[16px] font-semibold tracking-[-0.01em]\">{store}</span>\n          <nav className=\"hidden gap-6 text-[13px] @[640px]:flex\" style={{ color: p.body }} aria-label=\"Shop\">\n            <span>New</span>\n            <span>Audio</span>\n            <span>Desk</span>\n            <span>Outdoor</span>\n          </nav>\n          <button ref={triggerRef} type=\"button\" onClick={() => setOpen(true)} aria-haspopup=\"dialog\" aria-label={`Open bag, ${count} ${count === 1 ? \"item\" : \"items\"}`} className={cn(\"relative flex h-10 cursor-pointer items-center gap-2 rounded-full border px-3.5 text-[13px] font-medium\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title, ...ring }}>\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M6 7h12l-1 13H7zM9 7a3 3 0 0 1 6 0\" />\n            </svg>\n            Bag\n            <motion.span key={bump} className=\"grid h-5 min-w-5 place-items-center rounded-full px-1 text-[11px] font-semibold tabular-nums\" style={{ background: p.buttonBg, color: p.buttonText }} initial={reduce || bump === 0 ? false : { scale: 1.8 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 500, damping: 15 }}>\n              {count}\n            </motion.span>\n          </button>\n        </header>\n\n        {/* Products */}\n        <ul className=\"m-0 mt-6 grid list-none grid-cols-2 gap-4 p-0 @[760px]:grid-cols-4\">\n          {products.map((pr) => (\n            <li key={pr.id} className=\"min-w-0\">\n              <div className=\"relative aspect-square overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n                {/* eslint-disable-next-line @next/next/no-img-element */}\n                {pr.image && <img src={pr.image} alt={pr.title} className=\"h-full w-full object-cover\" />}\n              </div>\n              <div className=\"mt-2.5 flex items-center justify-between gap-2\">\n                <span className=\"min-w-0\">\n                  <span className=\"block truncate text-[13.5px] font-medium\">{pr.title}</span>\n                  <span className=\"block text-[13px] tabular-nums\" style={{ color: p.muted }}>\n                    {money(pr.price)}\n                  </span>\n                </span>\n                <button type=\"button\" onClick={() => add(pr.id)} aria-label={`Add ${pr.title} to bag`} className={cn(\"grid h-9 w-9 shrink-0 cursor-pointer place-items-center rounded-full border-0 text-[18px] leading-none\", focus)} style={{ background: justAdded === pr.id ? p.accent : p.buttonBg, color: justAdded === pr.id ? \"#0A0A0A\" : p.buttonText, ...ring }}>\n                  {justAdded === pr.id ? \"✓\" : \"+\"}\n                </button>\n              </div>\n            </li>\n          ))}\n        </ul>\n      </div>\n\n      <AnimatePresence>\n        {open && (\n          <>\n            <motion.div key=\"scrim\" className=\"absolute inset-0 z-20\" style={{ background: p.scrim }} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} onClick={close} aria-hidden=\"true\" />\n            <motion.aside\n              key=\"drawer\"\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-t`}\n              className=\"absolute top-0 right-0 bottom-0 z-30 flex w-full max-w-[400px] flex-col border-l shadow-[0_0_60px_rgba(0,0,0,0.5)]\"\n              style={{ background: p.panel, borderColor: p.line }}\n              initial={reduce ? false : { x: \"100%\" }}\n              animate={{ x: 0 }}\n              exit={reduce ? undefined : { x: \"100%\" }}\n              transition={{ type: \"spring\", stiffness: 380, damping: 38 }}\n            >\n              <div className=\"flex items-center justify-between border-b px-5 py-4\" style={{ borderColor: p.line }}>\n                <h2 id={`${uid}-t`} className=\"m-0 text-[17px] font-semibold\">\n                  Your bag <span style={{ color: p.muted }}>({count})</span>\n                </h2>\n                <button type=\"button\" ref={focusOnce} onClick={close} aria-label=\"Close bag\" className={cn(\"grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0\", focus)} style={{ background: p.well, color: p.title, ...ring }}>\n                  <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"M6 6l12 12M18 6 6 18\" />\n                  </svg>\n                </button>\n              </div>\n\n              <div className=\"px-5 pt-4\">\n                <p className=\"m-0 text-[13px]\" aria-live=\"polite\">\n                  {left > 0 ? (\n                    <>\n                      You&apos;re <span className=\"font-semibold\">{money(left)}</span> away from free shipping\n                    </>\n                  ) : (\n                    <span style={{ color: p.accent }}>🎉 You&apos;ve unlocked free shipping</span>\n                  )}\n                </p>\n                <div className=\"mt-2 h-1.5 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                  <motion.div className=\"h-full rounded-full\" initial={false} animate={{ width: `${pct * 100}%`, backgroundColor: left > 0 ? p.title : p.accent }} transition={{ duration: reduce ? 0 : 0.5, ease: [0.22, 1, 0.36, 1] }} />\n                </div>\n              </div>\n\n              <ul className=\"m-0 mt-2 flex-1 list-none overflow-y-auto px-5 py-0\">\n                <AnimatePresence initial={false}>\n                  {lines.map((l) => (\n                    <motion.li key={l.product.id} initial={reduce ? false : { opacity: 0, height: 0, backgroundColor: `${p.accent}22` }} animate={{ opacity: 1, height: \"auto\", backgroundColor: \"rgba(0,0,0,0)\" }} exit={reduce ? undefined : { opacity: 0, height: 0, x: 40 }} transition={{ duration: 0.3 }} className=\"overflow-hidden\">\n                      <div className=\"flex items-center gap-3 border-b py-3.5\" style={{ borderColor: p.line }}>\n                        <span className=\"h-16 w-16 shrink-0 overflow-hidden rounded-xl\" style={{ background: p.photo }}>\n                          {/* eslint-disable-next-line @next/next/no-img-element */}\n                          {l.product.image && <img src={l.product.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-[14px] font-medium\">{l.product.title}</span>\n                          <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n                            {l.product.variant}\n                          </span>\n                          <span className=\"mt-1.5 flex h-7 w-fit items-center rounded-full border\" style={{ borderColor: p.line }}>\n                            <button type=\"button\" onClick={() => setQty(l.product.id, l.quantity - 1)} aria-label={l.quantity === 1 ? `Remove ${l.product.title}` : `Decrease ${l.product.title}`} className={cn(\"grid h-7 w-7 cursor-pointer place-items-center rounded-l-full border-0 bg-transparent text-[14px]\", focus)} style={{ color: p.title, ...ring }}>\n                              {l.quantity === 1 ? (\n                                <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                                  <path d=\"M5 7h14M9 7V5h6v2M7 7l1 12h8l1-12\" />\n                                </svg>\n                              ) : (\n                                \"−\"\n                              )}\n                            </button>\n                            <span className=\"w-5 text-center text-[12.5px] tabular-nums\">{l.quantity}</span>\n                            <button type=\"button\" onClick={() => setQty(l.product.id, l.quantity + 1)} aria-label={`Increase ${l.product.title}`} className={cn(\"grid h-7 w-7 cursor-pointer place-items-center rounded-r-full border-0 bg-transparent text-[14px]\", focus)} style={{ color: p.title, ...ring }}>\n                              +\n                            </button>\n                          </span>\n                        </span>\n                        <span className=\"text-[14px] font-medium tabular-nums\">{money(l.product.price * l.quantity)}</span>\n                      </div>\n                    </motion.li>\n                  ))}\n                </AnimatePresence>\n                {lines.length === 0 && (\n                  <li className=\"flex flex-col items-center py-12 text-center\">\n                    <span className=\"text-[34px]\" aria-hidden=\"true\">\n                      🛍️\n                    </span>\n                    <p className=\"m-0 mt-2 text-[14px] font-medium\">Your bag is empty</p>\n                    <button type=\"button\" onClick={close} className={cn(\"mt-3 cursor-pointer border-0 bg-transparent text-[13px] underline\", focus)} style={{ color: p.body, ...ring }}>\n                      Continue shopping\n                    </button>\n                  </li>\n                )}\n              </ul>\n\n              {upsell && !cart.some((c) => c.id === upsell.id) && lines.length > 0 && (\n                <div className=\"mx-5 mb-3 flex items-center gap-3 rounded-2xl p-3\" style={{ background: p.well }}>\n                  <span className=\"h-12 w-12 shrink-0 overflow-hidden rounded-lg\" style={{ background: p.photo }}>\n                    {/* eslint-disable-next-line @next/next/no-img-element */}\n                    {upsell.image && <img src={upsell.image} alt=\"\" className=\"h-full w-full object-cover\" />}\n                  </span>\n                  <span className=\"min-w-0 flex-1\">\n                    <span className=\"block text-[11px] tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n                      Goes well with\n                    </span>\n                    <span className=\"block truncate text-[13px] font-medium\">\n                      {upsell.title} · {money(upsell.price)}\n                    </span>\n                  </span>\n                  <button type=\"button\" onClick={() => add(upsell.id, false)} className={cn(\"h-8 shrink-0 cursor-pointer rounded-full border px-3 text-[12px] font-semibold\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title, ...ring }}>\n                    + Add\n                  </button>\n                </div>\n              )}\n\n              <div className=\"border-t px-5 pt-4 pb-5\" style={{ borderColor: p.line }}>\n                <div className=\"flex items-baseline justify-between\">\n                  <span className=\"text-[14px]\" style={{ color: p.body }}>\n                    Subtotal\n                  </span>\n                  <span className=\"text-[20px] font-semibold tabular-nums\">\n                    <Money value={subtotal} currency={currency} reduce={reduce} />\n                  </span>\n                </div>\n                <p className=\"m-0 mt-0.5 text-[12px]\" style={{ color: p.muted }}>\n                  Taxes and shipping calculated at checkout\n                </p>\n                <button type=\"button\" onClick={() => onCheckout?.(lines)} disabled={!lines.length} className={cn(\"mt-4 flex h-12 w-full cursor-pointer items-center justify-center rounded-full border-0 text-[15px] font-semibold disabled:cursor-not-allowed disabled:opacity-40\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                  Checkout · {money(subtotal)}\n                </button>\n                <button type=\"button\" onClick={close} className={cn(\"mt-2 h-10 w-full cursor-pointer rounded-full border-0 bg-transparent text-[13px]\", focus)} style={{ color: p.body, ...ring }}>\n                  Continue shopping\n                </button>\n              </div>\n            </motion.aside>\n          </>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default MiniCartDrawer;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}