Skip to documentation content

Animated Beam

Connect two elements with a curved line and send a pulse of light along it.

animated-beam-demo

Overview

Animated Beam draws a curved path between two elements and sends a light pulse along it. Use it to explain how data moves through a system: sources feeding an assistant, services calling an API, or steps in a pipeline. The path is measured from the elements' boxes and recomputed whenever the container or either node resizes, so layouts can be responsive.

Installation

npx honestui@latest add animated-beam

Usage

import { AnimatedBeam } from "@/components/animated/animated-beam"

const containerRef = useRef<HTMLDivElement>(null)
const fromRef = useRef<HTMLDivElement>(null)
const toRef = useRef<HTMLDivElement>(null)

<div ref={containerRef} className="relative flex justify-between">
  <div ref={fromRef} className="z-10">Source</div>
  <div ref={toRef} className="z-10">Destination</div>
  <AnimatedBeam containerRef={containerRef} fromRef={fromRef} toRef={toRef} />
</div>

The container must be positioned. Give the nodes z-10 or a background so the beam passes behind them. Stagger several beams with delay so their pulses don't arrive together.

Accessibility

The beam is decorative and hidden from assistive technology, so the diagram's meaning must come from the nodes. Give each node an accessible name, and describe the flow in nearby text when it matters. When reduced motion is requested, the pulse is removed and the resting path stays.

API Reference

PropTypeDefaultDescription
containerRef*RefObject<HTMLElement>–Positioned element both nodes sit inside.
fromRef*RefObject<HTMLElement>–Element the beam starts from.
toRef*RefObject<HTMLElement>–Element the beam ends at.
curvaturenumber0Lifts the middle of the curve by this many px. Negative pushes it down. The path always leaves and arrives level.
reversebooleanfalseSends the pulse from the end back to the start.
durationnumber4Seconds for the pulse to travel the path.
delaynumber0Seconds before the first pulse.
pulseLengthnumber0.25Length of the pulse and its fading tail, as a fraction of the path.
pathColorstring"var(--muted-foreground)"Color of the resting path.
pathWidthnumber1.5Stroke width in px.
pathOpacitynumber0.2Opacity of the resting path.
gradientStartColorstring"var(--foreground)"Color at the head of the pulse.
gradientStopColorstring–Color the tail fades to.
startXOffsetnumber0Horizontal offset of the start point in px. startYOffset, endXOffset, and endYOffset work the same way.
classNamestring–Classes for the SVG.