GodUI

Animated Beam

An animated gradient beam that travels along a path connecting two separate nodes.

Installation

pnpm dlx shadcn@latest add "https://godui.design/r/animated-beam.json"

AnimatedBeam renders an absolutely-positioned SVG over a container and draws a quadratic path between two child refs, measured live with a ResizeObserver and on window resize. A travelling gradient animates along the path. Mount it as the last child of a relative container that also holds fromRef and toRef.

Usage

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

const containerRef = useRef(null);
const fromRef = useRef(null);
const toRef = useRef(null);
tsx
 
<div ref={containerRef} className="relative">
  <div ref={fromRef} />
  <div ref={toRef} />
  <AnimatedBeam containerRef={containerRef} fromRef={fromRef} toRef={toRef} curvature={50} />
</div>

Examples

Dotted data pipeline

Set pathDashArray for a dotted or dashed resting line. Here each stage connects with a dotted track ("0.1 8" with the round cap renders as dots), and staggered delays send the beam flowing from stage to stage.

Client
Edge
Compute
Database

Bidirectional sync

Stack two dashed beams with opposite curvature — and reverse on one — for a continuous two-way connection.

Device
Cloud

Props

PropTypeDefaultDescription
containerRefRefObject<HTMLElement>Element the SVG overlays.
fromRefRefObject<HTMLElement>Element the beam starts from.
toRefRefObject<HTMLElement>Element the beam ends at.
curvaturenumber0Bow of the curve in pixels.
reversebooleanfalseAnimate from end toward start.
durationnumber3Seconds for one travel of the gradient.
delaynumber0Delay before the first travel, in seconds.
pathColorstringvar(--border)Color of the static resting path.
pathWidthnumber2Width of the path in pixels.
pathOpacitynumber0.2Opacity of the static resting path.
pathDashArraystringstroke-dasharray for the resting path ("4 5" dashes, "0.1 8" dots).
gradientStartColorstringvar(--primary)Leading color of the travelling gradient.
gradientStopColorstringTrailing color of the travelling gradient.

On this page

Built with GodUI

Beautifully crafted motion components for modern interfaces.

Star on GitHub