Animated Beam
magicui/animated-beamFreeComponent
An animated beam of light which travels along a path. Useful for showcasing the integration features of a website.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/animated-beam.jsonSource
1"use client"23import { useEffect, useId, useState, type RefObject } from "react"4import { motion } from "motion/react"56import { cn } from "@/lib/utils"78export interface AnimatedBeamProps {9 className?: string10 containerRef: RefObject<HTMLElement | null> // Container ref11 fromRef: RefObject<HTMLElement | null>12 toRef: RefObject<HTMLElement | null>13 curvature?: number14 reverse?: boolean15 pathColor?: string16 pathWidth?: number17 pathOpacity?: number18 gradientStartColor?: string19 gradientStopColor?: string20 delay?: number21 duration?: number22 repeat?: number23 repeatDelay?: number24 startXOffset?: number25 startYOffset?: number26 endXOffset?: number27 endYOffset?: number28}2930export const AnimatedBeam: React.FC<AnimatedBeamProps> = ({31 className,32 containerRef,33 fromRef,34 toRef,35 curvature = 0,36 reverse = false, // Include the reverse prop37 duration = 5,38 delay = 0,39 pathColor = "gray",40 pathWidth = 2,41 pathOpacity = 0.2,42 gradientStartColor = "#ffaa40",43 gradientStopColor = "#9c40ff",44 repeat = Infinity,45 repeatDelay = 0,46 startXOffset = 0,47 startYOffset = 0,48 endXOffset = 0,49 endYOffset = 0,50}) => {51 const id = useId()52 const [pathD, setPathD] = useState("")53 const [svgDimensions, setSvgDimensions] = useState({ width: 0, height: 0 })5455 // Calculate the gradient coordinates based on the reverse prop56 const gradientCoordinates = reverse57 ? {58 x1: ["90%", "-10%"],59 x2: ["100%", "0%"],60 y1: ["0%", "0%"],61 y2: ["0%", "0%"],62 }63 : {64 x1: ["10%", "110%"],65 x2: ["0%", "100%"],66 y1: ["0%", "0%"],67 y2: ["0%", "0%"],68 }6970 useEffect(() => {71 const updatePath = () => {72 if (containerRef.current && fromRef.current && toRef.current) {73 const containerRect = containerRef.current.getBoundingClientRect()74 const rectA = fromRef.current.getBoundingClientRect()75 const rectB = toRef.current.getBoundingClientRect()7677 const svgWidth = containerRect.width78 const svgHeight = containerRect.height79 setSvgDimensions({ width: svgWidth, height: svgHeight })8081 const startX =82 rectA.left - containerRect.left + rectA.width / 2 + startXOffset83 const startY =84 rectA.top - containerRect.top + rectA.height / 2 + startYOffset85 const endX =86 rectB.left - containerRect.left + rectB.width / 2 + endXOffset87 const endY =88// … truncated
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep | |
| Aurora Textaurora-text | magicui | Components | Free | no deps |
