Animated Beam for React
AnimatedBeam is a React effect that sends a light along an SVG path between two elements, measured from refs. Use it for integration diagrams and data-flow maps; it moves by transform only and rests off-screen.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/animated-beam.jsonWaiting for sources
Integration diagram
Three sources feed one hub. Each beam is staggered with delay and bent with curvature, so the network reads as alive without any one beam competing. The beam is decorative (aria-hidden), so say what is connected in the labels.
import { useRef, useState } from "react";
import { AnimatedBeam } from "@/components/sheenui/animated-beam/animated-beam";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
import { Switch } from "@/components/sheenui/switch/switch";
// Package build (after the first npm release, or a packed tarball): import { AnimatedBeam, GlassCard, Switch } from "@sheenui/theme";
// This example also uses glass-card, switch: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/switch.json
export function Example() {
const [paused, setPaused] = useState(false);
const container = useRef<HTMLDivElement>(null);
const a = useRef<HTMLDivElement>(null);
const b = useRef<HTMLDivElement>(null);
const c = useRef<HTMLDivElement>(null);
const hub = useRef<HTMLDivElement>(null);
return (
<>
<Switch label="Pause beams" checked={paused} onCheckedChange={setPaused} />
<div ref={container} className="relative flex w-full max-w-md items-center justify-between py-6">
<div className="flex flex-col gap-8">
<GlassCard ref={a} className="grid size-16 place-items-center text-sm font-semibold">Billing</GlassCard>
<GlassCard ref={b} className="grid size-16 place-items-center text-sm font-semibold">Chat</GlassCard>
<GlassCard ref={c} className="grid size-16 place-items-center text-sm font-semibold">Docs</GlassCard>
</div>
<GlassCard ref={hub} tint className="grid size-24 place-items-center font-semibold">Your app</GlassCard>
<AnimatedBeam containerRef={container} fromRef={a} toRef={hub} curvature={-40} paused={paused} />
<AnimatedBeam containerRef={container} fromRef={b} toRef={hub} delay={0.8} paused={paused} />
<AnimatedBeam containerRef={container} fromRef={c} toRef={hub} curvature={40} delay={1.6} paused={paused} />
</div>
</>
);
}Files to copy
5 folders · 6 files · 4 packages
- From
theme/src/ components/animated-beam/hooks/{use-media-query.ts, use-preferences.ts}motion/{beat-animations.ts, beat.ts, gate.ts}lib/cn.tsstyles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/animated-beam.jsonRegistry item: animated-beam. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/glass-card/components/switch/hooks/{use-direction.ts, use-latest.ts}motion/{light-follower.ts, tokens.ts}lib/{field-control-shell.tsx, form.ts, heading.ts, motion-props.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/switch.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
One connection, your colours
colorFrom and colorTo take any CSS colour (the defaults are the accent tokens), length and thickness shape the comet, and reverse sends it the other way, for a reply travelling back.
import { useRef } from "react";
import { AnimatedBeam } from "@/components/sheenui/animated-beam/animated-beam";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
// Package build (after the first npm release, or a packed tarball): import { AnimatedBeam, GlassCard } from "@sheenui/theme";
// This example also uses glass-card: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json
export function Example() {
const container = useRef<HTMLDivElement>(null);
const from = useRef<HTMLDivElement>(null);
const to = useRef<HTMLDivElement>(null);
return (
<div ref={container} className="relative flex w-full max-w-md items-center justify-between py-6">
<GlassCard ref={from} className="grid size-16 place-items-center text-sm font-semibold">API</GlassCard>
<GlassCard ref={to} className="grid size-16 place-items-center text-sm font-semibold">Client</GlassCard>
<AnimatedBeam
containerRef={container}
fromRef={from}
toRef={to}
reverse
length={96}
thickness={3}
colorFrom="var(--sheen-accent-2)"
colorTo="var(--sheen-accent)"
/>
</div>
);
}Props
Keyboard
Accessibility
- Decorative: the overlay is aria-hidden. The connection must also be in text (a label, a heading or a sentence), because the picture is invisible to assistive technology.
- paused holds the light where it is, so a page can offer a stop control (WCAG 2.2.2). It also rests off-screen and in hidden tabs.
- Under reduced motion there is no light, only the faint still track between the elements.
- The light is one element moved by transform and faded by opacity along positions sampled from the real path; nothing blurs, masks or filters the glass nodes.
When to use the animated beam effect
- Use it in an integration diagram: a source card, your product in the middle and a destination, with a light running along the connection to show data flowing.
- Use it in a "connected to" section or an architecture map, with several beams staggered by delay so the network feels alive without any of them competing.
- Bend a path with curvature to route around a centre node, or reverse it for a response going back; the beam leaves from the edge of each element, not its centre.
- Skip it when the relationship is the point of the content and nothing else says so; the beam is aria-hidden, so name the connection in text as well.
- Pair it with GlassCard nodes, Badge labels on the nodes, and a Switch wired to the paused prop for a stop control.
Frequently asked questions
Related pages
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .