Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Email signups

2 examples. Resize any preview to see it at phone and tablet widths.

Waitlist

Free

An email capture with inline validation, a shake on bad or duplicate emails, a spring success card with your place in line and a copyable referral link, and a live count.

Hide code
components/blocks/waitlist.tsx
"use client";

import { useRef, useState } from "react";
import { AnimatePresence, motion, useAnimate, useReducedMotion } from "motion/react";
import { ArrowRight, Check, Copy, Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";

const TAKEN = new Set(["hello@acme.com", "founder@northwind.dev"]);
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
const ring = "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";
const faces = ["AK", "MR", "JL", "SO", "TP"];

export default function WaitlistBlock() {
  const reduce = useReducedMotion();
  const [scope, animate] = useAnimate();
  const [email, setEmail] = useState("");
  const [error, setError] = useState<string | null>(null);
  const [state, setState] = useState<"idle" | "loading" | "joined">("idle");
  const [position, setPosition] = useState(0);
  const [count, setCount] = useState(2841);
  const [copied, setCopied] = useState(false);
  const inputRef = useRef<HTMLInputElement>(null);
  const [code, setCode] = useState("");
  const [joined, setJoined] = useState<Set<string>>(new Set());

  function fail(msg: string) {
    setError(msg);
    inputRef.current?.focus();
    if (!reduce) animate(scope.current, { x: [0, -7, 6, -4, 2, 0] }, { duration: 0.38 });
  }

  function submit(e: React.FormEvent) {
    e.preventDefault();
    const v = email.trim().toLowerCase();
    if (!v) return fail("Enter your email to join.");
    if (!EMAIL.test(v)) return fail("That email doesn't look right.");
    if (TAKEN.has(v) || joined.has(v)) return fail("You're already on the list. Check your inbox for your spot.");
    setError(null);
    setState("loading");
    setTimeout(() => {
      setCode(Math.random().toString(36).slice(2, 8));
      setPosition(count + 1);
      setCount((c) => c + 1);
      setJoined((j) => new Set(j).add(v));
      setState("joined");
    }, 900);
  }

  const link = `northwind.dev/r/${code}`;

  return (
    <section className="max-w-[100vw] relative isolate flex min-h-full w-full items-center justify-center overflow-hidden bg-background px-4 py-20">
      <div aria-hidden className="absolute inset-0 -z-10 bg-[radial-gradient(60%_50%_at_50%_0%,color-mix(in_oklab,var(--foreground)_7%,transparent),transparent)]" />
      <div aria-hidden className="absolute inset-x-0 top-0 -z-10 h-px bg-gradient-to-r from-transparent via-foreground/20 to-transparent" />
      <div className="w-full max-w-md text-center">
        <span className="inline-flex items-center gap-2 rounded-md border border-border bg-card px-2.5 py-1 text-xs font-medium text-muted-foreground shadow-[inset_0_1px_0_rgb(255_255_255/0.05)]">
          <span className="relative flex size-1.5">
            {!reduce ? <span className="absolute inset-0 animate-ping rounded-full bg-emerald-500 opacity-60" /> : null}
            <span className="relative size-1.5 rounded-full bg-emerald-500" />
          </span>
          Private beta · opening in waves
        </span>
        <h2 className="mt-5 text-balance text-3xl font-semibold tracking-tight sm:text-4xl">Analytics that answer before you ask</h2>
        <p className="mx-auto mt-3 max-w-sm text-pretty text-sm text-muted-foreground">Join the waitlist. Invite friends to move up; every signup from your link skips you 50 spots.</p>

        <div className="mt-8">
          <AnimatePresence mode="wait" initial={false}>
            {state !== "joined" ? (
              <motion.form key="form" noValidate onSubmit={submit} exit={{ opacity: 0, y: -8, filter: "blur(4px)" }} transition={{ duration: 0.2 }}>
                <div
                  ref={scope}
                  className={cn(
                    "flex gap-1.5 rounded-lg border bg-card p-1.5 shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.06),0_12px_24px_-16px_rgb(0_0_0/0.35)] transition-[border-color,box-shadow] focus-within:border-foreground/30 focus-within:shadow-[0_0_0_4px_color-mix(in_oklab,var(--foreground)_6%,transparent),0_12px_24px_-16px_rgb(0_0_0/0.35)]",
                    error ? "border-red-500/50" : "border-border",
                  )}
                >
                  <label htmlFor="wl-email" className="sr-only">Email</label>
                  <input
                    ref={inputRef}
                    id="wl-email"
                    type="email"
                    autoComplete="email"
                    placeholder="you@company.com"
                    value={email}
                    aria-invalid={!!error}
                    aria-describedby={error ? "wl-error" : undefined}
                    onChange={(e) => (setEmail(e.target.value), error && setError(null))}
                    className="min-w-0 flex-1 bg-transparent px-2.5 text-sm outline-none placeholder:text-muted-foreground"
                  />
                  <button
                    type="submit"
                    disabled={state === "loading"}
                    className={cn("group inline-flex h-9 shrink-0 items-center gap-1.5 rounded-md bg-foreground px-3.5 text-[13px] font-medium text-background shadow-[inset_0_1px_0_rgb(255_255_255/0.18),0_1px_2px_rgb(0_0_0/0.3)] transition active:scale-[0.97] disabled:opacity-80", ring)}
                  >
                    {state === "loading" ? <Loader2 className="size-3.5 animate-spin" aria-hidden /> : null}
                    {state === "loading" ? "Joining" : "Join waitlist"}
                    {state === "idle" ? <ArrowRight className="size-3.5 transition-transform group-hover:translate-x-0.5" aria-hidden /> : null}
                  </button>
                </div>
                <AnimatePresence>
                  {error ? (
                    <motion.p id="wl-error" role="alert" initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} className="mt-2 text-left text-xs text-red-600 dark:text-red-400">
                      {error}
                    </motion.p>
                  ) : null}
                </AnimatePresence>
              </motion.form>
            ) : (
              <motion.div
                key="joined"
                initial={reduce ? { opacity: 0 } : { opacity: 0, y: 10, scale: 0.98 }}
                animate={{ opacity: 1, y: 0, scale: 1 }}
                transition={{ type: "spring", stiffness: 320, damping: 26 }}
                className="rounded-lg border border-border bg-card p-5 text-left shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.06),0_16px_32px_-20px_rgb(0_0_0/0.4)]"
                role="status"
              >
                <div className="flex items-center gap-3">
                  <motion.span initial={{ scale: 0 }} animate={{ scale: 1 }} transition={{ type: "spring", stiffness: 500, damping: 18, delay: 0.1 }} className="grid size-8 place-items-center rounded-full bg-emerald-500 text-white">
                    <Check className="size-4" strokeWidth={3} aria-hidden />
                  </motion.span>
                  <div>
                    <p className="text-sm font-medium">You&apos;re #{position.toLocaleString()} in line</p>
                    <p className="text-xs text-muted-foreground">Confirmation sent to {email.trim()}</p>
                  </div>
                </div>
                <p className="mt-4 text-xs font-medium text-muted-foreground">Your referral link</p>
                <div className="mt-1.5 flex items-center gap-1.5 rounded-md border border-border bg-muted/50 p-1 pl-2.5">
                  <code className="min-w-0 flex-1 truncate font-mono text-xs">{link}</code>
                  <button
                    type="button"
                    onClick={() => {
                      navigator.clipboard?.writeText(`https://${link}`).catch(() => {});
                      setCopied(true);
                      setTimeout(() => setCopied(false), 1600);
                    }}
                    className={cn("inline-flex h-7 items-center gap-1 rounded bg-background px-2 text-xs font-medium shadow-[0_0_0_1px_var(--border),0_1px_1px_rgb(0_0_0/0.06)]", ring)}
                  >
                    {copied ? <Check className="size-3" aria-hidden /> : <Copy className="size-3" aria-hidden />}
                    {copied ? "Copied" : "Copy"}
                  </button>
                </div>
                <button
                  type="button"
                  onClick={() => (setState("idle"), setEmail(""))}
                  className={cn("mt-4 rounded-sm text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground", ring)}
                >
                  Use a different email
                </button>
              </motion.div>
            )}
          </AnimatePresence>
        </div>

        <div className="mt-6 flex items-center justify-center gap-2.5 text-xs text-muted-foreground">
          <div className="flex -space-x-1" aria-hidden>
            {faces.map((f, i) => (
              <span key={f} className="grid size-6 place-items-center rounded-full bg-muted text-[9px] font-semibold text-foreground/70 ring-2 ring-background" style={{ zIndex: faces.length - i }}>
                {f}
              </span>
            ))}
          </div>
          <span>
            <motion.span key={count} initial={reduce ? false : { y: 6, opacity: 0 }} animate={{ y: 0, opacity: 1 }} className="inline-block font-medium tabular-nums text-foreground">
              {count.toLocaleString()}
            </motion.span>{" "}
            people waiting
          </span>
        </div>
      </div>
    </section>
  );
}

Newsletter Card

Pro

A ruled-paper signup card with a pill field, inline validation and a confirmation that replaces the helper line.

The source for this block is part of Truffle Pro.