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