Split Signup CTA
FreeA two-panel call to action with an email field that validates inline and a button that moves through sending and sent without changing size.
Hide codecomponents/blocks/cta-split.tsx
"use client";
import { useId, useState } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { ArrowRight, Check, LoaderCircle } from "lucide-react";
type Status = "idle" | "sending" | "sent";
export default function CtaSplit() {
const id = useId();
const reduce = useReducedMotion();
const [email, setEmail] = useState("");
const [status, setStatus] = useState<Status>("idle");
const [error, setError] = useState("");
function submit(event: React.FormEvent) {
event.preventDefault();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
setError("Enter an email address like name@company.com.");
return;
}
setError("");
setStatus("sending");
// Replace with your own request.
setTimeout(() => setStatus("sent"), 1100);
}
const swap = {
initial: reduce ? { opacity: 0 } : { opacity: 0, y: 6, filter: "blur(4px)" },
animate: { opacity: 1, y: 0, filter: "blur(0px)" },
exit: reduce ? { opacity: 0 } : { opacity: 0, y: -6, filter: "blur(4px)" },
transition: { duration: 0.2, ease: [0.215, 0.61, 0.355, 1] as const },
};
return (
<section className="w-full px-6 py-16 sm:px-10 sm:py-20">
<div className="mx-auto grid max-w-5xl overflow-hidden rounded-2xl border border-border md:grid-cols-[1.1fr_1fr]">
<div className="bg-foreground p-8 text-background sm:p-12">
<p className="font-mono text-xs uppercase tracking-[0.14em] opacity-70">Early access</p>
<h2 className="mt-4 text-balance text-3xl font-semibold tracking-[-0.035em] sm:text-5xl">Be first through the door.</h2>
<p className="mt-4 max-w-sm text-pretty leading-relaxed opacity-80">We open new workspaces every Monday. Leave your address and we will send one invite, then leave you alone.</p>
</div>
<form onSubmit={submit} noValidate className="flex flex-col justify-center bg-card p-8 sm:p-12">
<label htmlFor={id} className="text-sm font-medium">Work email</label>
<input
id={id}
type="email"
inputMode="email"
autoComplete="email"
value={email}
onChange={(event) => { setEmail(event.target.value); setError(""); }}
disabled={status !== "idle"}
aria-invalid={error ? true : undefined}
aria-describedby={`${id}-help`}
placeholder="you@company.com"
className="mt-2 h-12 w-full rounded-lg border border-border bg-background px-4 text-base outline-none transition-[border-color,box-shadow] duration-150 placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-4 focus-visible:ring-ring/20 disabled:opacity-60 aria-invalid:border-destructive"
/>
{/* The helper line keeps its height whether it shows help, an error or nothing. */}
<p id={`${id}-help`} role={error ? "alert" : undefined} className={`mt-2 min-h-5 text-sm ${error ? "text-destructive" : "text-muted-foreground"}`}>
{error || "No newsletter. One email when your seat is ready."}
</p>
<button
type="submit"
disabled={status !== "idle"}
className="mt-4 inline-flex h-12 items-center justify-center overflow-hidden rounded-lg bg-foreground px-5 text-sm font-medium text-background outline-none transition-[background-color,scale] duration-150 hover:bg-foreground/90 enabled:active:scale-[0.96] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card disabled:cursor-default motion-reduce:transition-none"
>
<AnimatePresence mode="wait" initial={false}>
{status === "idle" ? (
<motion.span key="idle" {...swap} className="inline-flex items-center gap-2">Request an invite <ArrowRight className="size-4" aria-hidden /></motion.span>
) : status === "sending" ? (
<motion.span key="sending" {...swap} className="inline-flex items-center gap-2"><LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden /> Sending</motion.span>
) : (
<motion.span key="sent" {...swap} className="inline-flex items-center gap-2"><Check className="size-4" aria-hidden /> You are on the list</motion.span>
)}
</AnimatePresence>
</button>
<p role="status" className="sr-only">{status === "sent" ? `Invite requested for ${email}.` : ""}</p>
</form>
</div>
</section>
);
}