# Animated Beam

> Light travels along curved paths from sources into a hub and out to a result, measured from the real DOM. Includes a Beam primitive to connect any two elements.

- Kind: Motion component (Motion)
- Docs: https://ui.minidev.pro/docs/animated-beam
- Source (registry JSON with the full file): https://ui.minidev.pro/r/animated-beam.json
- License: MIT. One file, yours to edit after install.

## When to use

Paths are measured from the real DOM, so the diagram reflows with its container. `AnimatedBeam` is a ready-made "inputs → hub → output" diagram; `Beam` is the primitive that connects any two refs in your own layout. Use it for integration and pipeline diagrams; for a lit box outline use BorderBeam instead. Reduced motion keeps the static path and drops the light.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/animated-beam
```

Writes `components/ui/animated-beam.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/animated-beam.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { AnimatedBeam, Beam } from "@/components/ui/animated-beam"
```

From the npm package:

```tsx
import { AnimatedBeam } from "minidev-ui-kit/premium/animated-beam"
```

## Usage

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

export function Example() {
  return (
    <AnimatedBeam />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `inputs` | `Node[]` | `[ { icon: MailIcon, label: "Email" },...` | no | Sources on the left, each joined to the hub by a beam. Labels must be unique. |
| `hub` | `Node` | `{ icon: BotIcon, label: "Agent" }` | no | The centre node, drawn larger in ink. |
| `output` | `Node` | `{ icon: UserIcon, label: "Customer" }` | no | The node on the right that the hub flows into. |
| `className` | `string` | - | no |  |

## Examples

### Custom nodes

inputs, hub and output each take a lucide icon and a label; the paths are measured from the DOM, so any count of inputs works.

```tsx
<AnimatedBeam
  inputs={[
    { icon: CreditCardIcon, label: "Cards" },
    { icon: BanknoteIcon, label: "Transfers" },
    { icon: ReceiptIcon, label: "Invoices" },
  ]}
  hub={{ icon: ZapIcon, label: "Lumen" }}
  output={{ icon: BookOpenIcon, label: "Ledger" }}
/>
```

### Beam primitive

Connect any two refs inside a relative container; curvature bends the path upward in pixels and duration sets one pass.

```tsx
function SingleBeamDemo() {
  const box = React.useRef<HTMLDivElement>(null)
  const from = React.useRef<HTMLDivElement>(null)
  const to = React.useRef<HTMLDivElement>(null)
  return (
    <div ref={box} className="relative flex w-full max-w-sm items-center justify-between px-4 py-8">
      <div ref={from} className="relative z-10 grid size-12 place-items-center rounded-2xl border border-border bg-raised text-fg shadow-raised">
        <ReceiptIcon className="size-5" strokeWidth={1.75} />
      </div>
      <div ref={to} className="relative z-10 grid size-12 place-items-center rounded-2xl border border-border bg-ink text-on-ink shadow-ink">
        <LandmarkIcon className="size-5" strokeWidth={1.75} />
      </div>
      <Beam container={box} from={from} to={to} curvature={48} duration={2.5} />
    </div>
  )
}
```

### Two-way sync

Two beams between the same refs with opposite curvature and reverse on one of them read as data flowing both ways.

```tsx
function TwoWayDemo() {
  const box = React.useRef<HTMLDivElement>(null)
  const ledger = React.useRef<HTMLDivElement>(null)
  const bank = React.useRef<HTMLDivElement>(null)
  return (
    <div ref={box} className="relative flex w-full max-w-sm items-center justify-between px-4 py-10">
      <div className="relative z-10 flex flex-col items-center gap-1.5">
        <div ref={ledger} className="grid size-12 place-items-center rounded-2xl border border-border bg-raised text-fg shadow-raised">
          <BookOpenIcon className="size-5" strokeWidth={1.75} />
        </div>
        <span className="text-[11px] text-fg-muted">Lumen ledger</span>
      </div>
      <RefreshCwIcon className="relative z-10 size-4 text-fg-subtle" aria-hidden />
      <div className="relative z-10 flex flex-col items-center gap-1.5">
        <div ref={bank} className="grid size-12 place-items-center rounded-2xl border border-border bg-raised text-fg shadow-raised">
          <LandmarkIcon className="size-5" strokeWidth={1.75} />
        </div>
        <span className="text-[11px] text-fg-muted">Bank feed</span>
      </div>
      <Beam container={box} from={ledger} to={bank} curvature={40} duration={3} />
      <Beam container={box} from={ledger} to={bank} curvature={-40} duration={3} delay={1.5} reverse />
    </div>
  )
}
```

## Accessibility

- Every beam SVG is `aria-hidden`. `AnimatedBeam` adds an `sr-only` sentence built from the labels, such as "Email, Chat, Docs, CRM flow into Agent, which responds to Customer." With `Beam` alone, describe the diagram yourself.
- Under reduced motion the travelling light is not rendered. The static grey path stays, so the connections are still visible.

## FAQ

### How do I draw a beam between my own elements?

Use the exported `Beam` primitive with three refs: `container`, `from` and `to`. Give the container `className="relative"`, because the SVG is placed over it with `absolute inset-0`. Each beam runs from the centre of one element to the centre of the other.

### Why doesn't the beam follow an element that moves?

Paths are measured on mount, one frame later, and whenever the container resizes (a `ResizeObserver` on `container`). A node that moves without the container changing size, for example during a transform animation, keeps the old path until the next resize.

### How do I stagger several beams or send data the other way?

Give each `Beam` a growing `delay` in seconds and the same `duration`. `reverse` runs the pulse from `to` back to `from`, and `curvature` bends the path in pixels (positive bends up, negative bends down). `AnimatedBeam` itself staggers its inputs by 0.35s.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`

## Related

- [Border Beam](https://ui.minidev.pro/docs/border-beam/md): React border beam: a light that travels around any card's border, drawn as a masked conic gradient in your accent colors. Pauses for reduced motion.
- [Orbiting Circles](https://ui.minidev.pro/docs/orbiting-circles/md): Icons orbit a central hub on hairline rings for integration sections. Set radius, speed and direction per ring; icons stay upright while they travel.
- [Animated Feature Row](https://ui.minidev.pro/docs/animated-feature-row/md): A row of feature cards that slide up with a staggered delay when scrolled into view. Pass title and description pairs; reduced motion keeps them still.
- [Card Tilt](https://ui.minidev.pro/docs/card-tilt/md): A card that tilts in 3D toward the pointer on springs, with an accent glare that follows the cursor. It stays flat when reduced motion is preferred.
- [Cursor Spotlight Panel](https://ui.minidev.pro/docs/cursor-spotlight-panel/md): A panel whose accent radial spotlight follows the cursor, driven by Framer Motion values without re-renders. It shows a still surface for reduced motion.
- [Device Frame Stack](https://ui.minidev.pro/docs/device-frame-stack/md): Three device frames labelled mobile, app and docs that spring into a fanned, rotated stack when scrolled into view. Works as a hero or feature visual.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
