{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "express-checkout-buttons",
  "title": "Express Checkout Buttons",
  "description": "An express checkout card with wallet, saved card, pay-in-4 and bank buttons above a continue-with-email field; each opens a payment sheet with the method's details (card, instalment plan or bank choice), shipping address and speed, the total and a confirm button that shows progress and success.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/express-checkout-buttons/express-checkout-buttons.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 type ExpressMethod = \"wallet\" | \"card\" | \"later\" | \"bank\";\nexport interface ExpressLine {\n  name: string;\n  price: number;\n  qty: number;\n  image: string;\n}\n\nexport interface ExpressCheckoutButtonsProps {\n  title?: string;\n  /** Which express options to offer, in order. */\n  methods?: ExpressMethod[];\n  lines?: ExpressLine[];\n  /** Shipping options shown in the payment sheet. */\n  shipping?: { id: string; label: string; eta: string; price: number }[];\n  currency?: string;\n  /** Called after the shopper confirms; resolve to finish, reject to show an error. */\n  onPay?: (method: ExpressMethod, total: number) => Promise<void> | void;\n  onEmail?: (email: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    card: \"#141414\",\n    sheet: \"#1A1A1A\",\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    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    ring: \"rgba(255,255,255,0.55)\",\n    scrim: \"rgba(0,0,0,0.55)\",\n    field: \"#0F0F0F\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    card: \"#F7F7F7\",\n    sheet: \"#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    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    ring: \"rgba(0,0,0,0.45)\",\n    scrim: \"rgba(0,0,0,0.3)\",\n    field: \"#FFFFFF\",\n  },\n};\n\nconst LINES: ExpressLine[] = [\n  { name: \"Wireless Earbuds\", price: 129, qty: 1, image: \"/demo/wireless-earbuds.webp\" },\n  { name: \"Insulated Bottle\", price: 39, qty: 2, image: \"/demo/insulated-water-bottle.webp\" },\n];\nconst SHIPPING = [\n  { id: \"std\", label: \"Standard\", eta: \"Arrives Thu, Nov 12\", price: 0 },\n  { id: \"exp\", label: \"Express\", eta: \"Arrives tomorrow\", price: 12 },\n];\nconst BANKS = [\"North Bank\", \"Harbor Credit Union\", \"Pine Savings\", \"Meridian\"];\n\n// Neutral icons; swap in real wallet marks where your payment provider's brand rules allow it.\nfunction MethodIcon({ m }: { m: ExpressMethod }) {\n  const common = { width: 18, height: 18, viewBox: \"0 0 24 24\", fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.8, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, \"aria-hidden\": true };\n  if (m === \"wallet\")\n    return (\n      <svg {...common}>\n        <rect x=\"6\" y=\"2.5\" width=\"12\" height=\"19\" rx=\"3\" />\n        <path d=\"M10.5 18.5h3\" />\n      </svg>\n    );\n  if (m === \"card\")\n    return (\n      <svg {...common}>\n        <rect x=\"2.5\" y=\"5\" width=\"19\" height=\"14\" rx=\"2.5\" />\n        <path d=\"M2.5 10h19M6.5 15h3\" />\n      </svg>\n    );\n  if (m === \"later\")\n    return (\n      <svg {...common}>\n        <circle cx=\"12\" cy=\"12\" r=\"9\" />\n        <path d=\"M12 7v5l3 2\" />\n      </svg>\n    );\n  return (\n    <svg {...common}>\n      <path d=\"M3 10 12 4l9 6M5 10v8M9.5 10v8M14.5 10v8M19 10v8M3 20h18\" />\n    </svg>\n  );\n}\nconst LABELS: Record<ExpressMethod, string> = { wallet: \"Wallet\", card: \"Saved card\", later: \"Pay in 4\", bank: \"Bank\" };\n\nconst money = (n: number, c: string) => `${c}${n.toFixed(2)}`;\n\nexport function ExpressCheckoutButtons({ title = \"Express checkout\", methods = [\"wallet\", \"card\", \"later\", \"bank\"], lines = LINES, shipping = SHIPPING, currency = \"$\", onPay, onEmail, theme = \"dark\", className }: ExpressCheckoutButtonsProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [method, setMethod] = React.useState<ExpressMethod | null>(null);\n  const [ship, setShip] = React.useState(shipping[0]?.id ?? \"\");\n  const [bank, setBank] = React.useState<string | null>(null);\n  const [state, setState] = React.useState<\"review\" | \"busy\" | \"done\" | \"error\">(\"review\");\n  const [email, setEmail] = React.useState(\"\");\n  const [emailSent, setEmailSent] = React.useState(false);\n  const sheetRef = React.useRef<HTMLDivElement>(null);\n  const openerRef = React.useRef<HTMLButtonElement | null>(null);\n\n  const subtotal = lines.reduce((t, l) => t + l.price * l.qty, 0);\n  const shipCost = shipping.find((s) => s.id === ship)?.price ?? 0;\n  const total = subtotal + shipCost;\n  const quarter = Math.round((total / 4) * 100) / 100;\n\n  const close = React.useCallback(() => {\n    setMethod(null);\n    setTimeout(() => openerRef.current?.focus(), 0);\n  }, []);\n  React.useEffect(() => {\n    if (!method) return;\n    const t = setTimeout(() => sheetRef.current?.querySelector<HTMLElement>(\"[data-autofocus]\")?.focus(), 40);\n    const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && state !== \"busy\" && close();\n    window.addEventListener(\"keydown\", onKey);\n    return () => {\n      clearTimeout(t);\n      window.removeEventListener(\"keydown\", onKey);\n    };\n  }, [method, state, close]);\n\n  const start = (m: ExpressMethod, el: HTMLButtonElement) => {\n    openerRef.current = el;\n    setMethod(m);\n    setState(\"review\");\n    setBank(null);\n  };\n  const confirm = async () => {\n    if (!method) return;\n    setState(\"busy\");\n    try {\n      await Promise.all([onPay?.(method, total), new Promise((r) => setTimeout(r, 1300))]);\n      setState(\"done\");\n    } catch {\n      setState(\"error\");\n    }\n  };\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const ready = method !== \"bank\" || !!bank;\n\n  return (\n    <section\n      aria-labelledby={`${uid}-h`}\n      className={cn(\"relative flex min-h-[640px] w-full items-center justify-center overflow-hidden px-4 py-12 sm:px-8\", className)}\n      style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.card } as React.CSSProperties}\n    >\n      <div className=\"w-full max-w-md rounded-3xl border p-6 sm:p-7\" style={{ background: p.card, borderColor: p.line }} inert={method ? true : undefined}>\n        <div className=\"flex items-baseline justify-between gap-3\">\n          <h2 id={`${uid}-h`} className=\"m-0 text-[20px] font-semibold tracking-[-0.01em]\">\n            {title}\n          </h2>\n          <span className=\"text-[14px] tabular-nums\" style={{ color: p.body }}>\n            {money(subtotal, currency)}\n          </span>\n        </div>\n        <ul className=\"m-0 mt-4 flex list-none -space-x-2 p-0\" aria-label={`${lines.reduce((t, l) => t + l.qty, 0)} items`}>\n          {lines.map((l) => (\n            <li key={l.name} className=\"relative h-12 w-12 overflow-hidden rounded-xl border-2\" style={{ background: p.tile, borderColor: p.card }} title={l.name}>\n              {/* eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic */}\n              <img src={l.image} alt={l.name} width={96} height={96} className=\"h-full w-full object-contain p-1\" />\n              {l.qty > 1 && (\n                <span className=\"absolute right-0.5 bottom-0.5 rounded-full px-1 text-[9.5px] font-bold\" style={{ background: p.buttonBg, color: p.buttonText }}>\n                  ×{l.qty}\n                </span>\n              )}\n            </li>\n          ))}\n        </ul>\n\n        <div className={cn(\"mt-5 grid gap-2\", methods.length >= 4 ? \"grid-cols-2\" : methods.length === 3 ? \"grid-cols-3\" : \"grid-cols-1\")}>\n          {methods.map((m, i) => (\n            <button\n              key={m}\n              type=\"button\"\n              onClick={(e) => start(m, e.currentTarget)}\n              aria-label={`Pay ${money(total, currency)} with ${LABELS[m]}`}\n              className={cn(\"flex h-12 cursor-pointer items-center justify-center gap-2 rounded-xl border text-[14.5px] font-semibold transition-transform active:scale-[0.98]\", focus)}\n              style={i === 0 ? { background: p.buttonBg, color: p.buttonText, borderColor: p.buttonBg } : { background: \"transparent\", color: p.title, borderColor: p.line }}\n            >\n              <MethodIcon m={m} />\n              {LABELS[m]}\n            </button>\n          ))}\n        </div>\n        <p className=\"m-0 mt-2.5 text-center text-[12px]\" style={{ color: p.muted }}>\n          Address and payment come from your account. Review before you pay.\n        </p>\n\n        <div className=\"my-6 flex items-center gap-3 text-[12px] tracking-[0.08em] uppercase\" style={{ color: p.muted }}>\n          <span className=\"h-px flex-1\" style={{ background: p.line }} />\n          or\n          <span className=\"h-px flex-1\" style={{ background: p.line }} />\n        </div>\n\n        {emailSent ? (\n          <p className=\"m-0 rounded-xl px-4 py-3 text-[13.5px]\" style={{ background: p.ghost, color: p.body }} role=\"status\">\n            Continuing as <span style={{ color: p.title }}>{email.trim()}</span>…\n          </p>\n        ) : (\n          <form\n            onSubmit={(e) => {\n              e.preventDefault();\n              if (!/^[^\\s@]+@[^\\s@]+\\.[a-z]{2,}$/i.test(email.trim())) return;\n              setEmailSent(true);\n              onEmail?.(email.trim());\n            }}\n            className=\"flex gap-2\"\n          >\n            <label htmlFor={`${uid}-em`} className=\"sr-only\">\n              Email\n            </label>\n            <input\n              id={`${uid}-em`}\n              type=\"email\"\n              autoComplete=\"email\"\n              value={email}\n              onChange={(e) => setEmail(e.target.value)}\n              placeholder=\"Continue with email\"\n              className={cn(\"h-12 min-w-0 flex-1 rounded-xl border px-4 text-[16px] sm:text-[14px]\", focus)}\n              style={{ background: p.field, borderColor: p.line, color: p.title }}\n            />\n            <button type=\"submit\" aria-label=\"Continue with email\" className={cn(\"h-12 w-12 shrink-0 cursor-pointer rounded-xl border-0 text-[18px]\", focus)} style={{ background: p.ghost, color: p.title }}>\n              →\n            </button>\n          </form>\n        )}\n      </div>\n\n      {/* Payment sheet */}\n      <AnimatePresence>\n        {method && (\n          <motion.div\n            className=\"absolute inset-0 z-20 flex items-end justify-center sm:items-center\"\n            style={{ background: p.scrim }}\n            initial={reduce ? false : { opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={reduce ? undefined : { opacity: 0 }}\n            onMouseDown={(e) => e.target === e.currentTarget && state !== \"busy\" && close()}\n          >\n            <motion.div\n              ref={sheetRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-st`}\n              initial={reduce ? false : { y: 60, opacity: 0 }}\n              animate={{ y: 0, opacity: 1 }}\n              exit={reduce ? undefined : { y: 60, opacity: 0 }}\n              transition={{ type: \"spring\", stiffness: 380, damping: 36 }}\n              className=\"w-full max-w-md rounded-t-3xl border p-5 sm:rounded-3xl\"\n              style={{ background: p.sheet, borderColor: p.line }}\n            >\n              <div className=\"flex items-center justify-between gap-3\">\n                <h3 id={`${uid}-st`} className=\"m-0 flex items-center gap-2 text-[16px] font-semibold\">\n                  <MethodIcon m={method} />\n                  {LABELS[method]}\n                </h3>\n                <button\n                  type=\"button\"\n                  data-autofocus\n                  onClick={close}\n                  disabled={state === \"busy\"}\n                  aria-label=\"Cancel\"\n                  className={cn(\"h-8 cursor-pointer rounded-full border-0 px-3 text-[13px] disabled:opacity-40\", focus)}\n                  style={{ background: p.ghost, color: p.title }}\n                >\n                  {state === \"done\" ? \"Close\" : \"Cancel\"}\n                </button>\n              </div>\n\n              <AnimatePresence mode=\"wait\" initial={false}>\n                {state === \"done\" ? (\n                  <motion.div key=\"done\" initial={reduce ? false : { opacity: 0, scale: 0.96 }} animate={{ opacity: 1, scale: 1 }} className=\"py-8 text-center\" role=\"status\">\n                    <motion.span\n                      initial={reduce ? false : { scale: 0 }}\n                      animate={{ scale: 1 }}\n                      transition={{ type: \"spring\", stiffness: 320, damping: 16 }}\n                      className=\"mx-auto flex h-14 w-14 items-center justify-center rounded-full text-[24px]\"\n                      style={{ background: p.accent, color: p.accentText }}\n                    >\n                      ✓\n                    </motion.span>\n                    <p className=\"m-0 mt-4 text-[18px] font-semibold\">Paid {money(method === \"later\" ? quarter : total, currency)}</p>\n                    <p className=\"m-0 mt-1 text-[13.5px]\" style={{ color: p.body }}>\n                      {method === \"later\" ? `Then 3 more payments of ${money(quarter, currency)}, every two weeks.` : `Order NL-20418 is confirmed. ${shipping.find((s) => s.id === ship)?.eta}.`}\n                    </p>\n                  </motion.div>\n                ) : (\n                  <motion.div key=\"review\" initial={false} exit={reduce ? undefined : { opacity: 0 }} className=\"mt-4 flex flex-col gap-3\">\n                    {/* Method-specific part */}\n                    {method === \"wallet\" && <Row label=\"Card\" value=\"Visa ···· 4242\" p={p} />}\n                    {method === \"card\" && <Row label=\"Card\" value=\"Mastercard ···· 4444 · exp 04/28\" p={p} />}\n                    {method === \"later\" && (\n                      <div className=\"rounded-2xl p-3\" style={{ background: p.ghost }}>\n                        <p className=\"m-0 text-[12.5px]\" style={{ color: p.body }}>\n                          4 interest-free payments\n                        </p>\n                        <ol className=\"m-0 mt-2 grid list-none grid-cols-4 gap-1.5 p-0\">\n                          {[\"Today\", \"Nov 19\", \"Dec 3\", \"Dec 17\"].map((d, i) => (\n                            <li key={d} className=\"rounded-lg px-1 py-2 text-center\" style={{ background: i === 0 ? p.buttonBg : \"transparent\", color: i === 0 ? p.buttonText : p.title }}>\n                              <span className=\"block text-[13px] font-semibold tabular-nums\">{money(quarter, currency)}</span>\n                              <span className=\"text-[11px] opacity-70\">{d}</span>\n                            </li>\n                          ))}\n                        </ol>\n                      </div>\n                    )}\n                    {method === \"bank\" && (\n                      <div role=\"radiogroup\" aria-label=\"Your bank\" className=\"grid grid-cols-2 gap-1.5\">\n                        {BANKS.map((b) => (\n                          <button\n                            key={b}\n                            type=\"button\"\n                            role=\"radio\"\n                            aria-checked={bank === b}\n                            onClick={() => setBank(b)}\n                            className={cn(\"h-11 cursor-pointer rounded-xl border px-3 text-left text-[13px]\", focus)}\n                            style={bank === b ? { background: p.buttonBg, color: p.buttonText, borderColor: p.buttonBg } : { background: \"transparent\", color: p.title, borderColor: p.line }}\n                          >\n                            {b}\n                          </button>\n                        ))}\n                      </div>\n                    )}\n                    <Row label=\"Ship to\" value=\"Maya Chen, 418 Alder St, Portland OR\" p={p} />\n                    <div role=\"radiogroup\" aria-label=\"Shipping\" className=\"flex gap-1.5\">\n                      {shipping.map((s) => (\n                        <button\n                          key={s.id}\n                          type=\"button\"\n                          role=\"radio\"\n                          aria-checked={ship === s.id}\n                          onClick={() => setShip(s.id)}\n                          className={cn(\"flex-1 cursor-pointer rounded-xl border p-2.5 text-left\", focus)}\n                          style={{ background: ship === s.id ? p.ghost : \"transparent\", borderColor: ship === s.id ? p.title : p.line, color: p.title }}\n                        >\n                          <span className=\"flex justify-between text-[13px] font-semibold\">\n                            {s.label}\n                            <span className=\"tabular-nums\">{s.price ? money(s.price, currency) : \"Free\"}</span>\n                          </span>\n                          <span className=\"block text-[11.5px]\" style={{ color: p.muted }}>\n                            {s.eta}\n                          </span>\n                        </button>\n                      ))}\n                    </div>\n                    <div className=\"flex items-baseline justify-between border-t pt-3\" style={{ borderColor: p.line }}>\n                      <span className=\"text-[14px]\" style={{ color: p.body }}>\n                        {method === \"later\" ? \"Due today\" : \"Total\"}\n                      </span>\n                      <span className=\"text-[22px] font-semibold tabular-nums\" aria-live=\"polite\">\n                        {money(method === \"later\" ? quarter : total, currency)}\n                      </span>\n                    </div>\n                    {state === \"error\" && (\n                      <p className=\"m-0 text-[12.5px]\" style={{ color: \"#FF8A7A\" }} role=\"alert\">\n                        That didn’t go through. Try again or pick another option.\n                      </p>\n                    )}\n                    <button\n                      type=\"button\"\n                      onClick={confirm}\n                      disabled={state === \"busy\" || !ready}\n                      className={cn(\"flex h-12 cursor-pointer items-center justify-center gap-2 rounded-xl border-0 text-[15px] font-semibold disabled:cursor-not-allowed disabled:opacity-50\", focus)}\n                      style={{ background: p.buttonBg, color: p.buttonText }}\n                    >\n                      {state === \"busy\" ? (\n                        <>\n                          <motion.span\n                            aria-hidden=\"true\"\n                            className=\"h-4 w-4 rounded-full border-2\"\n                            style={{ borderColor: `${p.buttonText}33`, borderTopColor: p.buttonText }}\n                            animate={reduce ? undefined : { rotate: 360 }}\n                            transition={{ duration: 0.8, repeat: Infinity, ease: \"linear\" }}\n                          />\n                          Confirming…\n                        </>\n                      ) : method === \"bank\" ? (\n                        bank ? (\n                          `Continue to ${bank}`\n                        ) : (\n                          \"Choose your bank\"\n                        )\n                      ) : method === \"later\" ? (\n                        \"Agree and pay first instalment\"\n                      ) : (\n                        `Pay ${money(total, currency)}`\n                      )}\n                    </button>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nfunction Row({ label, value, p }: { label: string; value: string; p: (typeof PALETTES)[\"dark\"] }) {\n  return (\n    <div className=\"flex items-center justify-between gap-3 rounded-xl px-3 py-2.5 text-[13px]\" style={{ background: p.ghost }}>\n      <span className=\"shrink-0 whitespace-nowrap\" style={{ color: p.muted }}>\n        {label}\n      </span>\n      <span className=\"min-w-0 truncate text-right\">{value}</span>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}