# Swarm Hero

> A hero for a GPU network: the headline and two calls to action on the left, and on the right a square stage where dots gather on the frame, fly in on hairline trails and pack into the brand's mark. Point at one of the three numbers under the headline and the same dots rearrange to spell it; leave and they go back to the mark.

A Hero Section block from KeyframeUI: a whole landing-page section built around the Swarm component, free to install as source with the shadcn CLI. Built with React and Tailwind CSS.

- Live preview: https://keyframeui.com/blocks/hero-sections/swarm-hero
- Category: Hero Sections
- Built with: [Swarm](https://keyframeui.com/components/swarm.md)
- npm dependencies: clsx, tailwind-merge

## Installation

Register the @keyframeui registry in `components.json` once per project:

```json
{
  "registries": {
    "@keyframeui": "https://keyframeui.com/r/{name}.json"
  }
}
```

Then add the block. It lands in `components/swarm-hero.tsx`, and the CLI also adds the components it's built with (`components/ui/swarm.tsx`) and `lib/utils.ts`, and installs the npm dependencies:

```bash
npx shadcn@latest add @keyframeui/swarm-hero
```

Or install by URL, without registering the namespace:

```bash
npx shadcn@latest add https://keyframeui.com/r/swarm-hero.json
```

## Usage

Put it where the section goes. The copy, links and data sit in constants at the top of the file; edit them there.

```tsx
import { SwarmHero } from "@/components/swarm-hero";

export default function Page() {
  return <SwarmHero />;
}
```

## Source

```tsx title="components/swarm-hero.tsx"
"use client";

import * as React from "react";

import { Swarm } from "@/components/ui/swarm";

/* ── Content ─────────────────────────────────────────────────
 * Everything you'd change to make the hero yours: the nav, the
 * headline, the two calls to action and the three numbers.
 * The stage sets your mark in dots; pointing at a number (or
 * focusing it) sets that number in the same dots instead.
 * ─────────────────────────────────────────────────────────── */

/** The brand's two colors: the logo, the mark's dots blend from one to the other. Light and dark. */
const ACCENT = { light: "#ff5a1f", dark: "#ff7a45" };
const ACCENT_TO = { light: "#ff2d87", dark: "#ff5ca8" };
/** The mark's dots, as the `text-*` classes the stage reads. */
const MARK_TONES = { from: "text-[#ff5a1f] dark:text-[#ff7a45]", to: "text-[#ff2d87] dark:text-[#ff5ca8]" };

const BRAND = { name: "Covey", href: "#" };
/** Covey's mark: three discs and a smaller one joining them, drawn in a 24 × 24 box. */
const MARK = [disc(6.5, 17.5, 4.5), disc(17.5, 17.5, 4.5), disc(6.5, 6.5, 4.5), disc(18.5, 5.5, 3)].join("");
const NAV_LINKS = [
  { label: "Network", href: "#network" },
  { label: "Pricing", href: "#pricing" },
  { label: "Docs", href: "#docs" },
  { label: "Changelog", href: "#changelog" },
];
const SIGN_IN = { label: "Sign in", href: "#sign-in" };
const NAV_CTA = { label: "Start building", href: "#start" };

const HEADLINE = "Every idle GPU, answering as one.";
const SUBLINE =
  "Covey pools spare GPUs from labs and data centers into a single inference endpoint. You send one request; the nearest free card answers it.";
const PRIMARY = { label: "Start building", href: "#start" };
const SECONDARY = { label: "Pool your GPUs", href: "#pool" };

/**
 * The numbers under the headline. `dots` is what the stage spells while one is pointed at, in the
 * number's own two colors; `label` is its label color, dark enough to read at 11px.
 */
const STATS = [
  {
    id: "gpus",
    label: "GPUs online",
    value: "41,207",
    dots: "41k",
    tones: { from: "text-[#00b25d] dark:text-[#34d399]", to: "text-[#00a3ff] dark:text-[#38bdf8]", label: "text-[#008a48] dark:text-[#34d399]" },
  },
  {
    id: "latency",
    label: "P50 latency",
    value: "38 ms",
    dots: "38ms",
    tones: { from: "text-[#7c3aed] dark:text-[#a78bfa]", to: "text-[#00a3ff] dark:text-[#38bdf8]", label: "text-[#7c3aed] dark:text-[#a78bfa]" },
  },
  {
    id: "price",
    label: "Per 1M tokens",
    value: "$0.18",
    dots: "$0.18",
    tones: { from: "text-[#f59e0b] dark:text-[#fbbf24]", to: "text-[#ff2d87] dark:text-[#ff5ca8]", label: "text-[#b45309] dark:text-[#fbbf24]" },
  },
];

const FIGURE = { caption: "Fig. 01 — The Covey network", status: "Live" };

/** Milliseconds a pointer rests on a number before the stage spells it, and lingers after it leaves. */
const INTENT = { enter: 120, leave: 260 };

/* ── Section ─────────────────────────────────────────────── */

export function SwarmHero() {
  const [active, setActive] = React.useState<string | null>(null);
  const timer = React.useRef(0);
  React.useEffect(() => () => window.clearTimeout(timer.current), []);

  const show = (id: string | null, wait: number) => {
    window.clearTimeout(timer.current);
    timer.current = window.setTimeout(() => setActive(id), wait);
  };
  const stat = STATS.find((s) => s.id === active);
  const tones = stat?.tones ?? MARK_TONES;
  const logoId = React.useId();

  return (
    <section
      style={
        { "--accent": ACCENT.light, "--accent-dark": ACCENT.dark, "--accent-to": ACCENT_TO.light, "--accent-to-dark": ACCENT_TO.dark } as React.CSSProperties
      }
      className="relative overflow-x-clip bg-white text-zinc-950 dark:bg-[#09090b] dark:text-white"
    >
      <header className="mx-auto flex h-16 max-w-6xl items-center justify-between gap-6 px-6">
        <a
          href={BRAND.href}
          className="flex items-center gap-2 rounded-sm text-[15px] font-semibold tracking-tight focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-zinc-950 dark:focus-visible:outline-white"
        >
          <svg viewBox="0 0 24 24" aria-hidden className="size-5">
            <defs>
              <linearGradient id={logoId} x1="0" y1="0" x2="1" y2="1">
                <stop offset="0" className="[stop-color:var(--accent)] dark:[stop-color:var(--accent-dark)]" />
                <stop offset="1" className="[stop-color:var(--accent-to)] dark:[stop-color:var(--accent-to-dark)]" />
              </linearGradient>
            </defs>
            <path d={MARK} fill={`url(#${logoId})`} />
          </svg>
          {BRAND.name}
        </a>
        <nav aria-label="Main" className="hidden items-center gap-7 text-sm text-zinc-600 md:flex dark:text-zinc-400">
          {NAV_LINKS.map((link) => (
            <a
              key={link.label}
              href={link.href}
              className="rounded-sm transition-colors duration-150 hover:text-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-zinc-950 dark:hover:text-white dark:focus-visible:outline-white"
            >
              {link.label}
            </a>
          ))}
        </nav>
        <div className="flex items-center gap-1">
          <a
            href={SIGN_IN.href}
            className="hidden rounded-sm px-3 py-2 font-mono text-xs text-zinc-600 transition-colors duration-150 hover:text-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 sm:block dark:text-zinc-400 dark:hover:text-white dark:focus-visible:outline-white"
          >
            [ {SIGN_IN.label} ]
          </a>
          <a
            href={NAV_CTA.href}
            className="rounded-full bg-zinc-950 px-4 py-2 text-sm font-medium text-white transition-colors duration-150 hover:bg-zinc-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 dark:bg-white dark:text-zinc-950 dark:hover:bg-zinc-200 dark:focus-visible:outline-white"
          >
            {NAV_CTA.label}
          </a>
        </div>
      </header>

      <div className="mx-auto grid max-w-6xl grid-cols-1 items-center gap-x-14 gap-y-10 px-6 pt-8 pb-16 sm:pt-12 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.05fr)] lg:pt-10 lg:pb-20">
        <div className="min-w-0">
          <h1 className="max-w-xl text-[2.6rem] leading-[1.04] font-semibold tracking-[-0.04em] text-balance sm:text-6xl lg:text-[4rem]">
            {HEADLINE}
          </h1>
          <p className="mt-6 max-w-md text-base leading-relaxed text-zinc-600 sm:text-[17px] dark:text-zinc-400">{SUBLINE}</p>
          <div className="mt-8 flex flex-wrap items-center gap-3">
            <a
              href={PRIMARY.href}
              className="rounded-full bg-zinc-950 px-5 py-3 text-sm font-medium text-white transition-colors duration-150 hover:bg-zinc-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 dark:bg-white dark:text-zinc-950 dark:hover:bg-zinc-200 dark:focus-visible:outline-white"
            >
              {PRIMARY.label}
            </a>
            <a
              href={SECONDARY.href}
              className="group rounded-sm px-3 py-3 font-mono text-[13px] whitespace-nowrap text-zinc-700 transition-colors duration-150 hover:text-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 dark:text-zinc-300 dark:hover:text-white dark:focus-visible:outline-white"
            >
              <span aria-hidden>[</span>
              {/* The space after the bracket holds a status dot that lights on hover, the way a node lights when it joins. */}
              <span aria-hidden className="relative inline-block w-[1ch] align-middle">
                <span className="absolute top-1/2 left-1/2 size-1.5 -translate-1/2 rounded-full bg-(--accent) opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-visible:opacity-100 dark:bg-(--accent-dark)" />
              </span>
              {SECONDARY.label}
              <span aria-hidden> ]</span>
            </a>
          </div>

          <dl className="mt-12 grid max-w-lg grid-cols-3 gap-x-7 gap-y-4 border-t border-zinc-950/10 pt-5 dark:border-white/10">
            {STATS.map((s) => (
              <div
                key={s.id}
                tabIndex={0}
                onPointerEnter={(e) => e.pointerType === "mouse" && show(s.id, INTENT.enter)}
                onPointerLeave={(e) => e.pointerType === "mouse" && show(null, INTENT.leave)}
                onClick={() => show(active === s.id ? null : s.id, 0)}
                onFocus={() => show(s.id, 0)}
                onBlur={() => show(null, INTENT.leave)}
                className="-m-2 cursor-default rounded-md p-2 transition-colors duration-150 outline-none hover:bg-zinc-950/[0.03] focus-visible:ring-2 focus-visible:ring-zinc-950 dark:hover:bg-white/[0.04] dark:focus-visible:ring-white"
              >
                <dt className={`font-mono text-[11px] tracking-wide uppercase ${s.tones.label}`}>{s.label}</dt>
                <dd className="mt-1.5 text-xl font-semibold tracking-tight tabular-nums sm:text-2xl">{s.value}</dd>
              </div>
            ))}
          </dl>
        </div>

        <figure className="relative w-full max-w-[34rem] lg:max-w-none">
          <Swarm
            text={stat?.dots}
            path={MARK}
            label={stat ? `${stat.label}: ${stat.value}` : `${BRAND.name} mark`}
            dotSize={6}
            gap={1.5}
            dotClassName={tones.from}
            gradientClassName={tones.to}
            className="aspect-square border border-zinc-950/10 bg-[#f4f4f5] dark:border-white/10 dark:bg-white/[0.03]"
          >
            {/* Registration marks, solid and outlined, set off the grid like a proof sheet. */}
            <span aria-hidden className="absolute top-[7%] left-[7%] size-2.5 bg-(--accent) dark:bg-(--accent-dark)" />
            <span aria-hidden className="absolute top-[11%] right-[12%] size-2.5 border border-zinc-400 dark:border-zinc-600" />
            <span aria-hidden className="absolute right-[5%] bottom-[38%] size-2.5 bg-(--accent-to) dark:bg-(--accent-to-dark)" />
            <span aria-hidden className="absolute bottom-[9%] left-[16%] size-2.5 border border-zinc-400 dark:border-zinc-600" />
          </Swarm>
          <figcaption className="flex items-center justify-between gap-4 border-x border-b border-zinc-950/10 px-4 py-3 font-mono text-[11px] tracking-wide text-zinc-500 uppercase dark:border-white/10 dark:text-zinc-400">
            <span>{FIGURE.caption}</span>
            <span className="flex items-center gap-2 text-zinc-700 dark:text-zinc-300">
              <span aria-hidden className="size-1.5 rounded-full bg-(--accent) dark:bg-(--accent-dark)" />
              {FIGURE.status}
            </span>
          </figcaption>
        </figure>
      </div>
    </section>
  );
}

/** A circle as path data, so the mark stays one `d` string the stage and the logo share. */
function disc(cx: number, cy: number, r: number) {
  return `M${cx} ${cy - r}A${r} ${r} 0 1 1 ${cx} ${cy + r}A${r} ${r} 0 1 1 ${cx} ${cy - r}Z`;
}
```
