{"slug":"border-beam","category":"effects","job":"ask","added":"2026-11-10T20:47Z","title":"Border Beam","description":"A soft multicolor glow that rides the border of an AI composer or search field, lapping faster and brighter while the AI works.","url":"https://ai-patterns.app/patterns/effects/border-beam","markdown":"https://ai-patterns.app/patterns/effects/border-beam.md","json":"https://ai-patterns.app/api/patterns/effects/border-beam","seenIn":[{"team":"mongodb","source":"https://jira.mongodb.org/browse/COMPASS-7836"}],"spec":"# Border Beam\n\n## Summary\nA soft, multicolor glow that travels around the border of an AI input surface — a composer, a search field, an \"ask AI\" card. At rest it marks the surface as the place where AI lives; while the AI is working it laps faster and brightens, so the same frame doubles as a quiet activity signal.\n\n## When to use\n- The primary AI composer or command bar, to set it apart from ordinary text fields on the same screen.\n- An AI-powered search field that sits next to a plain one, so people can tell which one reasons.\n- As an ambient \"working\" state on the surface that started a run, when a separate loader would crowd the layout.\n\n## When not to use\n- On more than one or two surfaces per view. A beam on every card turns into noise and stops meaning \"AI\".\n- As the only progress signal for long runs — pair it with a **Thinking Loader** or **Task List** that says what is happening and for how long.\n- On destructive or error states. The playful color reads as success; use **Generation Error** styling instead.\n- On dense lists or table rows, where the motion pulls the eye away from the content.\n\n## Anatomy\n- Wrapped surface: the existing composer or field, unchanged, with its own border and radius.\n- Beam: two short arcs of color, drawn only on the 1px border ring.\n- Glow: a blurred copy of the beam that bleeds a few pixels inward, never outward past the surface.\n\n## Behavior\n- Idle: the beam laps slowly (about 8 s per lap) at reduced opacity.\n- Active (a prompt was sent, the agent is running): the lap halves and the beam and glow brighten; both ease back when the run ends.\n- Disabled: remove the beam when the surface is hidden, read-only or not AI-backed — never leave it looping over a dead control.\n- The beam fades in on mount instead of popping, and never changes the surface's size or layout.\n\n## Content guidelines\n- The beam carries no text. Put state in words elsewhere: the placeholder (\"Building the Thinking Loader…\"), a loader or a status line.\n- Keep colors soft and in the product's palette; two arcs are enough. Avoid red, which reads as an error.\n\n## Accessibility\n- The beam and glow are decorative: `aria-hidden`, `pointer-events: none`, and never the only way state is conveyed.\n- With `prefers-reduced-motion`, stop the rotation and show a static arc; the active state can still brighten.\n- The beam must not lower the contrast of the surface's real border or focus ring — keep a visible focus indicator on the input itself.\n\n## Related patterns\n- **Shiny Button** — The same \"this is special\" signal for a single call to action instead of an input surface.\n- **Prompt Bar** — The composer the beam most often wraps.\n- **Thinking Loader** — Says what the AI is doing and for how long, which the beam alone cannot.\n","code":"\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface BorderBeamProps extends React.HTMLAttributes<HTMLDivElement> {\n  children: React.ReactNode;\n  /** Seconds for one lap of the beam. Halved while `active`. */\n  duration?: number;\n  /** Turn the beam up while the AI is working: faster lap and a brighter glow. */\n  active?: boolean;\n  /** Hide the beam entirely, e.g. once the surface is idle and out of focus. */\n  disabled?: boolean;\n  /** Colors the beam cycles through, as CSS colors. Two soft arcs are drawn from them. */\n  colors?: [string, string, string, string];\n  /** Inner radius of the wrapped surface, matched so the beam hugs its corners. */\n  radius?: number | string;\n}\n\n/** Masks an element down to its padding box: only the ring between border and content shows. */\nconst RING_MASK: React.CSSProperties = {\n  WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n};\n\nconst DEFAULT_COLORS: [string, string, string, string] = [\"#34d399\", \"#60a5fa\", \"#f472b6\", \"#fb923c\"];\n\n/**\n * Wraps a surface (composer, search field, card) and runs a soft multicolor\n * glow around its border. The beam is two arcs of a rotating conic gradient,\n * masked to a 1px ring, plus a blurred copy that bleeds slightly inside.\n */\nexport function BorderBeam({\n  children,\n  duration = 8,\n  active = false,\n  disabled = false,\n  colors = DEFAULT_COLORS,\n  radius = 16,\n  className,\n  style,\n  ...props\n}: BorderBeamProps) {\n  const reduceMotion = useReducedMotion();\n  const [a, b, c, d] = colors;\n  const gradient = `conic-gradient(from 0deg, transparent 0deg, ${a} 30deg, ${b} 70deg, transparent 110deg, transparent 180deg, ${c} 210deg, ${d} 250deg, transparent 290deg)`;\n  const lap = active ? duration / 2 : duration;\n  const r = typeof radius === \"number\" ? `${radius}px` : radius;\n\n  const spinner = (\n    <motion.span\n      aria-hidden\n      className=\"absolute top-1/2 left-1/2 aspect-square w-[max(200%,40rem)] -translate-x-1/2 -translate-y-1/2\"\n      style={{ background: gradient }}\n      animate={reduceMotion ? { rotate: 45 } : { rotate: 360 }}\n      transition={reduceMotion ? { duration: 0 } : { duration: lap, ease: \"linear\", repeat: Infinity }}\n    />\n  );\n\n  return (\n    <div className={cn(\"relative isolate\", className)} style={{ borderRadius: r, ...style }} {...props}>\n      {children}\n      {!disabled && (\n        <>\n          {/* Soft glow: a wider ring of the same beam, blurred and clipped so it bleeds inward only. */}\n          <motion.span\n            aria-hidden\n            className=\"pointer-events-none absolute inset-0 overflow-hidden\"\n            style={{ borderRadius: r }}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: active ? 0.8 : 0.45 }}\n            transition={{ duration: 0.6 }}\n          >\n            <span className=\"absolute inset-0 blur-md\">\n              <span className=\"absolute inset-0 overflow-hidden p-1.5\" style={{ borderRadius: r, ...RING_MASK }}>\n                {spinner}\n              </span>\n            </span>\n          </motion.span>\n          {/* The crisp beam on the 1px border ring. */}\n          <motion.span\n            aria-hidden\n            className=\"pointer-events-none absolute inset-0 overflow-hidden p-px\"\n            style={{ borderRadius: r, ...RING_MASK }}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: active ? 1 : 0.7 }}\n            transition={{ duration: 0.6 }}\n          >\n            {spinner}\n          </motion.span>\n        </>\n      )}\n    </div>\n  );\n}\n","dependencies":["motion"],"localImports":["@/lib/utils"]}