{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mini-cart-dropdown",
  "title": "Mini Cart Dropdown",
  "description": "A store header with a cart icon that opens a dropdown cart: badge that bumps on add, free-shipping progress, line items with quantity steppers and remove with undo, subtotal, view cart and checkout; adding from the picks below opens it, highlights the new line and closes it again after a few seconds.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/mini-cart-dropdown/mini-cart-dropdown.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } 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 MiniCartProduct {\n  id: string;\n  name: string;\n  price: number;\n  image: string;\n  /** Variant line, e.g. \"Black · M\". */\n  variant?: string;\n}\nexport interface MiniCartItem extends MiniCartProduct {\n  qty: number;\n}\n\nexport interface MiniCartDropdownProps {\n  /** Store name shown in the demo header. */\n  brand?: string;\n  items?: MiniCartItem[];\n  /** Products in the strip under the header; adding one opens the cart. */\n  suggestions?: MiniCartProduct[];\n  /** Subtotal that unlocks free shipping; 0 hides the bar. */\n  freeShippingAt?: number;\n  currency?: string;\n  /** How long the cart stays open after an add, in ms (0 = until closed). */\n  autoCloseMs?: number;\n  onChange?: (items: MiniCartItem[]) => void;\n  onViewCart?: () => void;\n  onCheckout?: (items: MiniCartItem[]) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    bar: \"#0F0F0F\",\n    panel: \"#161616\",\n    title: \"#FFFFFF\",\n    muted: \"rgba(255,255,255,0.45)\",\n    body: \"rgba(255,255,255,0.62)\",\n    line: \"rgba(255,255,255,0.12)\",\n    tile: \"#F1F1F1\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    warn: \"#F2B15A\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.08)\",\n    ring: \"rgba(255,255,255,0.55)\",\n    flash: \"rgba(124,222,106,0.12)\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    bar: \"#FAFAFA\",\n    panel: \"#FFFFFF\",\n    title: \"#111111\",\n    muted: \"rgba(0,0,0,0.45)\",\n    body: \"rgba(0,0,0,0.62)\",\n    line: \"rgba(0,0,0,0.1)\",\n    tile: \"#F1F1F1\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    warn: \"#B7791F\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    ring: \"rgba(0,0,0,0.45)\",\n    flash: \"rgba(47,158,68,0.1)\",\n  },\n};\n\nconst L = \"/demo/blocks/product-list\";\nconst ITEMS: MiniCartItem[] = [\n  { id: \"watch\", name: \"Minimal Watch\", price: 79, image: \"/demo/minimal-watch.webp\", variant: \"Black · 38 mm\", qty: 1 },\n  { id: \"notebook\", name: \"Dot Notebook\", price: 24, image: \"/demo/notebook.webp\", variant: \"A5 · Sand\", qty: 2 },\n];\nconst SUGGESTIONS: MiniCartProduct[] = [\n  { id: \"earbuds\", name: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\", variant: \"Graphite\" },\n  { id: \"bottle\", name: \"Insulated Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\", variant: \"750 ml · Black\" },\n  { id: \"lamp\", name: \"Desk Lamp\", price: 59, image: `${L}/lamp.webp`, variant: \"Matte black\" },\n  { id: \"stand\", name: \"Laptop Stand\", price: 49, image: \"/demo/laptop-stand.webp\", variant: \"Silver\" },\n];\n\nconst money = (n: number, c: string) => `${c}${n.toFixed(2)}`;\n\nexport function MiniCartDropdown({ brand = \"Northline\", items: initial = ITEMS, suggestions = SUGGESTIONS, freeShippingAt = 150, currency = \"$\", autoCloseMs = 3500, onChange, onViewCart, onCheckout, theme = \"dark\", className }: MiniCartDropdownProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [items, setItems] = React.useState<MiniCartItem[]>(initial);\n  const [open, setOpen] = React.useState(false);\n  const [flash, setFlash] = React.useState<string | null>(null);\n  const [removed, setRemoved] = React.useState<{ item: MiniCartItem; at: number } | null>(null);\n  const [bump, setBump] = React.useState(0);\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const btnRef = React.useRef<HTMLButtonElement>(null);\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const closeTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const hovering = React.useRef(false);\n\n  const count = items.reduce((t, i) => t + i.qty, 0);\n  const subtotal = items.reduce((t, i) => t + i.price * i.qty, 0);\n  const toFree = Math.max(0, freeShippingAt - subtotal);\n\n  const update = (next: MiniCartItem[]) => {\n    setItems(next);\n    onChange?.(next);\n  };\n  const clearTimer = () => {\n    if (closeTimer.current) clearTimeout(closeTimer.current);\n    closeTimer.current = null;\n  };\n  React.useEffect(() => clearTimer, []);\n\n  // Close on Escape or a click outside; Escape hands focus back to the cart button.\n  React.useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n        btnRef.current?.focus();\n      }\n    };\n    const onDown = (e: PointerEvent) => {\n      if (!wrapRef.current?.contains(e.target as Node)) setOpen(false);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    window.addEventListener(\"pointerdown\", onDown);\n    return () => {\n      window.removeEventListener(\"keydown\", onKey);\n      window.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [open]);\n\n  const add = (prod: MiniCartProduct) => {\n    const hit = items.find((i) => i.id === prod.id);\n    update(hit ? items.map((i) => (i.id === prod.id ? { ...i, qty: i.qty + 1 } : i)) : [{ ...prod, qty: 1 }, ...items]);\n    setFlash(prod.id);\n    setBump((b) => b + 1);\n    setOpen(true);\n    clearTimer();\n    if (autoCloseMs > 0)\n      closeTimer.current = setTimeout(function tick() {\n        // Stay open while the pointer is over the cart.\n        if (hovering.current) closeTimer.current = setTimeout(tick, 600);\n        else setOpen(false);\n      }, autoCloseMs);\n    setTimeout(() => setFlash((f) => (f === prod.id ? null : f)), 1600);\n  };\n  const setQty = (id: string, qty: number) => {\n    if (qty <= 0) {\n      const at = items.findIndex((i) => i.id === id);\n      setRemoved({ item: items[at], at });\n      update(items.filter((i) => i.id !== id));\n      return;\n    }\n    update(items.map((i) => (i.id === id ? { ...i, qty: Math.min(9, qty) } : i)));\n  };\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n\n  return (\n    <section\n      aria-label={`${brand} store header with mini cart`}\n      className={cn(\"relative min-h-[600px] w-full overflow-hidden\", className)}\n      style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.bg } as React.CSSProperties}\n    >\n      {/* Header */}\n      <header className=\"relative z-20 border-b\" style={{ background: p.bar, borderColor: p.line }}>\n        <div className=\"mx-auto flex h-16 max-w-5xl items-center justify-between gap-4 px-4 sm:px-8\">\n          <span className=\"text-[17px] font-semibold tracking-[-0.01em]\">{brand}</span>\n          <nav aria-label=\"Shop\" className=\"hidden gap-6 text-[14px] sm:flex\" style={{ color: p.body }}>\n            {[\"New\", \"Audio\", \"Desk\", \"Outdoor\"].map((l) => (\n              <a key={l} href=\"#cart\" className={cn(\"rounded no-underline hover:opacity-100\", focus)} style={{ color: p.body }}>\n                {l}\n              </a>\n            ))}\n          </nav>\n          <div\n            ref={wrapRef}\n            className=\"relative\"\n            onMouseEnter={() => {\n              hovering.current = true;\n            }}\n            onMouseLeave={() => {\n              hovering.current = false;\n            }}\n          >\n            <button\n              ref={btnRef}\n              type=\"button\"\n              aria-expanded={open}\n              aria-controls={`${uid}-panel`}\n              aria-label={`Cart, ${count} item${count === 1 ? \"\" : \"s\"}`}\n              onClick={() => setOpen((o) => !o)}\n              className={cn(\"relative flex h-10 w-10 cursor-pointer items-center justify-center rounded-full border-0\", focus)}\n              style={{ background: open ? p.ghost : \"transparent\", color: p.title }}\n            >\n              <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M6 7h12l-1 13H7L6 7Z\" />\n                <path d=\"M9 7a3 3 0 0 1 6 0\" />\n              </svg>\n              <AnimatePresence initial={false}>\n                {count > 0 && (\n                  <motion.span\n                    key={bump}\n                    initial={reduce ? false : { scale: 0.4 }}\n                    animate={{ scale: 1 }}\n                    transition={{ type: \"spring\", stiffness: 500, damping: 14 }}\n                    className=\"absolute -top-0.5 -right-0.5 flex h-[18px] min-w-[18px] items-center justify-center rounded-full px-1 text-[10.5px] font-bold tabular-nums\"\n                    style={{ background: p.accent, color: p.accentText }}\n                    aria-hidden=\"true\"\n                  >\n                    {count}\n                  </motion.span>\n                )}\n              </AnimatePresence>\n            </button>\n\n            <AnimatePresence>\n              {open && (\n                <motion.div\n                  ref={panelRef}\n                  id={`${uid}-panel`}\n                  role=\"dialog\"\n                  aria-label=\"Cart\"\n                  initial={reduce ? false : { opacity: 0, y: -8, scale: 0.98 }}\n                  animate={{ opacity: 1, y: 0, scale: 1 }}\n                  exit={reduce ? undefined : { opacity: 0, y: -6, scale: 0.98 }}\n                  transition={{ duration: 0.18 }}\n                  style={{ transformOrigin: \"calc(100% - 20px) 0\", background: p.panel, borderColor: p.line }}\n                  className=\"absolute top-[calc(100%+10px)] -right-2 w-[min(360px,calc(100vw-24px))] rounded-2xl border shadow-[0_24px_60px_rgba(0,0,0,0.4)]\"\n                >\n                  <span aria-hidden=\"true\" className=\"absolute -top-[7px] right-[22px] h-3 w-3 rotate-45 border-t border-l\" style={{ background: p.panel, borderColor: p.line }} />\n                  <div className=\"flex items-center justify-between px-4 pt-4\">\n                    <p className=\"m-0 text-[15px] font-semibold\">\n                      Your cart <span style={{ color: p.muted }}>({count})</span>\n                    </p>\n                    <button type=\"button\" onClick={() => setOpen(false)} aria-label=\"Close cart\" className={cn(\"flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-[18px]\", focus)} style={{ color: p.muted }}>\n                      ×\n                    </button>\n                  </div>\n\n                  {freeShippingAt > 0 && count > 0 && (\n                    <div className=\"px-4 pt-3\" aria-live=\"polite\">\n                      <p className=\"m-0 text-[12.5px]\" style={{ color: toFree ? p.body : p.accent }}>\n                        {toFree ? (\n                          <>\n                            Add{\" \"}\n                            <span className=\"font-semibold\" style={{ color: p.title }}>\n                              {money(toFree, currency)}\n                            </span>{\" \"}\n                            for free shipping\n                          </>\n                        ) : (\n                          \"Free shipping unlocked ✓\"\n                        )}\n                      </p>\n                      <div className=\"mt-2 h-1.5 overflow-hidden rounded-full\" style={{ background: p.ghost }}>\n                        <motion.div className=\"h-full rounded-full\" initial={false} animate={{ width: `${Math.min(100, (subtotal / freeShippingAt) * 100)}%` }} transition={{ duration: reduce ? 0 : 0.5 }} style={{ background: toFree ? p.warn : p.accent }} />\n                      </div>\n                    </div>\n                  )}\n\n                  <AnimatePresence initial={false}>\n                    {removed && (\n                      <motion.p\n                        initial={reduce ? false : { opacity: 0, height: 0 }}\n                        animate={{ opacity: 1, height: \"auto\" }}\n                        exit={reduce ? undefined : { opacity: 0, height: 0 }}\n                        className=\"m-0 mx-4 mt-3 flex items-center justify-between overflow-hidden rounded-lg px-3 py-2 text-[12.5px]\"\n                        style={{ background: p.ghost, color: p.body }}\n                        role=\"status\"\n                      >\n                        {removed.item.name} removed\n                        <button\n                          type=\"button\"\n                          onClick={() => {\n                            const next = [...items];\n                            next.splice(removed.at, 0, removed.item);\n                            update(next);\n                            setRemoved(null);\n                          }}\n                          className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-[12.5px] font-semibold underline underline-offset-2\", focus)}\n                          style={{ color: p.title }}\n                        >\n                          Undo\n                        </button>\n                      </motion.p>\n                    )}\n                  </AnimatePresence>\n\n                  {count === 0 ? (\n                    <div className=\"px-4 py-10 text-center\">\n                      <p className=\"m-0 text-[14px] font-medium\">Your cart is empty</p>\n                      <p className=\"m-0 mt-1 text-[12.5px]\" style={{ color: p.muted }}>\n                        Add something from the picks below.\n                      </p>\n                    </div>\n                  ) : (\n                    <ul className=\"m-0 mt-2 max-h-[264px] list-none overflow-y-auto overscroll-contain px-2 py-1\">\n                      <AnimatePresence initial={false}>\n                        {items.map((i) => (\n                          <motion.li\n                            key={i.id}\n                            layout={!reduce}\n                            initial={reduce ? false : { opacity: 0, height: 0 }}\n                            animate={{ opacity: 1, height: \"auto\", backgroundColor: flash === i.id ? p.flash : \"rgba(0,0,0,0)\" }}\n                            exit={reduce ? undefined : { opacity: 0, height: 0 }}\n                            transition={{ duration: 0.25 }}\n                            className=\"overflow-hidden rounded-xl\"\n                          >\n                            <div className=\"flex items-center gap-3 p-2\">\n                              <span className=\"h-14 w-14 shrink-0 overflow-hidden rounded-lg\" style={{ background: p.tile }}>\n                                {/* eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic */}\n                                <img src={i.image} alt=\"\" width={112} height={112} className=\"h-full w-full object-contain p-1\" />\n                              </span>\n                              <span className=\"min-w-0 flex-1\">\n                                <span className=\"block truncate text-[13.5px] font-medium\">{i.name}</span>\n                                {i.variant && (\n                                  <span className=\"block truncate text-[12px]\" style={{ color: p.muted }}>\n                                    {i.variant}\n                                  </span>\n                                )}\n                                <span className=\"mt-1 flex items-center gap-1\">\n                                  <button\n                                    type=\"button\"\n                                    onClick={() => setQty(i.id, i.qty - 1)}\n                                    aria-label={i.qty === 1 ? `Remove ${i.name}` : `One less ${i.name}`}\n                                    className={cn(\"flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border-0 text-[13px]\", focus)}\n                                    style={{ background: p.ghost, color: p.title }}\n                                  >\n                                    {i.qty === 1 ? (\n                                      <svg width=\"11\" height=\"11\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                                        <path d=\"M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13\" />\n                                      </svg>\n                                    ) : (\n                                      \"−\"\n                                    )}\n                                  </button>\n                                  <span className=\"w-5 text-center text-[12.5px] tabular-nums\" aria-label={`Quantity ${i.qty}`}>\n                                    {i.qty}\n                                  </span>\n                                  <button\n                                    type=\"button\"\n                                    onClick={() => setQty(i.id, i.qty + 1)}\n                                    disabled={i.qty >= 9}\n                                    aria-label={`One more ${i.name}`}\n                                    className={cn(\"flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border-0 text-[13px] disabled:opacity-30\", focus)}\n                                    style={{ background: p.ghost, color: p.title }}\n                                  >\n                                    +\n                                  </button>\n                                </span>\n                              </span>\n                              <span className=\"self-start pt-0.5 text-[13.5px] font-semibold tabular-nums\">{money(i.price * i.qty, currency)}</span>\n                            </div>\n                          </motion.li>\n                        ))}\n                      </AnimatePresence>\n                    </ul>\n                  )}\n\n                  <div className=\"mt-1 border-t px-4 pt-3 pb-4\" style={{ borderColor: p.line }}>\n                    <p className=\"m-0 flex justify-between text-[14px]\">\n                      <span style={{ color: p.body }}>Subtotal</span>\n                      <span className=\"font-semibold tabular-nums\">{money(subtotal, currency)}</span>\n                    </p>\n                    <p className=\"m-0 mt-0.5 text-[11.5px]\" style={{ color: p.muted }}>\n                      Taxes and shipping at checkout\n                    </p>\n                    <div className=\"mt-3 grid grid-cols-2 gap-2\">\n                      <button type=\"button\" onClick={() => onViewCart?.()} className={cn(\"h-10 cursor-pointer rounded-full border text-[13px] font-semibold\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title }}>\n                        View cart\n                      </button>\n                      <button\n                        type=\"button\"\n                        disabled={!count}\n                        onClick={() => onCheckout?.(items)}\n                        className={cn(\"h-10 cursor-pointer rounded-full border-0 text-[13px] font-semibold disabled:cursor-not-allowed disabled:opacity-40\", focus)}\n                        style={{ background: p.buttonBg, color: p.buttonText }}\n                      >\n                        Checkout\n                      </button>\n                    </div>\n                  </div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        </div>\n      </header>\n\n      {/* Picks */}\n      <div id=\"cart\" className=\"mx-auto max-w-5xl px-4 pt-8 pb-10 sm:px-8 sm:pt-10\">\n        <p className=\"m-0 text-[13px] font-medium tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n          Picked for you\n        </p>\n        <ul className=\"m-0 mt-4 grid list-none grid-cols-1 gap-3 p-0 sm:grid-cols-2 lg:w-[calc(100%-400px)]\">\n          {suggestions.map((s) => (\n            <li key={s.id} className=\"flex items-center gap-3 rounded-2xl border p-2.5\" style={{ borderColor: p.line }}>\n              <span className=\"h-14 w-14 shrink-0 overflow-hidden rounded-xl\" style={{ background: p.tile }}>\n                {/* eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic */}\n                <img src={s.image} alt=\"\" width={112} height={112} className=\"h-full w-full object-contain p-1\" />\n              </span>\n              <span className=\"min-w-0 flex-1\">\n                <span className=\"block truncate text-[13.5px] font-medium\">{s.name}</span>\n                <span className=\"block text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                  {money(s.price, currency)}\n                </span>\n              </span>\n              <button\n                type=\"button\"\n                onClick={() => add(s)}\n                aria-label={`Add ${s.name} to cart`}\n                className={cn(\"flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 text-[18px] leading-none\", focus)}\n                style={{ background: p.buttonBg, color: p.buttonText }}\n              >\n                +\n              </button>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}