{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter-signup-section",
  "title": "Newsletter Signup Section",
  "description": "A newsletter signup section: perks and reader proof on the left, a form card with email validation, weekly or monthly radio cards and topic chips on the right, a check-your-inbox screen with a resend cooldown, and a list of recent issues.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/newsletter-signup-section/newsletter-signup-section.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 NewsletterFrequency {\n  id: string;\n  label: string;\n  note?: string;\n}\n\nexport interface NewsletterIssue {\n  title: string;\n  date: string;\n  href?: string;\n}\n\nexport interface NewsletterSubscribeData {\n  email: string;\n  frequency: string;\n  topics: string[];\n}\n\nexport interface NewsletterSignupSectionProps {\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  perks?: string[];\n  /** Radio cards for how often people get the email. Pass [] to hide them. */\n  frequencies?: NewsletterFrequency[];\n  /** Topic chips people can pick from. Pass [] to hide them. */\n  topics?: string[];\n  /** Recent issues listed under the form. Pass [] to hide them. */\n  issues?: NewsletterIssue[];\n  /** Social proof under the perks. Pass null to hide it. */\n  proof?: { avatars?: string[]; text: string } | null;\n  /**\n   * Called with the email, frequency and topics. Return a promise: the button spins while it runs,\n   * a rejection (or a returned string) shows an error, and success shows the check-your-inbox screen.\n   */\n  onSubscribe?: (data: NewsletterSubscribeData) => void | string | Promise<void | string>;\n  /** Called from the success screen's resend link. */\n  onResend?: (email: string) => void;\n  submitLabel?: string;\n  privacyNote?: React.ReactNode;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    text: \"#F5F4F1\",\n    muted: \"rgba(245,244,241,0.6)\",\n    faint: \"rgba(245,244,241,0.38)\",\n    card: \"#111111\",\n    border: \"rgba(255,255,255,0.1)\",\n    field: \"rgba(255,255,255,0.03)\",\n    fieldBorder: \"rgba(255,255,255,0.14)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    on: \"#F5F4F1\",\n    onText: \"#0A0A0A\",\n    error: \"#FF7A6B\",\n    ok: \"#4ADE80\",\n    ring: \"rgba(245,244,241,0.6)\",\n  },\n  light: {\n    bg: \"#FAFAF8\",\n    text: \"#0A0A0A\",\n    muted: \"rgba(10,10,10,0.6)\",\n    faint: \"rgba(10,10,10,0.4)\",\n    card: \"#FFFFFF\",\n    border: \"rgba(10,10,10,0.1)\",\n    field: \"#FFFFFF\",\n    fieldBorder: \"rgba(10,10,10,0.16)\",\n    chip: \"rgba(10,10,10,0.04)\",\n    on: \"#0A0A0A\",\n    onText: \"#FAFAF8\",\n    error: \"#D93F2B\",\n    ok: \"#16A34A\",\n    ring: \"rgba(10,10,10,0.5)\",\n  },\n};\n\nconst DEFAULT_FREQUENCIES: NewsletterFrequency[] = [\n  { id: \"weekly\", label: \"Weekly\", note: \"Every Thursday, 5 minutes\" },\n  { id: \"monthly\", label: \"Monthly\", note: \"The best of the month\" },\n];\nconst DEFAULT_TOPICS = [\"Product\", \"Design\", \"Engineering\", \"Careers\"];\nconst DEFAULT_ISSUES: NewsletterIssue[] = [\n  { title: \"How we cut our planning meetings in half\", date: \"Oct 30\", href: \"#\" },\n  { title: \"A spec template that people actually read\", date: \"Oct 23\", href: \"#\" },\n  { title: \"Roadmaps without dates: a field guide\", date: \"Oct 16\", href: \"#\" },\n];\nconst DEFAULT_PERKS = [\"One practical idea per issue, no fluff\", \"Templates and checklists you can copy\", \"Unsubscribe in one click, any time\"];\n\nexport function NewsletterSignupSection({\n  eyebrow = \"Newsletter\",\n  title = \"The Thursday letter for people who build products\",\n  description = \"One email a week with what we learned shipping software: planning, specs, design reviews and the occasional mistake.\",\n  perks = DEFAULT_PERKS,\n  frequencies = DEFAULT_FREQUENCIES,\n  topics = DEFAULT_TOPICS,\n  issues = DEFAULT_ISSUES,\n  proof = { avatars: [\"/demo/41.webp\", \"/demo/44.webp\", \"/demo/42.webp\"], text: \"Join 24,000 readers\" },\n  onSubscribe,\n  onResend,\n  submitLabel = \"Subscribe\",\n  privacyNote = \"No spam. We never share your email.\",\n  theme = \"dark\",\n  className,\n}: NewsletterSignupSectionProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [email, setEmail] = React.useState(\"\");\n  const [touched, setTouched] = React.useState(false);\n  const [freq, setFreq] = React.useState(frequencies[0]?.id ?? \"\");\n  const [picked, setPicked] = React.useState<string[]>(topics.slice(0, 2));\n  const [status, setStatus] = React.useState<\"idle\" | \"loading\" | \"done\">(\"idle\");\n  const [error, setError] = React.useState(\"\");\n  const [cooldown, setCooldown] = React.useState(0);\n  // The success heading mounts after the form has faded out, so focus it when it attaches.\n  const doneRef = React.useCallback((el: HTMLHeadingElement | null) => el?.focus(), []);\n  const valid = /^\\S+@\\S+\\.\\S+$/.test(email.trim());\n  const showInvalid = touched && !valid;\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n\n  React.useEffect(() => {\n    if (cooldown <= 0) return;\n    const id = setTimeout(() => setCooldown((c) => c - 1), 1000);\n    return () => clearTimeout(id);\n  }, [cooldown]);\n\n  const submit = async (e: React.FormEvent) => {\n    e.preventDefault();\n    setTouched(true);\n    setError(\"\");\n    if (!valid) return;\n    setStatus(\"loading\");\n    try {\n      const res = await onSubscribe?.({ email: email.trim(), frequency: freq, topics: picked });\n      if (typeof res === \"string\") {\n        setError(res);\n        setStatus(\"idle\");\n        return;\n      }\n      setStatus(\"done\");\n    } catch (err) {\n      setError(err instanceof Error ? err.message : \"Something went wrong. Please try again.\");\n      setStatus(\"idle\");\n    }\n  };\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto grid max-w-6xl grid-cols-1 items-start gap-10 px-6 py-20 @[860px]:grid-cols-[1fr_1.05fr] @[860px]:gap-16 @[640px]:py-24\">\n        <div>\n          {eyebrow && (\n            <p className=\"m-0 text-[13px] font-medium tracking-[0.12em] uppercase\" style={{ color: p.faint }}>\n              {eyebrow}\n            </p>\n          )}\n          <h2 className=\"mt-3 mb-0 max-w-[18ch] text-[32px] leading-[1.1] font-semibold tracking-[-0.03em] @[640px]:text-[44px]\">{title}</h2>\n          {description && (\n            <p className=\"mt-4 mb-0 max-w-[460px] text-[16px] leading-[1.6]\" style={{ color: p.muted }}>\n              {description}\n            </p>\n          )}\n          {perks.length > 0 && (\n            <ul className=\"m-0 mt-7 flex list-none flex-col gap-3 p-0\">\n              {perks.map((perk, i) => (\n                <motion.li key={perk} initial={reduce ? false : { opacity: 0, x: -8 }} whileInView={{ opacity: 1, x: 0 }} viewport={{ once: true }} transition={{ delay: reduce ? 0 : i * 0.08 }} className=\"flex items-start gap-3 text-[15px]\">\n                  <span className=\"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full\" style={{ background: p.chip, color: p.ok }} aria-hidden=\"true\">\n                    <svg width=\"11\" height=\"11\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                      <path d=\"m3 8.5 3 3 7-7\" />\n                    </svg>\n                  </span>\n                  {perk}\n                </motion.li>\n              ))}\n            </ul>\n          )}\n          {proof && (\n            <div className=\"mt-8 flex items-center gap-3\">\n              {proof.avatars && proof.avatars.length > 0 && (\n                <div className=\"flex -space-x-2\">\n                  {proof.avatars.slice(0, 4).map((src) => (\n                    // eslint-disable-next-line @next/next/no-img-element\n                    <img key={src} src={src} alt=\"\" width={30} height={30} className=\"h-[30px] w-[30px] rounded-full object-cover\" style={{ boxShadow: `0 0 0 2px ${p.bg}` }} />\n                  ))}\n                </div>\n              )}\n              <span className=\"text-[13.5px]\" style={{ color: p.muted }}>\n                {proof.text}\n              </span>\n            </div>\n          )}\n        </div>\n\n        <div>\n          <div className=\"relative overflow-hidden rounded-2xl border p-5 @[640px]:p-7\" style={{ background: p.card, borderColor: p.border }}>\n            <AnimatePresence mode=\"wait\" initial={false}>\n              {status === \"done\" ? (\n                <motion.div key=\"done\" role=\"status\" initial={reduce ? false : { opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"flex flex-col items-center py-6 text-center\">\n                  <motion.svg width=\"64\" height=\"64\" viewBox=\"0 0 64 64\" fill=\"none\" aria-hidden=\"true\" initial={reduce ? false : { scale: 0.6, rotate: -8 }} animate={{ scale: 1, rotate: 0 }} transition={{ type: \"spring\", stiffness: 220, damping: 14 }}>\n                    <rect x=\"8\" y=\"16\" width=\"48\" height=\"34\" rx=\"6\" stroke={p.text} strokeWidth=\"2.5\" />\n                    <motion.path d=\"m10 20 22 16 22-16\" stroke={p.text} strokeWidth=\"2.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={reduce ? false : { pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ delay: 0.2, duration: 0.5 }} />\n                    <circle cx=\"50\" cy=\"16\" r=\"8\" fill={p.ok} />\n                    <path d=\"m46.5 16 2.5 2.5 4.5-5\" stroke={p.card} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                  </motion.svg>\n                  <h3 ref={doneRef} tabIndex={-1} className=\"mt-5 mb-0 text-[22px] font-semibold tracking-[-0.02em] outline-none\">\n                    Check your inbox\n                  </h3>\n                  <p className=\"mt-2 mb-0 max-w-[320px] text-[14.5px] leading-[1.6]\" style={{ color: p.muted }}>\n                    We sent a confirmation link to <span style={{ color: p.text }}>{email.trim()}</span>. Click it and you are in.\n                  </p>\n                  <div className=\"mt-6 flex flex-wrap items-center justify-center gap-x-4 gap-y-2 text-[13.5px]\">\n                    <button\n                      type=\"button\"\n                      disabled={cooldown > 0}\n                      onClick={() => {\n                        onResend?.(email.trim());\n                        setCooldown(30);\n                      }}\n                      className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 underline underline-offset-4 disabled:cursor-default disabled:no-underline\", focus)}\n                      style={{ color: cooldown > 0 ? p.faint : p.text, ...ring }}\n                    >\n                      <span aria-live=\"polite\">{cooldown > 0 ? `Sent again. Resend in ${cooldown}s` : \"Resend the email\"}</span>\n                    </button>\n                    <button\n                      type=\"button\"\n                      onClick={() => {\n                        setStatus(\"idle\");\n                        setTouched(false);\n                      }}\n                      className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 underline underline-offset-4\", focus)}\n                      style={{ color: p.muted, ...ring }}\n                    >\n                      Use a different email\n                    </button>\n                  </div>\n                </motion.div>\n              ) : (\n                <motion.form key=\"form\" noValidate onSubmit={submit} initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} aria-labelledby={`${uid}-t`}>\n                  <h3 id={`${uid}-t`} className=\"m-0 text-[17px] font-semibold\">\n                    Get the letter\n                  </h3>\n                  <label htmlFor={`${uid}-email`} className=\"mt-5 mb-1.5 block text-[13px]\" style={{ color: p.muted }}>\n                    Email\n                  </label>\n                  <input\n                    id={`${uid}-email`}\n                    type=\"email\"\n                    autoComplete=\"email\"\n                    inputMode=\"email\"\n                    placeholder=\"you@company.com\"\n                    value={email}\n                    disabled={status === \"loading\"}\n                    aria-invalid={showInvalid || undefined}\n                    aria-describedby={`${uid}-err`}\n                    onChange={(e) => {\n                      setEmail(e.target.value);\n                      setError(\"\");\n                    }}\n                    onBlur={() => email && setTouched(true)}\n                    className=\"h-12 w-full rounded-xl border px-4 text-[16px] transition-colors outline-none focus-visible:ring-2 disabled:opacity-60\"\n                    style={{ background: p.field, borderColor: showInvalid ? p.error : p.fieldBorder, color: p.text, ...ring }}\n                  />\n                  {frequencies.length > 0 && (\n                    <fieldset className=\"m-0 mt-5 min-w-0 border-0 p-0\">\n                      <legend className=\"mb-2 p-0 text-[13px]\" style={{ color: p.muted }}>\n                        How often\n                      </legend>\n                      <div className=\"grid grid-cols-1 gap-2 @[480px]:grid-cols-2\">\n                        {frequencies.map((f) => {\n                          const on = freq === f.id;\n                          return (\n                            <label key={f.id} className=\"relative flex cursor-pointer items-start gap-3 rounded-xl border p-3 transition-colors has-[:focus-visible]:ring-2\" style={{ borderColor: on ? p.on : p.fieldBorder, background: on ? p.chip : \"transparent\", ...ring }}>\n                              <input type=\"radio\" name={`${uid}-freq`} value={f.id} checked={on} onChange={() => setFreq(f.id)} className=\"sr-only\" />\n                              <span className=\"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border\" style={{ borderColor: on ? p.on : p.fieldBorder }} aria-hidden=\"true\">\n                                {on && <motion.span layoutId={`${uid}-dot`} className=\"h-2 w-2 rounded-full\" style={{ background: p.on }} />}\n                              </span>\n                              <span>\n                                <span className=\"block text-[14px] font-medium\">{f.label}</span>\n                                {f.note && (\n                                  <span className=\"mt-0.5 block text-[12.5px]\" style={{ color: p.faint }}>\n                                    {f.note}\n                                  </span>\n                                )}\n                              </span>\n                            </label>\n                          );\n                        })}\n                      </div>\n                    </fieldset>\n                  )}\n                  {topics.length > 0 && (\n                    <fieldset className=\"m-0 mt-5 min-w-0 border-0 p-0\">\n                      <legend className=\"mb-2 p-0 text-[13px]\" style={{ color: p.muted }}>\n                        Topics you care about\n                      </legend>\n                      <div className=\"flex flex-wrap gap-1.5\">\n                        {topics.map((t) => {\n                          const on = picked.includes(t);\n                          return (\n                            <label key={t} className=\"cursor-pointer rounded-full transition-colors has-[:focus-visible]:ring-2\" style={ring}>\n                              <input type=\"checkbox\" checked={on} onChange={() => setPicked((v) => (on ? v.filter((x) => x !== t) : [...v, t]))} className=\"sr-only\" />\n                              <span className=\"flex h-8 items-center gap-1.5 rounded-full border px-3 text-[13px]\" style={{ borderColor: on ? p.on : p.fieldBorder, background: on ? p.on : \"transparent\", color: on ? p.onText : p.muted }}>\n                                {on && (\n                                  <svg width=\"11\" height=\"11\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                    <path d=\"m3 8.5 3 3 7-7\" />\n                                  </svg>\n                                )}\n                                {t}\n                              </span>\n                            </label>\n                          );\n                        })}\n                      </div>\n                    </fieldset>\n                  )}\n                  <p id={`${uid}-err`} role=\"alert\" className=\"m-0 mt-3 min-h-[20px] text-[13px]\" style={{ color: p.error }}>\n                    {showInvalid ? \"Add a valid email address.\" : error}\n                  </p>\n                  <button type=\"submit\" disabled={status === \"loading\"} className={cn(\"mt-1 flex h-12 w-full cursor-pointer items-center justify-center gap-2 rounded-xl border-0 text-[15px] font-medium transition-opacity hover:opacity-90 disabled:cursor-wait\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                    {status === \"loading\" ? (\n                      <>\n                        <motion.span className=\"h-4 w-4 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: \"linear\" }} aria-hidden=\"true\" />\n                        Subscribing...\n                      </>\n                    ) : (\n                      submitLabel\n                    )}\n                  </button>\n                  {privacyNote && (\n                    <p className=\"m-0 mt-3 text-center text-[12.5px]\" style={{ color: p.faint }}>\n                      {privacyNote}\n                    </p>\n                  )}\n                </motion.form>\n              )}\n            </AnimatePresence>\n          </div>\n\n          {issues.length > 0 && (\n            <div className=\"mt-6\">\n              <p className=\"m-0 mb-2 text-[12px] font-medium tracking-[0.1em] uppercase\" style={{ color: p.faint }}>\n                Recent issues\n              </p>\n              <ul className=\"m-0 list-none p-0\">\n                {issues.map((issue) => (\n                  <li key={issue.title} className=\"border-t first:border-t-0\" style={{ borderColor: p.border }}>\n                    <a href={issue.href ?? \"#\"} className={cn(\"group flex items-baseline gap-4 rounded py-3 text-[14.5px] no-underline\", focus)} style={{ color: p.text, ...ring, [\"--tw-ring-offset-color\" as string]: p.bg }}>\n                      <span className=\"w-12 shrink-0 text-[12.5px] tabular-nums\" style={{ color: p.faint }}>\n                        {issue.date}\n                      </span>\n                      <span className=\"flex-1 group-hover:underline group-hover:underline-offset-4\">{issue.title}</span>\n                      <span aria-hidden=\"true\" className=\"transition-transform group-hover:translate-x-0.5\" style={{ color: p.faint }}>\n                        →\n                      </span>\n                    </a>\n                  </li>\n                ))}\n              </ul>\n            </div>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default NewsletterSignupSection;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}