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

Onboarding

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

Onboarding Checklist

Free

A first-run checklist with a spring progress ring, drawn checkmarks, inline actions per step (validated forms, copyable SDK snippet, a live event listener) and a completion state.

Hide code
components/blocks/onboarding-checklist.tsx
"use client";

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

type StepId = "profile" | "invite" | "install" | "event" | "billing";
const steps: { id: StepId; title: string; body: string; minutes: number }[] = [
  { id: "profile", title: "Name your workspace", body: "This is what teammates and customers see in emails.", minutes: 1 },
  { id: "invite", title: "Invite a teammate", body: "Projects move faster with two people. You can change roles later.", minutes: 1 },
  { id: "install", title: "Install the SDK", body: "Add the package and initialise it once at the root of your app.", minutes: 3 },
  { id: "event", title: "Send your first event", body: "We listen for events from your key and confirm when one arrives.", minutes: 2 },
  { id: "billing", title: "Add a payment method", body: "You won't be charged until your trial ends on Dec 8.", minutes: 1 },
];
const SNIPPETS = [
  { label: "Terminal", code: "pnpm add @northwind/sdk" },
  { label: "app/layout.tsx", code: `import { init } from "@northwind/sdk";\n\ninit({ key: "nw_live_8f2c…" });` },
];

function CodeBlock({ label, code }: { label: string; code: string }) {
  const [copied, setCopied] = useState(false);
  return (
    <div className="relative overflow-hidden rounded-lg border border-border bg-zinc-950 text-zinc-100 shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]">
      <p className="border-b border-white/10 px-3.5 py-1.5 font-mono text-[10px] text-zinc-400">{label}</p>
      <pre className="overflow-x-auto p-3.5 pr-12 font-mono text-[12px] leading-relaxed"><code>{code}</code></pre>
      <button
        type="button"
        aria-label={copied ? "Copied" : `Copy ${label} snippet`}
        onClick={() => {
          navigator.clipboard?.writeText(code).catch(() => {});
          setCopied(true);
          setTimeout(() => setCopied(false), 1600);
        }}
        className={cn("absolute right-2 top-9 grid size-8 place-items-center rounded-md text-zinc-400 transition-colors hover:bg-white/10 hover:text-white", ring)}
      >
        <AnimatePresence mode="popLayout" initial={false}>
          <motion.span key={String(copied)} initial={{ scale: 0.5, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.5, opacity: 0 }}>
            {copied ? <Check className="size-3.5 text-emerald-400" aria-hidden /> : <Copy className="size-3.5" aria-hidden />}
          </motion.span>
        </AnimatePresence>
      </button>
    </div>
  );
}
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));

const ring = "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";
const input = "h-9 w-full min-w-0 rounded-md border border-input bg-background px-3 text-[13px] shadow-[inset_0_1px_2px_rgb(0_0_0/0.06)] outline-none transition-[border-color,box-shadow] placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/25 aria-[invalid=true]:border-red-500 aria-[invalid=true]:ring-red-500/20";
const primary = cn("inline-flex h-9 shrink-0 items-center justify-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.24)] transition-[background-color,scale] hover:bg-foreground/90 active:scale-[0.98] disabled:pointer-events-none disabled:opacity-60", ring);

function ProgressRing({ value }: { value: number }) {
  const reduce = useReducedMotion();
  const r = 20;
  const c = 2 * Math.PI * r;
  return (
    <div className="relative size-12 shrink-0">
      <svg viewBox="0 0 48 48" className="size-12 -rotate-90" aria-hidden>
        <circle cx="24" cy="24" r={r} className="fill-none stroke-muted" strokeWidth="4" />
        <motion.circle
          cx="24"
          cy="24"
          r={r}
          className="fill-none stroke-foreground"
          strokeWidth="4"
          strokeLinecap="round"
          strokeDasharray={c}
          initial={false}
          animate={{ strokeDashoffset: c * (1 - value) }}
          transition={reduce ? { duration: 0 } : { type: "spring", stiffness: 90, damping: 18 }}
        />
      </svg>
      <span className="absolute inset-0 grid place-items-center text-[11px] font-semibold tabular-nums">{Math.round(value * 100)}%</span>
    </div>
  );
}

function Tick({ done }: { done: boolean }) {
  const reduce = useReducedMotion();
  return (
    <span
      className={cn(
        "grid size-5 shrink-0 place-items-center rounded-full border transition-[background-color,border-color,box-shadow] duration-300",
        done ? "border-emerald-500 bg-emerald-500 text-white shadow-[0_0_0_4px_rgb(16_185_129/0.14)]" : "border-dashed border-muted-foreground/50",
      )}
    >
      <svg viewBox="0 0 16 16" className="size-3" aria-hidden>
        <motion.path
          d="M3.5 8.5l3 3 6-7"
          fill="none"
          stroke="currentColor"
          strokeWidth="2.2"
          strokeLinecap="round"
          strokeLinejoin="round"
          initial={false}
          animate={{ pathLength: done ? 1 : 0, opacity: done ? 1 : 0 }}
          transition={reduce ? { duration: 0 } : { duration: 0.32, ease: "easeOut", delay: 0.08 }}
        />
      </svg>
    </span>
  );
}

function StepBody({ id, onDone }: { id: StepId; onDone: () => void }) {
  const [value, setValue] = useState("");
  const [error, setError] = useState<string>();
  const [busy, setBusy] = useState(false);
  const [listening, setListening] = useState(false);

  async function submit(e: React.FormEvent) {
    e.preventDefault();
    if (id === "profile" && value.trim().length < 2) return setError("Use at least 2 characters.");
    if (id === "invite" && !EMAIL.test(value)) return setError("Enter a valid email address.");
    setError(undefined);
    setBusy(true);
    await wait(700);
    setBusy(false);
    onDone();
  }

  if (id === "install")
    return (
      <div className="space-y-3">
        {SNIPPETS.map((snip) => <CodeBlock key={snip.label} {...snip} />)}
        <button type="button" className={primary} onClick={onDone}>I&apos;ve installed it</button>
      </div>
    );

  if (id === "event")
    return (
      <div className="flex flex-wrap items-center gap-3">
        <div className="flex min-w-0 flex-1 items-center gap-2.5 rounded-md border border-dashed border-border px-3 py-2 text-[13px] text-muted-foreground">
          <span className="relative flex size-2.5">
            {listening ? <span className="absolute inset-0 animate-ping rounded-full bg-amber-500/60 motion-reduce:hidden" /> : null}
            <span className={cn("relative size-2.5 rounded-full", listening ? "bg-amber-500" : "bg-muted-foreground/40")} />
          </span>
          <span aria-live="polite">{listening ? "Listening for events on nw_live_8f2c…" : "Not listening yet"}</span>
        </div>
        <button
          type="button"
          className={primary}
          disabled={listening}
          onClick={async () => {
            setListening(true);
            await wait(1800);
            setListening(false);
            onDone();
          }}
        >
          {listening ? <Loader2 className="size-3.5 animate-spin" aria-hidden /> : <Radio className="size-3.5" aria-hidden />}
          Send test event
        </button>
      </div>
    );

  if (id === "billing")
    return (
      <button type="button" className={primary} onClick={async () => { setBusy(true); await wait(800); setBusy(false); onDone(); }} disabled={busy}>
        {busy ? <Loader2 className="size-3.5 animate-spin" aria-hidden /> : null}
        Add card with Stripe
      </button>
    );

  const field = id === "profile" ? { label: "Workspace name", placeholder: "Acme Inc.", type: "text" } : { label: "Teammate's email", placeholder: "sam@acme.io", type: "email" };
  return (
    <form onSubmit={submit} noValidate>
      <label htmlFor={`ob-${id}`} className="sr-only">{field.label}</label>
      <div className="flex gap-2">
        <input
          id={`ob-${id}`}
          type={field.type}
          value={value}
          placeholder={field.placeholder}
          onChange={(e) => (setValue(e.target.value), error && setError(undefined))}
          aria-invalid={!!error}
          aria-describedby={error ? `ob-${id}-err` : undefined}
          className={input}
        />
        <button type="submit" className={primary} disabled={busy}>
          {busy ? <Loader2 className="size-3.5 animate-spin" aria-hidden /> : null}
          {id === "profile" ? "Save" : "Send invite"}
        </button>
      </div>
      <AnimatePresence>
        {error ? (
          <motion.p id={`ob-${id}-err`} initial={{ opacity: 0, height: 0 }} animate={{ opacity: 1, height: "auto" }} exit={{ opacity: 0, height: 0 }} className="pt-1.5 text-xs text-red-600 dark:text-red-400">
            {error}
          </motion.p>
        ) : null}
      </AnimatePresence>
    </form>
  );
}

export default function OnboardingChecklistBlock() {
  const reduce = useReducedMotion();
  const [done, setDone] = useState<Set<StepId>>(new Set());
  const [open, setOpen] = useState<StepId | null>("profile");
  const [hidden, setHidden] = useState(false);
  const headRefs = useRef<Partial<Record<StepId, HTMLButtonElement | null>>>({});
  const progress = done.size / steps.length;
  const left = steps.filter((s) => !done.has(s.id)).reduce((n, s) => n + s.minutes, 0);
  const complete = done.size === steps.length;

  const finish = (id: StepId) => {
    const next = new Set(done).add(id);
    setDone(next);
    const upcoming = steps.find((s) => !next.has(s.id));
    setOpen(upcoming?.id ?? null);
    if (upcoming) requestAnimationFrame(() => headRefs.current[upcoming.id]?.focus());
  };


  return (
    <section className="flex min-h-full w-full items-start justify-center bg-muted/40 px-4 py-10 sm:py-14">
      <AnimatePresence mode="wait">
        {hidden ? (
          <motion.div key="hidden" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} className="mt-20 flex flex-col items-center gap-3 text-sm text-muted-foreground">
            <p>{complete ? "Checklist dismissed." : "Checklist hidden. Your progress is saved."}</p>
            <button type="button" onClick={() => setHidden(false)} className={cn("rounded-md border border-border bg-background px-3 py-1.5 text-[13px] font-medium text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05)] hover:bg-muted", ring)}>
              Show checklist
            </button>
          </motion.div>
        ) : (
          <motion.div
            key="card"
            layout={!reduce}
            initial={{ opacity: 0, y: 8 }}
            animate={{ opacity: 1, y: 0 }}
            exit={{ opacity: 0, y: -8, scale: 0.98 }}
            className="w-full max-w-lg overflow-hidden rounded-xl border border-border bg-card shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.05),0_24px_48px_-28px_rgb(0_0_0/0.35)]"
          >
            <div className="flex items-center gap-4 border-b border-border p-5">
              <ProgressRing value={progress} />
              <div className="min-w-0 flex-1">
                <h2 className="text-[15px] font-semibold tracking-tight">{complete ? "You're all set" : "Get set up"}</h2>
                <p className="text-[13px] text-muted-foreground" aria-live="polite">
                  {complete ? "Every step is done. Nice work." : `${done.size} of ${steps.length} done · about ${left} min left`}
                </p>
              </div>
              <button type="button" onClick={() => setHidden(true)} className={cn("rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground", ring)}>
                {complete ? "Dismiss" : "Skip for now"}
              </button>
            </div>

            <AnimatePresence initial={false}>
              {complete ? (
                <motion.div
                  key="complete"
                  initial={{ opacity: 0, height: 0 }}
                  animate={{ opacity: 1, height: "auto" }}
                  className="relative overflow-hidden border-b border-border bg-emerald-500/[0.06]"
                >
                  <div className="flex items-center gap-3 p-5 text-[13px]">
                    <motion.span initial={reduce ? false : { scale: 0, rotate: -30 }} animate={{ scale: 1, rotate: 0 }} transition={{ type: "spring", stiffness: 300, damping: 14 }} className="grid size-8 place-items-center rounded-md bg-emerald-500 text-white shadow-[0_6px_16px_-6px_rgb(16_185_129/0.8)]">
                      <Sparkles className="size-4" aria-hidden />
                    </motion.span>
                    Your first event is live. Open the dashboard to see it.
                  </div>
                </motion.div>
              ) : null}
            </AnimatePresence>

            <ol>
              {steps.map((s, i) => {
                const isDone = done.has(s.id);
                const isOpen = open === s.id;
                return (
                  <li key={s.id} className="border-b border-border/70 last:border-0">
                    <h3>
                      <button
                        ref={(el) => {
                          headRefs.current[s.id] = el;
                        }}
                        type="button"
                        aria-expanded={isOpen}
                        aria-controls={`ob-panel-${s.id}`}
                        onClick={() => setOpen(isOpen ? null : s.id)}
                        className={cn("flex w-full items-center gap-3 px-5 py-3.5 text-left transition-colors hover:bg-muted/40", ring, "focus-visible:ring-inset focus-visible:ring-offset-0")}
                      >
                        <Tick done={isDone} />
                        <span className={cn("flex-1 text-[13px] font-medium transition-colors", isDone && "text-muted-foreground line-through decoration-muted-foreground/40")}>
                          <span className="sr-only">Step {i + 1}{isDone ? ", done" : ""}: </span>
                          {s.title}
                        </span>
                        {!isDone ? <span className="font-mono text-[10px] text-muted-foreground">{s.minutes} min</span> : null}
                        <ChevronDown className={cn("size-4 text-muted-foreground transition-transform duration-200", isOpen && "rotate-180")} aria-hidden />
                      </button>
                    </h3>
                    <AnimatePresence initial={false}>
                      {isOpen ? (
                        <motion.div
                          id={`ob-panel-${s.id}`}
                          key="panel"
                          initial={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}
                          animate={reduce ? { opacity: 1 } : { height: "auto", opacity: 1 }}
                          exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}
                          transition={{ duration: 0.24, ease: [0.22, 1, 0.36, 1] }}
                          className="overflow-hidden"
                        >
                          <div className="space-y-3 px-5 pb-4 pl-13">
                            <p className="text-[13px] text-muted-foreground">{s.body}</p>
                            {isDone ? (
                              <p className="flex items-center gap-1.5 text-[13px] text-emerald-700 dark:text-emerald-400"><Check className="size-3.5" aria-hidden /> Done</p>
                            ) : (
                              <StepBody id={s.id} onDone={() => finish(s.id)} />
                            )}
                          </div>
                        </motion.div>
                      ) : null}
                    </AnimatePresence>
                  </li>
                );
              })}
            </ol>
          </motion.div>
        )}
      </AnimatePresence>
    </section>
  );
}

Setup Wizard

Pro

A four-step setup: one question a screen, a segmented progress bar, steps that slide in from the side you are moving toward, validation only where it matters, and a finish that reflects the answers.

The source for this block is part of Truffle Pro.