Luca Perullo
Components

Component

LiveNew

Animated Beam

Calcola il path SVG tra due ref, traccia una curva quadratica, poi anima un overlay div via CSS offset-path lungo lo stesso d. ResizeObserver mantiene il beam attaccato se i nodi si muovono.

DiagramSVGAnimationClient
Open in ClaudeSorgente

Esempio01

animated-beam.tsx
001HTTP round-trip · waypoints
request →
← response
Browser
client
Server
edge
Database
postgres
fetchqueryresultrender
002Integration hub · smooth curves
Workflow
hub
Slack
channel
Github
repo
Email
transactional
Calendar
events
webhookfan-out4 destinations
003Build pipeline · linear
Source
git
Build
rust + swc
Test
vitest
Deploy
edge
commitcompileverifyship
004Health probe · pulse
Probe
every 30s
API
200 OK
Database
12ms
Cache
redis
ping3 endpointsalive
005Continuous stream · flow
Source
kafka
Processor
map · filter
Sink
warehouse
ingesttransformpersist
006Packet stream · particles
Client
browser
Edge
cdn pop
Origin
us-east-1
request5 packets / segment

Note Il container DEVE essere position-relative; le coordinate sono relative al suo bounding box. ResizeObserver ricomputa il path quando cambia la viewport o i nodi si rimisurano. Per più beam usa delay diversi.

Prompt LLM02

Incolla in Claude o ChatGPT per generare la tua variante. Include il contesto del brand, i token e i vincoli del progetto.

Prompt · animated-beam
Open in Claude
Sei un senior frontend engineer. Stai lavorando su un sito Next.js 16 + React 19 + Tailwind v4 in italiano, look chanhdai-inspired: colonna stretta 672px, Geist Sans + Geist Mono, hairline 1px, divisori a stripe diagonale, palette zinc.

Token CSS disponibili: --bg, --bg-alt, --fg, --fg-muted, --fg-soft, --border, --border-strong, --accent. Usa SEMPRE queste variabili tramite le utility tailwind generate (bg-bg, text-fg-muted, border-border, ecc.). Helper "cn" da "@/lib/utils". Niente librerie UI extra: solo lucide-react e tailwind-merge.

Genera un componente <AnimatedBeam> che disegna una curva animata tra due nodi (containerRef + fromRef + toRef).
Props (vedi BlobMixer per stile prompt):
- containerRef: RefObject<HTMLElement | null>.
- fromRef: RefObject<HTMLElement | null>.
- toRef: RefObject<HTMLElement | null>.
- duration?: number sec (default 2.6).
- strokeWidth?: number (default 2).
- pathColor?: string (default "var(--border-strong)").
- gradientStartColor?: string (default "var(--accent)").
- gradientStopColor?: string (default "transparent").
- curvature?: number 0-1 (default 0.45).
- reverse?: boolean.
- delay?: number sec.

Implementazione:
- "use client", useEffect con ResizeObserver sul container + window resize.
- Calcola midpoint + perpendicular offset per la curva quadratica: M ax ay Q (mx+ox) (my+oy) bx by.
- Render: <svg> con <path d=...> idle (stroke pathColor opacity 0.35) + <linearGradient>.
- Cometa: <div className="absolute"> con offsetPath path("..."), offsetRotate auto, animation sweep duration linear infinite, background linear-gradient.
- Keyframes uniche per id (Math.random) per evitare conflitti.
- prefers-reduced-motion blocca l'animazione.

Output: file completo src/components/animated-beam.tsx.

Uso tipico03

tsx
<div ref={containerRef} className="relative">
  <Node ref={fromRef}/>
  <Node ref={toRef}/>
  <AnimatedBeam containerRef={containerRef} fromRef={fromRef} toRef={toRef} />
</div>

Dipendenze04

npm
  • tailwind-merge
  • clsx
Interno
  • @/lib/utils#cn

Ti è servito? Dimmelo, oppure proponi il prossimo componente.