{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swarm-demo",
  "type": "registry:block",
  "title": "Swarm: Product Tabs",
  "description": "Particle Text Animation example, Product Tabs: Three product names on tabs; each one reroutes the same dots into the next word. A take on the particle effect (particles) and text animation (text effect). Fits hero, about, preloader and 404 page sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "hero",
    "about",
    "preloader",
    "404-page",
    "particle-effect",
    "text-animation",
    "text",
    "canvas"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/swarm#swarm-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/swarm.json"
  ],
  "files": [
    {
      "path": "components/swarm-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Swarm } from \"@/components/ui/swarm\";\n\n// Each product has its own pair of colors; the dots blend from the first to the second across the stage.\nconst PRODUCTS = [\n  {\n    id: \"ingest\",\n    word: \"ingest\",\n    line: \"Pulls events from forty sources into one stream.\",\n    from: \"text-[#ff5a1f] dark:text-[#ff7a45]\",\n    to: \"text-[#ff2d87] dark:text-[#ff5ca8]\",\n    swatch: \"bg-[#ff5a1f] dark:bg-[#ff7a45]\",\n  },\n  {\n    id: \"route\",\n    word: \"route\",\n    line: \"Hands every event to whichever model is free.\",\n    from: \"text-[#7c3aed] dark:text-[#a78bfa]\",\n    to: \"text-[#00a3ff] dark:text-[#38bdf8]\",\n    swatch: \"bg-[#7c3aed] dark:bg-[#a78bfa]\",\n  },\n  {\n    id: \"serve\",\n    word: \"serve\",\n    line: \"Answers from the nearest of nine regions.\",\n    from: \"text-[#00b25d] dark:text-[#34d399]\",\n    to: \"text-[#f59e0b] dark:text-[#fbbf24]\",\n    swatch: \"bg-[#00b25d] dark:bg-[#34d399]\",\n  },\n];\n\n// Seconds a settled word holds before the next one, until the visitor picks one.\nconst HOLD = 2.4;\n\nexport function SwarmDemo() {\n  const [index, setIndex] = React.useState(0);\n  const [picked, setPicked] = React.useState(false);\n  const timer = React.useRef(0);\n  const tabs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const product = PRODUCTS[index];\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  // Once every dot has landed, wait a beat and move on, unless the visitor has taken over.\n  const onSettle = React.useCallback(() => {\n    window.clearTimeout(timer.current);\n    if (picked || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    timer.current = window.setTimeout(() => setIndex((i) => (i + 1) % PRODUCTS.length), HOLD * 1000);\n  }, [picked]);\n\n  const pick = (i: number) => {\n    window.clearTimeout(timer.current);\n    setPicked(true);\n    setIndex(i);\n  };\n\n  const onKeyDown = (event: React.KeyboardEvent) => {\n    const step = event.key === \"ArrowRight\" ? 1 : event.key === \"ArrowLeft\" ? -1 : 0;\n    if (!step) return;\n    event.preventDefault();\n    const next = (index + step + PRODUCTS.length) % PRODUCTS.length;\n    pick(next);\n    tabs.current[next]?.focus();\n  };\n\n  return (\n    <div className=\"w-full max-w-3xl overflow-hidden rounded-2xl border border-zinc-950/10 bg-white text-zinc-950 dark:border-white/10 dark:bg-zinc-950 dark:text-white\">\n      <div className=\"flex items-center justify-between gap-4 px-5 py-3.5 font-mono text-[11px] tracking-wide text-zinc-500 uppercase dark:text-zinc-400\">\n        <span className=\"flex items-center gap-2 text-zinc-950 dark:text-white\">\n          <span aria-hidden className={`size-2 transition-colors duration-300 ${product.swatch}`} />\n          Kestrel\n        </span>\n        <span aria-hidden>[ 0{index + 1} / 0{PRODUCTS.length} ]</span>\n      </div>\n\n      <Swarm\n        id=\"swarm-demo-panel\"\n        role=\"tabpanel\"\n        aria-labelledby={`swarm-demo-tab-${product.id}`}\n        text={product.word}\n        label={product.word}\n        dotClassName={product.from}\n        gradientClassName={product.to}\n        onSettle={onSettle}\n        className=\"aspect-[4/3] border-y border-zinc-950/10 bg-zinc-100/70 sm:aspect-[16/8] dark:border-white/10 dark:bg-white/[0.03]\"\n      >\n        {/* Registration marks: two corner ticks and two squares, the way a proof sheet is marked. */}\n        <span aria-hidden className=\"absolute top-3 left-3 size-3 border-t border-l border-zinc-400 dark:border-zinc-600\" />\n        <span aria-hidden className=\"absolute right-3 bottom-3 size-3 border-r border-b border-zinc-400 dark:border-zinc-600\" />\n        <span aria-hidden className=\"absolute top-[18%] right-[9%] size-2 border border-zinc-400 dark:border-zinc-600\" />\n        <span aria-hidden className={`absolute bottom-[16%] left-[8%] size-2 transition-colors duration-300 ${product.swatch}`} />\n      </Swarm>\n\n      <div className=\"flex flex-col gap-4 px-5 py-4 sm:flex-row sm:items-center sm:justify-between\">\n        <p aria-live=\"polite\" className=\"font-mono text-xs leading-relaxed text-zinc-600 dark:text-zinc-400\">\n          {product.line}\n        </p>\n        <div role=\"tablist\" aria-label=\"Kestrel products\" onKeyDown={onKeyDown} className=\"flex shrink-0 gap-1\">\n          {PRODUCTS.map((p, i) => (\n            <button\n              key={p.id}\n              ref={(el) => {\n                tabs.current[i] = el;\n              }}\n              id={`swarm-demo-tab-${p.id}`}\n              type=\"button\"\n              role=\"tab\"\n              aria-selected={i === index}\n              aria-controls=\"swarm-demo-panel\"\n              tabIndex={i === index ? 0 : -1}\n              onClick={() => pick(i)}\n              className=\"flex items-center gap-1.5 rounded-full px-3.5 py-1.5 font-mono text-xs text-zinc-500 transition-colors hover:text-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 aria-selected:bg-zinc-950 aria-selected:text-white dark:text-zinc-400 dark:hover:text-white dark:focus-visible:outline-white dark:aria-selected:bg-white dark:aria-selected:text-zinc-950\"\n            >\n              <span aria-hidden className={`size-1.5 rounded-full ${p.swatch}`} />\n              {p.word}\n            </button>\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}