{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter-motion",
  "title": "Newsletter (Motion)",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 3 newsletter variants: https://avaraui.com/view/newsletter. This item holds 3 of them as looks of one component (portraits, spotlight, issues). Skip the question if the user already named one. A sign-up section in three layouts: readers' faces drifting around a centred form, a panel with a pointer glow and a ticker of who just joined, or the form beside a fanned stack of recent issues. The form becomes a thank-you when your promise resolves.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://avaraui.com/r/button.json",
    "https://avaraui.com/r/input.json",
    "https://avaraui.com/r/marquee.json",
    "https://avaraui.com/r/tilted-card.json",
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/motion/NewsletterBlock.tsx",
      "content": "\"use client\";\n\nimport React, { createContext, useContext, useRef, useState } from \"react\";\nimport {\n  AnimatePresence,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n  type MotionValue,\n  type Variants,\n} from \"motion/react\";\nimport { ArrowRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport Button from \"@/components/custom/blocks/Button\";\nimport { InputBlock } from \"@/components/custom/blocks/InputBlock\";\nimport { MarqueeBlock } from \"@/components/custom/blocks/MarqueeBlock\";\nimport { TiltedCard } from \"@/components/custom/blocks/TiltedCardBlock\";\n\n// ==========================================\n// NEWSLETTER\n// A sign-up section in three layouts. `portraits` puts four readers' faces\n// around a centred form on a soft panel and lets them drift with the pointer;\n// `spotlight` is the same form on a dark panel with a glow under the cursor\n// and a ticker of who just joined; `issues` puts the form beside a fanned\n// stack of recent issues. One reveal when the section first appears, a\n// form that turns into a thank-you when your promise resolves, and nothing\n// else moves unless the reader does.\n// ==========================================\n\nexport type NewsletterVariant = \"portraits\" | \"spotlight\" | \"issues\";\n\ninterface NewsletterContextValue {\n  variant: NewsletterVariant;\n  reveal: \"in-view\" | \"immediate\";\n  reduced: boolean;\n}\n\nconst NewsletterContext = createContext<NewsletterContextValue>({\n  variant: \"portraits\",\n  reveal: \"in-view\",\n  reduced: false,\n});\n\nconst rise: Variants = {\n  hidden: { opacity: 0, y: 18 },\n  visible: { opacity: 1, y: 0, transition: { duration: 0.7, ease: [0.16, 1, 0.3, 1] } },\n};\n\n/** Animates as one child of the section's staggered reveal. */\nfunction Reveal({ className, children }: { className?: string; children: React.ReactNode }) {\n  const { reduced } = useContext(NewsletterContext);\n  return (\n    <motion.div className={className} {...(reduced ? {} : { variants: rise })}>\n      {children}\n    </motion.div>\n  );\n}\n\n// ------------------------------------------\n// Heading, Intro\n// ------------------------------------------\nfunction Heading({ className, children, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <h2\n        className={cn(\n          \"font-sans text-[2rem] font-semibold leading-[1.08] tracking-[-0.03em] sm:text-[2.6rem]\",\n          variant === \"issues\" ? \"text-left\" : \"text-center\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </h2>\n    </Reveal>\n  );\n}\n\nfunction Intro({ className, children, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <p\n        className={cn(\n          \"mt-4 max-w-md text-[15px] leading-[1.65] opacity-65\",\n          variant === \"issues\" ? \"text-left\" : \"mx-auto text-center\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </p>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Form — a pill with the button inside, that becomes a thank-you\n// ------------------------------------------\nexport interface NewsletterFormProps extends Omit<React.FormHTMLAttributes<HTMLFormElement>, \"onSubmit\"> {\n  placeholder?: string;\n  /** Button label. */\n  action?: string;\n  /** Return a promise to keep the button busy; resolve to show the thank-you, throw to stay on the form. */\n  onSubscribe?: (email: string) => void | Promise<void>;\n  successTitle?: string;\n  successText?: string;\n}\n\nfunction Form({\n  placeholder = \"name@email.com\",\n  action = \"Subscribe now\",\n  onSubscribe,\n  successTitle = \"You're subscribed\",\n  successText = \"Look out for the next edition in your inbox.\",\n  className,\n  ...props\n}: NewsletterFormProps) {\n  const { variant, reduced } = useContext(NewsletterContext);\n  const [email, setEmail] = useState(\"\");\n  const [busy, setBusy] = useState(false);\n  const [done, setDone] = useState(false);\n\n  const submit = async (e: React.FormEvent<HTMLFormElement>) => {\n    e.preventDefault();\n    if (!email || busy) return;\n    setBusy(true);\n    try {\n      await onSubscribe?.(email);\n      setDone(true);\n    } catch {\n      // Stay on the form; the caller shows its own error.\n    } finally {\n      setBusy(false);\n    }\n  };\n\n  return (\n    <Reveal className={cn(\"mt-8 w-full max-w-[26rem]\", variant !== \"issues\" && \"mx-auto\")}>\n      <AnimatePresence mode=\"wait\" initial={false}>\n        {done ? (\n          <motion.div\n            key=\"done\"\n            role=\"status\"\n            initial={reduced ? false : { opacity: 0, scale: 0.96 }}\n            animate={{ opacity: 1, scale: 1 }}\n            transition={{ duration: 0.45, ease: [0.16, 1, 0.3, 1] }}\n            className=\"flex items-center gap-3 rounded-full bg-card py-2 pl-2 pr-5 text-card-foreground shadow-[0_1px_2px_rgba(0,0,0,0.05),0_8px_24px_-12px_rgba(0,0,0,0.2)] dark:shadow-none dark:ring-1 dark:ring-border\"\n          >\n            <span className=\"grid h-10 w-10 shrink-0 place-items-center rounded-full bg-emerald-500 text-white\">\n              <motion.svg viewBox=\"0 0 24 24\" className=\"h-5 w-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2.5} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <motion.path\n                  d=\"M5 12.5l4.5 4.5L19 7.5\"\n                  initial={reduced ? false : { pathLength: 0 }}\n                  animate={{ pathLength: 1 }}\n                  transition={{ duration: 0.5, delay: 0.15, ease: \"easeOut\" }}\n                />\n              </motion.svg>\n            </span>\n            <span className=\"min-w-0 text-left\">\n              <span className=\"block text-[14px] font-semibold leading-tight\">{successTitle}</span>\n              <span className=\"block text-[12px] leading-tight text-muted-foreground\">{successText}</span>\n            </span>\n          </motion.div>\n        ) : (\n          <motion.div\n            key=\"form\"\n            initial={false}\n            {...(reduced ? {} : { exit: { opacity: 0, scale: 0.97, transition: { duration: 0.2 } } })}\n          >\n          <form\n            onSubmit={submit}\n            className={cn(\n              \"flex items-center gap-1 rounded-full p-1.5 transition-shadow duration-300\",\n              \"bg-card shadow-[0_1px_2px_rgba(0,0,0,0.05),0_8px_24px_-12px_rgba(0,0,0,0.2)] focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.05),0_12px_32px_-12px_rgba(0,0,0,0.28)]\",\n              \"dark:shadow-none dark:ring-1 dark:ring-foreground/15 dark:backdrop-blur dark:focus-within:shadow-none dark:focus-within:ring-foreground/30\",\n              className,\n            )}\n            {...props}\n          >\n            {/* The library input, with its own box made invisible so the pill is the field. */}\n            <InputBlock\n              type=\"email\"\n              variant=\"filled\"\n              inputSize=\"md\"\n              required\n              value={email}\n              onChange={(e) => setEmail(e.target.value)}\n              placeholder={placeholder}\n              aria-label=\"Email address\"\n              autoComplete=\"email\"\n              className=\"min-w-0 flex-1 gap-0 [&>div>div]:h-10 [&>div>div]:rounded-full [&>div>div]:border-0 [&>div>div]:bg-transparent [&>div>div]:px-4 [&>div>div]:shadow-none [&>div>div]:focus-within:bg-transparent [&>div>div]:focus-within:ring-0 [&_input]:text-foreground [&_input]:placeholder:text-muted-foreground\"\n            />\n            <Button\n              type=\"submit\"\n              variant=\"default\"\n              size=\"sm\"\n              loading={busy}\n              iconRight={<ArrowRight size={14} />}\n              className=\"h-10 shrink-0 rounded-full px-4 text-[13px] shadow-none\"\n            >\n              {action}\n            </Button>\n          </form>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Proof — a stack of faces and a line\n// ------------------------------------------\nexport interface NewsletterProofProps extends React.HTMLAttributes<HTMLDivElement> {\n  avatars: string[];\n}\n\nfunction Proof({ avatars, className, children, ...props }: NewsletterProofProps) {\n  const { variant } = useContext(NewsletterContext);\n  return (\n    <Reveal>\n      <div\n        className={cn(\n          \"mt-7 flex items-center gap-3 text-[13px] font-medium text-foreground/65\",\n          variant !== \"issues\" && \"justify-center\",\n          className,\n        )}\n        {...props}\n      >\n        <span className=\"flex items-center\">\n          <span className=\"flex -space-x-2\">\n            {avatars.slice(0, 5).map((src, i) => (\n              <img\n                key={src + i}\n                src={src}\n                alt=\"\"\n                className=\"h-7 w-7 rounded-full object-cover ring-2 ring-background\"\n              />\n            ))}\n          </span>\n          <span\n            className=\"-ml-1 grid h-7 w-7 place-items-center rounded-full bg-foreground text-[11px] font-semibold text-background ring-2 ring-background\"\n            aria-hidden\n          >\n            +\n          </span>\n        </span>\n        <span>{children}</span>\n      </div>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Ticker — who just joined (spotlight)\n// ------------------------------------------\nexport interface NewsletterTickerItem {\n  name: string;\n  avatar?: string;\n  when: string;\n}\n\nfunction Ticker({ items, className }: { items: NewsletterTickerItem[]; className?: string }) {\n  return (\n    <Reveal className={cn(\"mt-12 w-full\", className)}>\n      <MarqueeBlock direction=\"left\" speed=\"slow\" gap=\"0.75rem\" fade pauseOnHover className=\"w-full\">\n        {items.map((it, i) => (\n          <span\n            key={it.name + i}\n            className=\"inline-flex shrink-0 items-center gap-2 rounded-full bg-card py-1.5 pl-1.5 pr-3.5 text-[12px] text-foreground/75 shadow-[0_1px_2px_rgba(0,0,0,0.04),0_6px_16px_-10px_rgba(0,0,0,0.2)] ring-1 ring-foreground/[0.08] dark:shadow-none\"\n          >\n            {it.avatar ? (\n              <img src={it.avatar} alt=\"\" className=\"h-6 w-6 rounded-full object-cover\" />\n            ) : (\n              <span className=\"grid h-6 w-6 place-items-center rounded-full bg-foreground/10 text-[10px] font-semibold\">\n                {it.name.slice(0, 1)}\n              </span>\n            )}\n            <span className=\"font-semibold text-foreground\">{it.name}</span> joined\n            <span className=\"text-foreground/45\">· {it.when}</span>\n          </span>\n        ))}\n      </MarqueeBlock>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Issues — a fanned stack of recent issues (issues layout)\n// ------------------------------------------\nexport interface NewsletterIssue {\n  title: string;\n  date: string;\n  excerpt: string;\n  /** A picture for the top card. */\n  cover?: string;\n  tag?: string;\n}\n\nfunction Issues({ items, className }: { items: NewsletterIssue[]; className?: string }) {\n  const [top, ...rest] = items;\n  if (!top) return null;\n  return (\n    <Reveal className={cn(\"relative mx-auto w-full max-w-[22rem] pt-8\", className)}>\n      {/* The two behind sit back, offset and turned; the stack spreads a little on hover. */}\n      <div className=\"group relative\">\n        {rest.slice(0, 2).map((issue, i) => (\n          <div\n            key={issue.title}\n            aria-hidden\n            className={cn(\n              \"absolute inset-x-0 top-0 rounded-2xl border border-border bg-card p-5 text-card-foreground shadow-[0_8px_24px_-14px_rgba(0,0,0,0.25)] transition-transform duration-500 ease-out\",\n              i === 0\n                ? \"-translate-y-4 scale-[0.94] rotate-[-4deg] group-hover:-translate-y-7 group-hover:rotate-[-7deg]\"\n                : \"-translate-y-8 scale-[0.88] rotate-[3deg] group-hover:-translate-y-12 group-hover:rotate-[6deg]\",\n            )}\n          >\n            <p className=\"text-[11px] font-medium opacity-50\">{issue.date}</p>\n            <p className=\"mt-1 truncate text-[15px] font-semibold\">{issue.title}</p>\n          </div>\n        ))}\n        <TiltedCard tiltIntensity={7} glareOpacity={0.1} scaleOnHover={1.02} className=\"h-auto\">\n          <article className=\"rounded-2xl border border-border bg-card p-5 text-left text-card-foreground\">\n            {top.cover && (\n              <div className=\"mb-4 h-32 overflow-hidden rounded-xl\">\n                <img src={top.cover} alt=\"\" className=\"h-full w-full object-cover\" />\n              </div>\n            )}\n            <div className=\"flex items-center justify-between gap-3 text-[11px] font-medium\">\n              <span className=\"opacity-50\">{top.date}</span>\n              {top.tag && <span className=\"rounded-full bg-primary/10 px-2 py-0.5 text-primary\">{top.tag}</span>}\n            </div>\n            <h3 className=\"mt-2 text-[17px] font-semibold leading-snug tracking-tight\">{top.title}</h3>\n            <p className=\"mt-2 text-[13px] leading-relaxed opacity-65\">{top.excerpt}</p>\n          </article>\n        </TiltedCard>\n      </div>\n    </Reveal>\n  );\n}\n\n// ------------------------------------------\n// Portraits — four faces that drift with the pointer\n// ------------------------------------------\nexport interface NewsletterPortrait {\n  src: string;\n  alt?: string;\n}\n\nconst CORNERS = [\n  { className: \"left-[7%] top-[13%] h-20 w-20 lg:h-[5.5rem] lg:w-[5.5rem]\", depth: 14 },\n  { className: \"right-[7%] top-[13%] h-16 w-16 lg:h-[4.5rem] lg:w-[4.5rem]\", depth: -10 },\n  { className: \"bottom-[13%] left-[8%] h-16 w-16 lg:h-[4.5rem] lg:w-[4.5rem]\", depth: -8 },\n  { className: \"bottom-[13%] right-[7%] h-20 w-20 lg:h-[5.5rem] lg:w-[5.5rem]\", depth: 12 },\n];\n\nfunction Portrait({\n  portrait,\n  corner,\n  mx,\n  my,\n  index,\n}: {\n  portrait: NewsletterPortrait;\n  corner: (typeof CORNERS)[number];\n  mx: MotionValue<number>;\n  my: MotionValue<number>;\n  index: number;\n}) {\n  const { reduced } = useContext(NewsletterContext);\n  const x = useTransform(mx, (v) => v * corner.depth);\n  const y = useTransform(my, (v) => v * corner.depth);\n  return (\n    <motion.div\n      className={cn(\"absolute hidden overflow-hidden rounded-full md:block\", corner.className)}\n      {...(reduced\n        ? {}\n        : {\n            style: { x, y },\n            variants: {\n              hidden: { opacity: 0, scale: 0.6 },\n              visible: {\n                opacity: 1,\n                scale: 1,\n                transition: { type: \"spring\" as const, stiffness: 260, damping: 18, delay: 0.35 + index * 0.08 },\n              },\n            },\n          })}\n    >\n      <img src={portrait.src} alt={portrait.alt ?? \"\"} className=\"h-full w-full object-cover\" />\n    </motion.div>\n  );\n}\n\n// ------------------------------------------\n// Root\n// ------------------------------------------\nexport interface NewsletterProps extends React.HTMLAttributes<HTMLElement> {\n  variant?: NewsletterVariant;\n  /** Up to four faces, for the `portraits` layout. */\n  portraits?: NewsletterPortrait[];\n  /** Accent for buttons, tags and the spotlight; defaults to the theme's primary. */\n  accent?: string;\n  reveal?: \"in-view\" | \"immediate\";\n  children: React.ReactNode;\n}\n\nconst isPart = (child: React.ReactNode, type: React.ElementType) =>\n  React.isValidElement(child) && child.type === type;\n\nexport function Newsletter({\n  variant = \"portraits\",\n  portraits = [],\n  accent,\n  reveal = \"in-view\",\n  className,\n  style,\n  children,\n  ...props\n}: NewsletterProps) {\n  const reduced = useReducedMotion() ?? false;\n  const ref = useRef<HTMLElement>(null);\n\n  // Pointer position as -1..1 across the panel, smoothed; the portraits and\n  // the spotlight read it.\n  const mx = useMotionValue(0);\n  const my = useMotionValue(0);\n  const sx = useSpring(mx, { stiffness: 60, damping: 18, mass: 0.6 });\n  const sy = useSpring(my, { stiffness: 60, damping: 18, mass: 0.6 });\n  const glowX = useTransform(sx, [-1, 1], [\"0%\", \"100%\"]);\n  const glowY = useTransform(sy, [-1, 1], [\"0%\", \"100%\"]);\n  const glow = useTransform(\n    [glowX, glowY],\n    ([x, y]) =>\n      `radial-gradient(420px circle at ${x} ${y}, color-mix(in oklab, var(--primary) 22%, transparent), transparent 70%)`,\n  );\n\n  const onMove = (e: React.MouseEvent<HTMLElement>) => {\n    const r = e.currentTarget.getBoundingClientRect();\n    mx.set(((e.clientX - r.left) / r.width) * 2 - 1);\n    my.set(((e.clientY - r.top) / r.height) * 2 - 1);\n  };\n  const onLeave = () => {\n    mx.set(0);\n    my.set(0);\n  };\n\n  const all = React.Children.toArray(children);\n  const issues = all.filter((c) => isPart(c, Issues));\n  const ticker = all.filter((c) => isPart(c, Ticker));\n  const body = all.filter((c) => !isPart(c, Issues) && !isPart(c, Ticker));\n\n  const container: Variants = {\n    hidden: {},\n    visible: { transition: { staggerChildren: reduced ? 0 : 0.11, delayChildren: reduced ? 0 : 0.05 } },\n  };\n  const revealProps =\n    reveal === \"immediate\"\n      ? { initial: \"hidden\" as const, animate: \"visible\" as const }\n      : { initial: \"hidden\" as const, whileInView: \"visible\" as const, viewport: { once: true, amount: 0.3 } };\n\n  const spotlight = variant === \"spotlight\";\n\n  return (\n    <NewsletterContext.Provider value={{ variant, reveal, reduced }}>\n      <section\n        ref={ref}\n        onMouseMove={onMove}\n        onMouseLeave={onLeave}\n        className={cn(\n          \"relative isolate w-full overflow-hidden text-foreground\",\n          // Every layout follows the site's theme: a muted or plain ground by day, the page ground by night.\n          variant === \"issues\" ? \"bg-background\" : \"bg-muted dark:bg-background\",\n          className,\n        )}\n        style={accent ? ({ ...style, \"--primary\": accent } as React.CSSProperties) : style}\n        {...props}\n      >\n      <motion.div className=\"relative\" variants={container} {...revealProps}>\n        {/* Spotlight: a soft disc of the accent that follows the pointer. */}\n        {spotlight && !reduced && (\n          <motion.div aria-hidden className=\"pointer-events-none absolute inset-0 -z-10\" style={{ background: glow }} />\n        )}\n\n        {variant === \"portraits\" &&\n          portraits.slice(0, 4).map((p, i) => {\n            const corner = CORNERS[i];\n            return corner ? <Portrait key={p.src} portrait={p} corner={corner} mx={sx} my={sy} index={i} /> : null;\n          })}\n\n        {variant === \"issues\" ? (\n          <div className=\"mx-auto grid max-w-5xl grid-cols-1 items-center gap-12 px-6 py-14 sm:px-10 sm:py-20 lg:grid-cols-[1.1fr_1fr] lg:gap-16\">\n            <div className=\"flex flex-col items-start\">{body}</div>\n            <div>{issues}</div>\n          </div>\n        ) : (\n          <div className=\"mx-auto flex max-w-xl flex-col items-center px-6 py-16 sm:py-24\">\n            {variant === \"portraits\" && portraits.length > 0 && (\n              <Reveal className=\"mb-6 flex -space-x-3 md:hidden\">\n                {portraits.slice(0, 4).map((p) => (\n                  <img key={p.src} src={p.src} alt={p.alt ?? \"\"} className=\"h-12 w-12 rounded-full object-cover ring-2 ring-muted dark:ring-background\" />\n                ))}\n              </Reveal>\n            )}\n            {body}\n            {ticker}\n          </div>\n        )}\n      </motion.div>\n      </section>\n    </NewsletterContext.Provider>\n  );\n}\n\nNewsletter.Heading = Heading;\nNewsletter.Intro = Intro;\nNewsletter.Form = Form;\nNewsletter.Proof = Proof;\nNewsletter.Ticker = Ticker;\nNewsletter.Issues = Issues;\n\nexport default Newsletter;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/NewsletterBlock.tsx"
    }
  ],
  "docs": "Motion build of `newsletter` — same props, markup and install path; install one or the other. Named export: Newsletter, with parts Heading, Intro, Form, Proof, Ticker and Issues. Composed from the input, button, marquee and tilted-card items, which install alongside it. `variant` is portraits | spotlight | issues, each styled for light and dark mode; `portraits` takes up to four faces; `Form` takes `onSubscribe(email)` (a promise holds the busy state), `action`, `successTitle`/`successText`; `accent` pins the glow and button colour; `reveal` is in-view or immediate.",
  "categories": [
    "marketing",
    "forms"
  ],
  "type": "registry:component"
}
