{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gift-card-designer",
  "title": "Gift Card Designer",
  "description": "A gift card builder with a live 3D preview that tilts with the pointer and flips to show the message side: six card designs, preset or custom amounts with limits, to, from and recipient email, a 140-character message in three letterings, send now or on a date, and an add-to-cart button that confirms.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/gift-card-designer/gift-card-designer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, 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 GiftDesign {\n  id: string;\n  name: string;\n  /** CSS background for the card face. */\n  background: string;\n  /** Text colour on the face. */\n  ink: string;\n}\nexport interface GiftCardDesign {\n  design: string;\n  amount: number;\n  to: string;\n  email: string;\n  from: string;\n  message: string;\n  font: \"sans\" | \"serif\" | \"hand\";\n  deliver: \"now\" | string;\n}\n\nexport interface GiftCardDesignerProps {\n  brand?: string;\n  designs?: GiftDesign[];\n  amounts?: number[];\n  min?: number;\n  max?: number;\n  currency?: string;\n  onAdd?: (card: GiftCardDesign) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    panel: \"#141414\",\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    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    danger: \"#FF8A7A\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    ring: \"rgba(255,255,255,0.55)\",\n    field: \"#0D0D0D\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    panel: \"#F7F7F7\",\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    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    danger: \"#C0392B\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    ring: \"rgba(0,0,0,0.45)\",\n    field: \"#FFFFFF\",\n  },\n};\n\nconst DESIGNS: GiftDesign[] = [\n  { id: \"aurora\", name: \"Aurora\", background: \"radial-gradient(120% 90% at 0% 0%, #7CDE6A 0%, transparent 55%), radial-gradient(90% 80% at 100% 100%, #5B8CFF 0%, transparent 60%), #0E1420\", ink: \"#FFFFFF\" },\n  { id: \"sunset\", name: \"Sunset\", background: \"linear-gradient(135deg, #FF9A62 0%, #FF5E7E 45%, #7A3CF0 100%)\", ink: \"#FFFFFF\" },\n  { id: \"paper\", name: \"Paper\", background: \"repeating-linear-gradient(45deg, rgba(0,0,0,0.035) 0 2px, transparent 2px 9px), #F1ECE2\", ink: \"#1B1A17\" },\n  { id: \"mono\", name: \"Mono\", background: \"linear-gradient(160deg, #2A2A2A 0%, #0B0B0B 100%)\", ink: \"#FFFFFF\" },\n  { id: \"dots\", name: \"Confetti\", background: \"radial-gradient(#FFD25A 2px, transparent 2.5px) 0 0 / 22px 22px, radial-gradient(#FF7AA8 2px, transparent 2.5px) 11px 11px / 22px 22px, #1C2541\", ink: \"#FFFFFF\" },\n  { id: \"forest\", name: \"Forest\", background: \"linear-gradient(200deg, #2E5E4E 0%, #12332B 70%), #12332B\", ink: \"#F3F1E7\" },\n];\nconst FONTS = {\n  sans: { label: \"Clean\", family: \"ui-sans-serif, system-ui, sans-serif\", style: \"normal\" as const },\n  serif: { label: \"Classic\", family: \"Georgia, 'Times New Roman', serif\", style: \"italic\" as const },\n  hand: { label: \"Handwritten\", family: \"'Segoe Print', 'Bradley Hand', 'Comic Sans MS', cursive\", style: \"normal\" as const },\n};\nconst MAX_MSG = 140;\n\nexport function GiftCardDesigner({ brand = \"Northline\", designs = DESIGNS, amounts = [25, 50, 100, 150], min = 10, max = 500, currency = \"$\", onAdd, theme = \"dark\", className }: GiftCardDesignerProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [design, setDesign] = React.useState(designs[0].id);\n  const [amount, setAmount] = React.useState(amounts[1] ?? amounts[0]);\n  const [custom, setCustom] = React.useState(\"\");\n  const [to, setTo] = React.useState(\"Sam\");\n  const [email, setEmail] = React.useState(\"\");\n  const [from, setFrom] = React.useState(\"Maya\");\n  const [message, setMessage] = React.useState(\"Happy birthday! Treat yourself to something good.\");\n  const [font, setFont] = React.useState<keyof typeof FONTS>(\"serif\");\n  const [when, setWhen] = React.useState<\"now\" | \"later\">(\"now\");\n  const [date, setDate] = React.useState(\"2026-11-20\");\n  const [flipped, setFlipped] = React.useState(false);\n  const [tried, setTried] = React.useState(false);\n  const [added, setAdded] = React.useState(false);\n\n  const d = designs.find((x) => x.id === design) ?? designs[0];\n  const customNum = Number(custom);\n  const value = custom ? customNum : amount;\n  const amountErr = custom && (!Number.isFinite(customNum) || customNum < min || customNum > max) ? `Between ${currency}${min} and ${currency}${max}` : \"\";\n  const emailErr = !/^[^\\s@]+@[^\\s@]+\\.[a-z]{2,}$/i.test(email.trim()) ? \"Where should we send it?\" : \"\";\n\n  // Pointer tilt for the preview card (off for reduced motion).\n  const mx = useMotionValue(0);\n  const my = useMotionValue(0);\n  const rx = useSpring(useTransform(my, [-0.5, 0.5], [8, -8]), { stiffness: 200, damping: 20 });\n  const ry = useSpring(useTransform(mx, [-0.5, 0.5], [-10, 10]), { stiffness: 200, damping: 20 });\n  const onMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (reduce || e.pointerType !== \"mouse\") return;\n    const r = e.currentTarget.getBoundingClientRect();\n    mx.set((e.clientX - r.left) / r.width - 0.5);\n    my.set((e.clientY - r.top) / r.height - 0.5);\n  };\n  const reset = () => {\n    mx.set(0);\n    my.set(0);\n  };\n\n  const add = () => {\n    setTried(true);\n    if (amountErr || emailErr || !to.trim()) return;\n    onAdd?.({ design, amount: value, to: to.trim(), email: email.trim(), from: from.trim(), message: message.trim(), font, deliver: when === \"now\" ? \"now\" : date });\n    setAdded(true);\n    setTimeout(() => setAdded(false), 1800);\n  };\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const field = cn(\"h-11 w-full rounded-xl border px-3.5 text-[16px] sm:text-[14px]\", focus);\n  const fs = (bad: boolean) => ({ background: p.field, borderColor: bad ? p.danger : p.line, color: p.title });\n  const f = FONTS[font];\n\n  return (\n    <section aria-labelledby={`${uid}-h`} className={cn(\"relative w-full px-4 py-12 sm:px-8\", className)} style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.bg } as React.CSSProperties}>\n      <div className=\"mx-auto grid max-w-5xl grid-cols-1 items-start gap-8 md:grid-cols-[minmax(0,1fr)_minmax(0,380px)] lg:grid-cols-[minmax(0,1fr)_minmax(0,420px)]\">\n        {/* Preview */}\n        <div className=\"md:sticky md:top-8\">\n          <h2 id={`${uid}-h`} className=\"m-0 text-[28px] font-semibold tracking-[-0.02em]\">\n            Design a gift card\n          </h2>\n          <p className=\"m-0 mt-1.5 text-[14.5px]\" style={{ color: p.body }}>\n            Delivered by email, never expires, spend it on anything.\n          </p>\n          <div className=\"mt-6 [perspective:1200px]\" onPointerMove={onMove} onPointerLeave={reset}>\n            <motion.div className=\"relative mx-auto aspect-[1.6/1] w-full max-w-[460px] [transform-style:preserve-3d]\" style={{ rotateX: rx, rotateY: ry }}>\n              <motion.div className=\"absolute inset-0 [transform-style:preserve-3d]\" animate={{ rotateY: flipped ? 180 : 0 }} transition={{ duration: reduce ? 0 : 0.6, ease: [0.22, 1, 0.36, 1] }}>\n                {/* Front */}\n                <div\n                  className=\"absolute inset-0 flex flex-col justify-between overflow-hidden rounded-[22px] p-6 shadow-[0_30px_60px_rgba(0,0,0,0.45)] [backface-visibility:hidden]\"\n                  style={{ background: d.background, color: d.ink }}\n                  aria-hidden={flipped || undefined}\n                >\n                  <div className=\"flex items-start justify-between\">\n                    <span className=\"text-[17px] font-semibold tracking-[0.02em]\">{brand}</span>\n                    <span className=\"rounded-full px-2.5 py-1 text-[11px] font-semibold tracking-[0.08em] uppercase\" style={{ background: \"rgba(255,255,255,0.18)\", backdropFilter: \"blur(6px)\" }}>\n                      Gift card\n                    </span>\n                  </div>\n                  <div>\n                    <AnimatePresence mode=\"popLayout\" initial={false}>\n                      <motion.p\n                        key={value}\n                        initial={reduce ? false : { y: 14, opacity: 0 }}\n                        animate={{ y: 0, opacity: 1 }}\n                        exit={reduce ? undefined : { y: -14, opacity: 0 }}\n                        transition={{ duration: 0.2 }}\n                        className=\"m-0 text-[44px] leading-none font-semibold tracking-[-0.03em] tabular-nums sm:text-[52px]\"\n                      >\n                        {currency}\n                        {Number.isFinite(value) && value > 0 ? value : 0}\n                      </motion.p>\n                    </AnimatePresence>\n                    <p className=\"m-0 mt-2 text-[14px] opacity-80\">For {to.trim() || \"someone special\"}</p>\n                  </div>\n                </div>\n                {/* Back */}\n                <div\n                  className=\"absolute inset-0 flex flex-col justify-between overflow-hidden rounded-[22px] p-6 shadow-[0_30px_60px_rgba(0,0,0,0.45)] [backface-visibility:hidden] [transform:rotateY(180deg)]\"\n                  style={{ background: \"#FBF8F2\", color: \"#1B1A17\" }}\n                  aria-hidden={!flipped || undefined}\n                >\n                  <p className=\"m-0 text-[12px] tracking-[0.1em] uppercase opacity-50\">Dear {to.trim() || \"you\"},</p>\n                  <p className=\"m-0 line-clamp-4 text-[19px] leading-[1.35]\" style={{ fontFamily: f.family, fontStyle: f.style }}>\n                    {message.trim() || \"Your message appears here.\"}\n                  </p>\n                  <p className=\"m-0 text-right text-[14px]\" style={{ fontFamily: f.family, fontStyle: f.style }}>\n                    — {from.trim() || \"A friend\"}\n                  </p>\n                </div>\n              </motion.div>\n            </motion.div>\n          </div>\n          <div className=\"mt-5 flex justify-center\">\n            <button\n              type=\"button\"\n              onClick={() => setFlipped((v) => !v)}\n              aria-pressed={flipped}\n              className={cn(\"flex h-9 cursor-pointer items-center gap-2 rounded-full border px-4 text-[13px] font-medium\", focus)}\n              style={{ borderColor: p.line, background: \"transparent\", color: p.title }}\n            >\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M4 12a8 8 0 0 1 13.6-5.7L20 9M20 4v5h-5M20 12a8 8 0 0 1-13.6 5.7L4 15M4 20v-5h5\" />\n              </svg>\n              {flipped ? \"Show the front\" : \"See the message side\"}\n            </button>\n          </div>\n        </div>\n\n        {/* Form */}\n        <div className=\"flex flex-col gap-6 rounded-3xl border p-5 sm:p-6\" style={{ background: p.panel, borderColor: p.line }}>\n          <fieldset className=\"m-0 border-0 p-0\">\n            <legend className=\"mb-2.5 text-[13.5px] font-semibold\">Design · {d.name}</legend>\n            <div role=\"radiogroup\" aria-label=\"Design\" className=\"grid grid-cols-6 gap-2\">\n              {designs.map((x) => (\n                <button\n                  key={x.id}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={design === x.id}\n                  aria-label={x.name}\n                  onClick={() => {\n                    setDesign(x.id);\n                    setFlipped(false);\n                  }}\n                  className={cn(\"aspect-[1.6/1] cursor-pointer rounded-lg border-2 p-0\", focus)}\n                  style={{ background: x.background, borderColor: design === x.id ? p.accent : \"transparent\" }}\n                />\n              ))}\n            </div>\n          </fieldset>\n\n          <fieldset className=\"m-0 border-0 p-0\">\n            <legend className=\"mb-2.5 text-[13.5px] font-semibold\">Amount</legend>\n            <div className=\"grid grid-cols-4 gap-2\">\n              {amounts.map((a) => {\n                const on = !custom && amount === a;\n                return (\n                  <button\n                    key={a}\n                    type=\"button\"\n                    aria-pressed={on}\n                    onClick={() => {\n                      setAmount(a);\n                      setCustom(\"\");\n                      setFlipped(false);\n                    }}\n                    className={cn(\"h-11 cursor-pointer rounded-xl border text-[14.5px] font-semibold tabular-nums\", focus)}\n                    style={on ? { background: p.buttonBg, color: p.buttonText, borderColor: p.buttonBg } : { background: \"transparent\", color: p.title, borderColor: p.line }}\n                  >\n                    {currency}\n                    {a}\n                  </button>\n                );\n              })}\n            </div>\n            <div className=\"relative mt-2\">\n              <label htmlFor={`${uid}-custom`} className=\"sr-only\">\n                Custom amount\n              </label>\n              <span className=\"pointer-events-none absolute top-1/2 left-3.5 -translate-y-1/2 text-[14px]\" style={{ color: p.muted }}>\n                {currency}\n              </span>\n              <input\n                id={`${uid}-custom`}\n                inputMode=\"numeric\"\n                value={custom}\n                onChange={(e) => {\n                  setCustom(e.target.value.replace(/\\D/g, \"\").slice(0, 4));\n                  setFlipped(false);\n                }}\n                placeholder={`Other amount (${min}–${max})`}\n                aria-invalid={!!amountErr}\n                className={cn(field, \"pl-8\")}\n                style={fs(!!amountErr)}\n              />\n            </div>\n            {amountErr && (\n              <p className=\"m-0 mt-1 text-[12px]\" style={{ color: p.danger }}>\n                {amountErr}\n              </p>\n            )}\n          </fieldset>\n\n          <div className=\"grid grid-cols-2 gap-3\">\n            {(\n              [\n                [\"to\", \"To\", to, setTo, \"Recipient’s name\"],\n                [\"from\", \"From\", from, setFrom, \"Your name\"],\n              ] as const\n            ).map(([k, label, v, set, ph]) => (\n              <div key={k}>\n                <label htmlFor={`${uid}-${k}`} className=\"mb-1.5 block text-[12.5px] font-medium\" style={{ color: p.body }}>\n                  {label}\n                </label>\n                <input id={`${uid}-${k}`} value={v} onChange={(e) => set(e.target.value.slice(0, 30))} placeholder={ph} className={field} style={fs(k === \"to\" && tried && !to.trim())} />\n              </div>\n            ))}\n            <div className=\"col-span-2\">\n              <label htmlFor={`${uid}-email`} className=\"mb-1.5 block text-[12.5px] font-medium\" style={{ color: p.body }}>\n                Recipient’s email\n              </label>\n              <input id={`${uid}-email`} type=\"email\" autoComplete=\"off\" value={email} onChange={(e) => setEmail(e.target.value)} placeholder=\"sam@example.com\" aria-invalid={tried && !!emailErr} className={field} style={fs(tried && !!emailErr)} />\n              {tried && emailErr && (\n                <p className=\"m-0 mt-1 text-[12px]\" style={{ color: p.danger }}>\n                  {emailErr}\n                </p>\n              )}\n            </div>\n          </div>\n\n          <div>\n            <div className=\"mb-1.5 flex items-center justify-between\">\n              <label htmlFor={`${uid}-msg`} className=\"text-[12.5px] font-medium\" style={{ color: p.body }}>\n                Message\n              </label>\n              <span className=\"text-[11.5px] tabular-nums\" style={{ color: MAX_MSG - message.length < 15 ? p.danger : p.muted }}>\n                {MAX_MSG - message.length}\n              </span>\n            </div>\n            <textarea\n              id={`${uid}-msg`}\n              rows={3}\n              maxLength={MAX_MSG}\n              value={message}\n              onChange={(e) => setMessage(e.target.value)}\n              onFocus={() => setFlipped(true)}\n              className={cn(\"w-full resize-none rounded-xl border px-3.5 py-2.5 text-[16px] leading-[1.45] sm:text-[14px]\", focus)}\n              style={{ ...fs(false), fontFamily: f.family, fontStyle: f.style }}\n            />\n            <div role=\"radiogroup\" aria-label=\"Lettering\" className=\"mt-2 flex gap-1.5\">\n              {(Object.keys(FONTS) as (keyof typeof FONTS)[]).map((k) => (\n                <button\n                  key={k}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={font === k}\n                  onClick={() => {\n                    setFont(k);\n                    setFlipped(true);\n                  }}\n                  className={cn(\"h-8 flex-1 cursor-pointer rounded-lg border text-[13px]\", focus)}\n                  style={{ fontFamily: FONTS[k].family, fontStyle: FONTS[k].style, ...(font === k ? { background: p.ghost, borderColor: p.title, color: p.title } : { background: \"transparent\", borderColor: p.line, color: p.body }) }}\n                >\n                  {FONTS[k].label}\n                </button>\n              ))}\n            </div>\n          </div>\n\n          <fieldset className=\"m-0 border-0 p-0\">\n            <legend className=\"mb-2.5 text-[13.5px] font-semibold\">Send it</legend>\n            <div role=\"radiogroup\" aria-label=\"Delivery\" className=\"grid grid-cols-2 gap-2\">\n              {(\n                [\n                  [\"now\", \"Right away\"],\n                  [\"later\", \"On a date\"],\n                ] as const\n              ).map(([k, label]) => (\n                <button\n                  key={k}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={when === k}\n                  onClick={() => setWhen(k)}\n                  className={cn(\"h-11 cursor-pointer rounded-xl border text-[13.5px] font-medium\", focus)}\n                  style={when === k ? { background: p.ghost, borderColor: p.title, color: p.title } : { background: \"transparent\", borderColor: p.line, color: p.body }}\n                >\n                  {label}\n                </button>\n              ))}\n            </div>\n            <AnimatePresence initial={false}>\n              {when === \"later\" && (\n                <motion.div initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"overflow-hidden\">\n                  <label htmlFor={`${uid}-date`} className=\"mt-3 mb-1.5 block text-[12.5px] font-medium\" style={{ color: p.body }}>\n                    Delivery date (9 am their time)\n                  </label>\n                  <input id={`${uid}-date`} type=\"date\" min=\"2026-11-05\" value={date} onChange={(e) => setDate(e.target.value)} className={field} style={{ ...fs(false), colorScheme: theme }} />\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </fieldset>\n\n          <button\n            type=\"button\"\n            onClick={add}\n            className={cn(\"flex h-12 cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[15px] font-semibold transition-colors\", focus)}\n            style={added ? { background: p.accent, color: p.accentText } : { background: p.buttonBg, color: p.buttonText }}\n            aria-live=\"polite\"\n          >\n            {added ? `Added ✓ ${currency}${value} card for ${to.trim()}` : `Add ${currency}${Number.isFinite(value) && value > 0 ? value : 0} gift card`}\n          </button>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}