Developer hero with typing terminal

A hero for developer tools: a large headline beside one sentence, two actions and a copy-to-clipboard install command, above a wide terminal that types a command and prints its output line by line, then offers a replay. Command, output lines, tones and timings are props. With reduced motion the terminal shows the finished session at once, and screen readers get the full transcript instead of the animation.

Hero sectionsBlockTailwind v4

Source

"use client";

import { useEffect, useState } from "react";
import { ArrowRight, ArrowUpRight, Check, Copy, RotateCcw } from "lucide-react";
import { cn } from "@/lib/utils";

type Action = { label: string; href: string };
export type TerminalLine = { text: string; tone?: "success" | "muted" | "accent" | "plain" };
export type PullRequestCard = {
  number: number;
  title: string;
  branch: string;
  previewUrl: string;
  /** Each check turns green once this many output lines have printed. */
  checks: { label: string; time: string; at: number }[];
};

export type HeroTerminalProps = {
  title?: string;
  description?: string;
  primaryAction?: Action;
  secondaryAction?: Action;
  /** The command shown in the copy chip. */
  installCommand?: string;
  /** The command typed in the terminal. */
  command?: string;
  output?: TerminalLine[];
  /** The pull request card beside the terminal. Pass null to let the terminal take the full width. */
  pullRequest?: PullRequestCard | null;
  /** Milliseconds per typed character. */
  typingSpeed?: number;
  /** Milliseconds between output lines. */
  lineDelay?: number;
  className?: string;
};

const focusRing = "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";

const DEFAULT_OUTPUT: TerminalLine[] = [
  { text: "Reading branchyard.toml", tone: "muted" },
  { text: "✓ Found 3 services: web, api, worker", tone: "success" },
  { text: "✓ Seeded database from snapshot nightly-0412 (2.1 GB)", tone: "success" },
  { text: "✓ Linked repository northvane/atlas", tone: "success" },
  { text: "→ Preview ready at https://pr-482.atlas.branchyard.dev", tone: "accent" },
  { text: "Done in 41s. Run `branchyard logs web` to follow the build.", tone: "muted" },
];

const DEFAULT_PULL_REQUEST: PullRequestCard = {
  number: 482,
  title: "Add CSV export to invoices",
  branch: "feat/invoice-export → main",
  previewUrl: "#preview",
  checks: [
    { label: "Services built", time: "18s", at: 2 },
    { label: "Database seeded", time: "12s", at: 3 },
    { label: "Preview deployed", time: "11s", at: 5 },
  ],
};

const TONES: Record<NonNullable<TerminalLine["tone"]>, string> = {
  success: "text-emerald-400",
  muted: "text-background/55 dark:text-muted-foreground",
  accent: "text-sky-300",
  plain: "text-background dark:text-card-foreground",
};

function useReducedMotion() {
  const [reduced, setReduced] = useState(false);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    setReduced(query.matches);
    const onChange = () => setReduced(query.matches);
    query.addEventListener("change", onChange);
    return () => query.removeEventListener("change", onChange);
  }, []);
  return reduced;
}

export function HeroTerminal({
  title = "Preview every branch before it merges",
  description = "Branchyard builds an isolated copy of your app for each pull request, with its own database and URL, in under a minute.",
  primaryAction = { label: "Get started", href: "#start" },
  secondaryAction = { label: "Read the docs", href: "#docs" },
  installCommand = "npm i -g branchyard",
  command = "npx branchyard up --pr 482",
  output = DEFAULT_OUTPUT,
  pullRequest = DEFAULT_PULL_REQUEST,
  typingSpeed = 45,
  lineDelay = 380,
  className,
}: HeroTerminalProps) {
  const reduced = useReducedMotion();
  const [typed, setTyped] = useState(0);
  const [shown, setShown] = useState(0);
  const [run, setRun] = useState(0);
  const [copied, setCopied] = useState(false);
  const outputKey = output.map((line) => line.text).join("|");

  // Type the command, pause, then print the output one line at a time. Reduced motion jumps to the end.
  useEffect(() => {
    if (reduced) {
      setTyped(command.length);
      setShown(output.length);
      return;
    }
    setTyped(0);
    setShown(0);
    const timers: ReturnType<typeof setTimeout>[] = [];
    const start = 500;
    for (let index = 1; index <= command.length; index++) timers.push(setTimeout(() => setTyped(index), start + index * typingSpeed));
    const typedAt = start + command.length * typingSpeed + 350;
    for (let index = 1; index <= output.length; index++) timers.push(setTimeout(() => setShown(index), typedAt + index * lineDelay));
    return () => timers.forEach(clearTimeout);
    // Keyed on the text, so a new array with the same lines does not restart the animation.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [reduced, command, outputKey, typingSpeed, lineDelay, run]);

  const done = typed >= command.length && shown >= output.length;

  const copy = async () => {
    try {
      await navigator.clipboard.writeText(installCommand);
      setCopied(true);
      setTimeout(() => setCopied(false), 1600);
    } catch {
      setCopied(false);
    }
  };

  return (
    <section aria-labelledby="hero-terminal-title" className={cn("bg-background", className)}>
      <div className="mx-auto max-w-6xl px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="grid gap-8 lg:grid-cols-12 lg:items-end lg:gap-12">
          <h1
            id="hero-terminal-title"
            className="text-balance text-4xl font-semibold leading-[1.02] tracking-[-0.04em] text-foreground sm:text-6xl lg:col-span-7 lg:text-[4.25rem]"
          >
            {title}
          </h1>
          <div className="lg:col-span-5 lg:pb-2">
            <p className="max-w-md text-lg leading-relaxed text-muted-foreground">{description}</p>
            <div className="mt-7 flex flex-wrap items-center gap-3">
              <a
                href={primaryAction.href}
                className={cn("group inline-flex h-11 items-center gap-2 rounded-md bg-primary px-5 text-sm font-medium text-primary-foreground transition-opacity hover:opacity-90", focusRing)}
              >
                {primaryAction.label}
                <ArrowRight className="size-4 motion-safe:transition-transform group-hover:translate-x-0.5" aria-hidden="true" />
              </a>
              <a
                href={secondaryAction.href}
                className={cn("inline-flex h-11 items-center rounded-md px-4 text-sm font-medium text-foreground underline-offset-4 transition-colors hover:bg-accent", focusRing)}
              >
                {secondaryAction.label}
              </a>
            </div>
            <button
              type="button"
              onClick={copy}
              className={cn(
                "mt-5 inline-flex h-10 max-w-full items-center gap-3 rounded-md bg-muted px-3.5 font-mono text-[0.8125rem] text-foreground transition-colors hover:bg-accent",
                focusRing,
              )}
            >
              <span className="truncate"><span className="select-none text-muted-foreground">$ </span>{installCommand}</span>
              {copied ? <Check className="size-4 shrink-0 text-emerald-600 dark:text-emerald-400" aria-hidden="true" /> : <Copy className="size-4 shrink-0 text-muted-foreground" aria-hidden="true" />}
              <span className="sr-only">{copied ? "Copied" : "Copy install command"}</span>
            </button>
            <span role="status" className="sr-only">{copied ? "Install command copied" : ""}</span>
          </div>
        </div>

        <div className={cn("mt-12 grid gap-4 lg:mt-16", pullRequest && "lg:grid-cols-[minmax(0,1.65fr)_minmax(0,1fr)]")}>
          <div data-ui className="overflow-hidden rounded-xl bg-foreground text-background dark:bg-card dark:text-card-foreground dark:ring-1 dark:ring-border">
            <div className="flex h-11 items-center gap-2 px-4">
              <span className="size-3 rounded-full bg-background/20 dark:bg-foreground/15" />
              <span className="size-3 rounded-full bg-background/20 dark:bg-foreground/15" />
              <span className="size-3 rounded-full bg-background/20 dark:bg-foreground/15" />
              <span className="ml-3 truncate text-xs text-background/55 dark:text-muted-foreground">~/atlas — zsh</span>
              <button
                type="button"
                onClick={() => setRun((value) => value + 1)}
                disabled={!done || reduced}
                className="ml-auto inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs text-background/70 transition-colors hover:bg-background/10 hover:text-background disabled:pointer-events-none disabled:opacity-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-background/60 dark:text-muted-foreground dark:hover:bg-foreground/10 dark:hover:text-foreground dark:focus-visible:ring-ring"
              >
                <RotateCcw className="size-3.5" aria-hidden="true" /> Replay
              </button>
            </div>
            <pre aria-hidden="true" className="min-h-[14.5rem] whitespace-pre-wrap break-words px-4 pb-6 pt-1 font-mono text-[0.8125rem] leading-7 sm:px-6 sm:text-sm">
              <code>
                <span className="text-background/55 dark:text-muted-foreground">~/atlas </span>
                <span className="text-emerald-400">❯ </span>
                {command.slice(0, typed)}
                {!done && <span className="ml-px inline-block h-[1.1em] w-[0.55em] translate-y-[0.2em] bg-current motion-safe:animate-pulse" />}
                {output.slice(0, shown).map((line, index) => (
                  <span key={index} className={cn("block", TONES[line.tone ?? "plain"])}>{line.text}</span>
                ))}
              </code>
            </pre>
            <div className="sr-only">
              <p>Terminal session:</p>
              <p>{command}</p>
              {output.map((line, index) => <p key={index}>{line.text}</p>)}
            </div>
          </div>

          {pullRequest && (
            <div data-ui className="flex flex-col rounded-xl bg-muted/60 p-5 text-foreground sm:p-6 dark:bg-muted/30">
              <p className="text-sm text-muted-foreground">Pull request #{pullRequest.number}</p>
              <p className="mt-1 text-lg font-semibold tracking-tight">{pullRequest.title}</p>
              <p className="mt-1 truncate font-mono text-xs text-muted-foreground">{pullRequest.branch}</p>
              <ul className="mt-5 space-y-3" aria-label="Checks">
                {pullRequest.checks.map((check, index) => {
                  const state = shown >= check.at ? "done" : typed >= command.length && (index === 0 || shown >= pullRequest.checks[index - 1].at) ? "running" : "waiting";
                  return (
                    <li key={check.label} className="flex items-center gap-3 text-sm">
                      <span
                        className={cn(
                          "grid size-5 shrink-0 place-items-center rounded-full",
                          state === "done" ? "bg-emerald-500/15 text-emerald-700 dark:text-emerald-300" : "bg-foreground/8 text-muted-foreground",
                        )}
                      >
                        {state === "done" ? <Check className="size-3" aria-hidden="true" /> : state === "running" ? (
                          <span className="size-2 rounded-full bg-current motion-safe:animate-pulse" />
                        ) : <span className="size-1.5 rounded-full bg-current opacity-60" />}
                      </span>
                      <span className={state === "waiting" ? "text-muted-foreground" : "text-foreground"}>{check.label}</span>
                      <span className="ml-auto text-xs text-muted-foreground">{state === "done" ? check.time : state === "running" ? "Running" : "Queued"}</span>
                    </li>
                  );
                })}
              </ul>
              <a
                href={pullRequest.previewUrl}
                aria-disabled={!done || undefined}
                className={cn(
                  "mt-6 inline-flex h-10 items-center justify-center gap-2 rounded-md bg-background px-4 text-sm font-medium text-foreground ring-1 ring-border transition-colors hover:bg-accent sm:mt-auto",
                  !done && "pointer-events-none opacity-50",
                  focusRing,
                )}
              >
                {done ? "Open preview" : "Waiting for preview"}
                {done && <ArrowUpRight className="size-4" aria-hidden="true" />}
              </a>
            </div>
          )}
        </div>
      </div>
    </section>
  );
}