{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "payment-button",
  "title": "Payment Button",
  "description": "A pay button that shows every step of a payment: the amount, a spinner while it processes, a drawn tick when it's paid, a shake and a clear message when a card is declined, and an optional press-and-hold mode that fills up before it charges.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/payment-button/payment-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, animate, 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 type PaymentState = \"idle\" | \"processing\" | \"success\" | \"error\";\n\nexport interface PaymentButtonProps {\n  amount?: number;\n  currency?: string;\n  locale?: string;\n  /** Resolve to finish successfully; reject (or resolve false) to show the error state. */\n  onPay?: () => Promise<boolean | void>;\n  /** click: pay on click. hold: press and hold for holdMs to pay (stops accidental charges). */\n  mode?: \"click\" | \"hold\";\n  holdMs?: number;\n  /** Text under the button. Set to \"\" to hide. */\n  note?: string;\n  errorMessage?: string;\n  /** Go back to idle this many ms after success or error (0 = stay). */\n  resetAfter?: number;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#F5F4F1\", text: \"#0A0A0A\", muted: \"rgba(245,244,241,0.5)\", ok: \"#3FBF7F\", err: \"#FF7A6B\", hold: \"rgba(10,10,10,0.14)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { bg: \"#0A0A0A\", text: \"#FFFFFF\", muted: \"rgba(10,10,10,0.5)\", ok: \"#1F9D5C\", err: \"#E5484D\", hold: \"rgba(255,255,255,0.18)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nexport function PaymentButton({\n  amount = 49,\n  currency = \"USD\",\n  locale = \"en-US\",\n  onPay = () => new Promise((r) => setTimeout(() => r(true), 1400)),\n  mode = \"click\",\n  holdMs = 900,\n  note = \"Payments are encrypted and processed securely.\",\n  errorMessage = \"Card declined\",\n  resetAfter = 2400,\n  theme = \"dark\",\n  className,\n}: PaymentButtonProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [state, setState] = React.useState<PaymentState>(\"idle\");\n  const hold = useMotionValue(0);\n  const holdWidth = useTransform(hold, (v) => `${v * 100}%`);\n  const holdAnim = React.useRef<ReturnType<typeof animate> | null>(null);\n  const price = new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(amount);\n\n  React.useEffect(() => {\n    if ((state === \"success\" || state === \"error\") && resetAfter > 0) {\n      const id = window.setTimeout(() => setState(\"idle\"), resetAfter);\n      return () => window.clearTimeout(id);\n    }\n  }, [state, resetAfter]);\n\n  const pay = async () => {\n    if (state === \"processing\") return;\n    setState(\"processing\");\n    try {\n      const ok = await onPay();\n      setState(ok === false ? \"error\" : \"success\");\n    } catch {\n      setState(\"error\");\n    }\n  };\n\n  const startHold = () => {\n    if (mode !== \"hold\" || state !== \"idle\") return;\n    holdAnim.current = animate(hold, 1, {\n      duration: holdMs / 1000,\n      ease: \"linear\",\n      onComplete: () => {\n        hold.set(0);\n        pay();\n      },\n    });\n  };\n  const cancelHold = () => {\n    if (mode !== \"hold\") return;\n    holdAnim.current?.stop();\n    animate(hold, 0, { duration: 0.2 });\n  };\n\n  const bg = state === \"success\" ? p.ok : state === \"error\" ? p.err : p.bg;\n  const fg = state === \"success\" || state === \"error\" ? \"#0A0A0A\" : p.text;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 420, damping: 32 };\n\n  const content: Record<PaymentState, React.ReactNode> = {\n    idle: (\n      <>\n        <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <rect x=\"4\" y=\"11\" width=\"16\" height=\"10\" rx=\"2\" />\n          <path d=\"M8 11V7.5a4 4 0 0 1 8 0V11\" />\n        </svg>\n        {mode === \"hold\" ? `Hold to pay ${price}` : `Pay ${price}`}\n      </>\n    ),\n    processing: (\n      <>\n        <motion.svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" aria-hidden=\"true\" animate={reduce ? undefined : { rotate: 360 }} transition={{ duration: 0.9, repeat: Infinity, ease: \"linear\" }}>\n          <path d=\"M12 3a9 9 0 1 0 9 9\" />\n        </motion.svg>\n        Processing…\n      </>\n    ),\n    success: (\n      <>\n        <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <motion.path d=\"m5 12.5 4.5 4.5L19 7.5\" initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: reduce ? 0 : 0.35, delay: 0.1 }} />\n        </svg>\n        Paid {price}\n      </>\n    ),\n    error: (\n      <>\n        <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" aria-hidden=\"true\">\n          <path d=\"M12 7v6M12 16.5h.01\" />\n          <circle cx=\"12\" cy=\"12\" r=\"9\" />\n        </svg>\n        {errorMessage} · Try again\n      </>\n    ),\n  };\n\n  return (\n    <div className={cn(\"flex flex-col items-center\", className)} style={{ gap: 10, fontFamily: \"Inter, sans-serif\" }}>\n      <motion.button\n        type=\"button\"\n        layout\n        onClick={mode === \"click\" ? pay : state === \"error\" ? () => setState(\"idle\") : undefined}\n        onPointerDown={startHold}\n        onPointerUp={cancelHold}\n        onPointerLeave={cancelHold}\n        onKeyDown={(e) => {\n          if (mode === \"hold\" && (e.key === \" \" || e.key === \"Enter\") && !e.repeat) startHold();\n        }}\n        onKeyUp={(e) => {\n          if (mode === \"hold\" && (e.key === \" \" || e.key === \"Enter\")) cancelHold();\n        }}\n        disabled={state === \"processing\"}\n        aria-live=\"polite\"\n        aria-busy={state === \"processing\"}\n        className=\"relative flex cursor-pointer items-center justify-center overflow-hidden rounded-full border-none text-[15px] font-semibold whitespace-nowrap outline-none select-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-progress\"\n        style={{ height: 50, padding: \"0 26px\", color: fg, touchAction: \"none\", [\"--tw-ring-color\" as string]: p.focus }}\n        initial={false}\n        animate={{ backgroundColor: bg, x: state === \"error\" && !reduce ? [0, -8, 7, -5, 3, 0] : 0 }}\n        transition={{ layout: spring, backgroundColor: { duration: 0.25 }, x: { duration: 0.45 } }}\n        whileTap={mode === \"click\" && state === \"idle\" && !reduce ? { scale: 0.97 } : undefined}\n      >\n        {mode === \"hold\" && <motion.span aria-hidden=\"true\" className=\"absolute inset-y-0 left-0\" style={{ width: holdWidth, background: p.hold }} />}\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          <motion.span key={state} className=\"relative flex items-center\" style={{ gap: 9 }} initial={reduce ? { opacity: 0 } : { opacity: 0, y: 14, filter: \"blur(4px)\" }} animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }} exit={reduce ? { opacity: 0 } : { opacity: 0, y: -14, filter: \"blur(4px)\" }} transition={{ duration: 0.22 }}>\n            {content[state]}\n          </motion.span>\n        </AnimatePresence>\n      </motion.button>\n      {note && (\n        <span className=\"flex items-center text-[12px]\" style={{ gap: 6, color: p.muted }}>\n          <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M12 3 4.5 6v5.5c0 4.6 3.2 8.2 7.5 9.5 4.3-1.3 7.5-4.9 7.5-9.5V6Z\" />\n          </svg>\n          {note}\n        </span>\n      )}\n    </div>\n  );\n}\n\nexport default PaymentButton;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}