Pages
CTA
CTA Section
A waitlist or newsletter call to action for React with a working form: email validation, loading spinner, success state and error handling.
cta-section.preview
Install
Copies the source into components/blocks/cta-section.tsx and installs what it needs.
$ pnpm dlx shadcn@latest add https://makeui.xyz/r/cta-section.jsonUsage
app/page.tsx
import { CtaSection } from "@/components/blocks/cta-section"
export default function Page() {
return (
<CtaSection
title="Get new components the day they ship"
onSubmit={async (email) => {
const res = await fetch("/api/subscribe", { method: "POST", body: JSON.stringify({ email }) })
if (!res.ok) throw new Error("Couldn't subscribe. Try again.")
}}
/>
)
}Source
Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.
components/blocks/cta-section.tsx
"use client"
import { useState } from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { ArrowRight, Check, Loader2 } from "lucide-react"
import { cn } from "@/lib/utils"
type Props = {
badge?: string
title?: string
description?: string
placeholder?: string
buttonLabel?: string
successTitle?: string
successMessage?: string
/** Called with the email. Return a promise: the button shows a spinner until it settles, and a thrown error is shown under the field. */
onSubmit?: (email: string) => Promise<unknown> | unknown
/** Short reassurance points under the form. */
perks?: string[]
/** Line next to the avatar stack. Pass an empty string to hide the row. */
proof?: string
className?: string
}
type State = "idle" | "loading" | "success"
const emailOk = (v: string) => /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(v.trim())
const avatars = ["bg-amber-300", "bg-sky-300", "bg-rose-300", "bg-emerald-300", "bg-violet-300"]
/**
* Waitlist / newsletter call to action. A real form: validates the address, shows a spinner while your
* handler runs, then swaps to a confirmation (or shows the error you threw). Keyboard and screen reader friendly.
*/
export function CtaSection({
badge = "Early access",
title = "Get new components the day they ship",
description = "One short email when something new lands: a component, a page section, a micro-interaction. Nothing else.",
placeholder = "you@company.com",
buttonLabel = "Join the list",
successTitle = "You're on the list",
successMessage = "Check your inbox to confirm. The first drop is on its way.",
onSubmit,
perks = ["Free forever", "One email a week", "Unsubscribe anytime"],
proof = "Joined by 2,400+ developers",
className,
}: Props) {
const reduce = useReducedMotion()
const [email, setEmail] = useState("")
const [state, setState] = useState<State>("idle")
const [error, setError] = useState("")
async function submit(e: React.FormEvent) {
e.preventDefault()
if (state === "loading") return
if (!emailOk(email)) {
setError("Enter a valid email address, like you@company.com")
return
}
setError("")
setState("loading")
try {
await onSubmit?.(email.trim())
setState("success")
} catch (err) {
setState("idle")
setError(err instanceof Error ? err.message : "Something went wrong. Try again in a moment.")
}
}
function reset() {
setEmail("")
setState("idle")
}
return (
<div className="@container">
<section className={cn("bg-white px-6 py-20 dark:bg-neutral-950 @2xl:py-28", className)}>
<div className="relative isolate mx-auto max-w-4xl overflow-hidden rounded-[2rem] border border-neutral-800 bg-neutral-900 px-6 py-14 text-center @2xl:px-16 @2xl:py-20">
<div
aria-hidden
className="absolute inset-0 -z-10 bg-[linear-gradient(rgb(255_255_255/0.045)_1px,transparent_1px),linear-gradient(90deg,rgb(255_255_255/0.045)_1px,transparent_1px)] [background-size:44px_44px] [mask-image:radial-gradient(70%_70%_at_50%_30%,black,transparent)]"
/>
<motion.div
aria-hidden
className="absolute left-1/2 top-0 -z-10 h-72 w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-indigo-500/35 blur-[90px]"
animate={reduce ? undefined : { x: [-60, 60, -60], scale: [1, 1.15, 1] }}
transition={{ duration: 12, repeat: Infinity, ease: "easeInOut" }}
/>
{badge && (
<span className="inline-flex items-center gap-2 rounded-full bg-white/10 px-3 py-1 text-xs text-neutral-300 ring-1 ring-white/10">
<span className="size-1.5 rounded-full bg-emerald-400" />
{badge}
</span>
)}
<h2 className="mx-auto mt-6 max-w-xl text-balance text-4xl font-medium leading-[1.08] tracking-[-0.035em] text-white @2xl:text-5xl">
{title}
</h2>
<p className="mx-auto mt-4 max-w-md text-pretty text-base leading-relaxed text-neutral-400">{description}</p>
<div className="mx-auto mt-9 min-h-[4.75rem] max-w-md">
<AnimatePresence mode="wait" initial={false}>
{state === "success" ? (
<motion.div
key="done"
role="status"
initial={reduce ? false : { opacity: 0, y: 10, filter: "blur(4px)" }}
animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
exit={{ opacity: 0 }}
transition={{ type: "spring", stiffness: 260, damping: 26 }}
className="flex flex-col items-center gap-2"
>
<motion.span
initial={reduce ? false : { scale: 0 }}
animate={{ scale: 1 }}
transition={{ type: "spring", stiffness: 420, damping: 18, delay: 0.1 }}
className="grid size-11 place-items-center rounded-full bg-emerald-500 text-white"
>
<Check className="size-5" strokeWidth={3} />
</motion.span>
<p className="mt-1 text-lg font-medium text-white">{successTitle}</p>
<p className="text-sm text-neutral-400">{successMessage}</p>
<button
type="button"
onClick={reset}
className="mt-1 text-sm text-neutral-400 underline underline-offset-4 outline-none transition-colors hover:text-white focus-visible:text-white"
>
Use another email
</button>
</motion.div>
) : (
<motion.form
key="form"
onSubmit={submit}
noValidate
initial={reduce ? false : { opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
>
<div
className={cn(
"flex items-center gap-2 rounded-full bg-black/30 p-1.5 pl-5 ring-1 transition-shadow focus-within:ring-2",
error ? "ring-rose-400/70 focus-within:ring-rose-400" : "ring-white/10 focus-within:ring-white/40"
)}
>
<input
type="email"
inputMode="email"
autoComplete="email"
value={email}
onChange={(e) => {
setEmail(e.target.value)
if (error) setError("")
}}
placeholder={placeholder}
aria-label="Email address"
aria-invalid={!!error}
aria-describedby="cta-error"
disabled={state === "loading"}
className="min-w-0 flex-1 bg-transparent text-[15px] text-white outline-none placeholder:text-neutral-500"
/>
<button
type="submit"
disabled={state === "loading"}
className="group inline-flex h-10 shrink-0 items-center gap-2 rounded-full bg-white px-5 text-sm font-medium text-neutral-900 outline-none transition-transform focus-visible:ring-2 focus-visible:ring-white/60 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-900 active:scale-[0.97] disabled:opacity-70"
>
{state === "loading" ? (
<Loader2 className="size-4 animate-spin" />
) : (
<>
{buttonLabel}
<ArrowRight className="size-4 transition-transform group-hover:translate-x-0.5" />
</>
)}
</button>
</div>
<p id="cta-error" role="alert" className="mt-2 min-h-5 text-left text-sm text-rose-300 pl-5">
{error}
</p>
</motion.form>
)}
</AnimatePresence>
</div>
{perks.length > 0 && (
<ul className="mt-5 flex flex-wrap items-center justify-center gap-x-5 gap-y-2 text-sm text-neutral-400">
{perks.map((p) => (
<li key={p} className="inline-flex items-center gap-1.5">
<Check className="size-3.5 text-emerald-400" strokeWidth={3} />
{p}
</li>
))}
</ul>
)}
{proof && (
<div className="mt-8 flex items-center justify-center gap-3 text-sm text-neutral-400">
<div className="flex -space-x-2" aria-hidden>
{avatars.map((c) => (
<span key={c} className={cn("size-7 rounded-full ring-2 ring-neutral-900", c)} />
))}
</div>
{proof}
</div>
)}
</div>
</section>
</div>
)
}