animated-beam
jolyui-ui/animated-beamFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/animated-beam.jsonSource
1import * as React from "react";2import { cn } from "@/lib/utils";34interface AnimatedBeamProps {5 /** Reference to the container element */6 containerRef: React.RefObject<HTMLElement | null>;7 /** Reference to the start element */8 fromRef: React.RefObject<HTMLElement | null>;9 /** Reference to the end element */10 toRef: React.RefObject<HTMLElement | null>;11 /** Curvature of the beam (-1 to 1, 0 is straight) */12 curvature?: number;13 /** Animation duration in seconds */14 duration?: number;15 /** Delay before animation starts */16 delay?: number;17 /** Reverse the animation direction */18 reverse?: boolean;19 /** Width of the beam path */20 pathWidth?: number;21 /** Color of the beam gradient start */22 gradientStartColor?: string;23 /** Color of the beam gradient end */24 gradientStopColor?: string;25 /** Starting point offset */26 startXOffset?: number;27 startYOffset?: number;28 /** Ending point offset */29 endXOffset?: number;30 endYOffset?: number;31 className?: string;32}3334const AnimatedBeam = ({35 containerRef,36 fromRef,37 toRef,38 curvature = 0,39 duration = 2,40 delay = 0,41 reverse = false,42 pathWidth = 2,43 gradientStartColor = "#18181b",44 gradientStopColor = "#18181b",45 startXOffset = 0,46 startYOffset = 0,47 endXOffset = 0,48 endYOffset = 0,49 className,50}: AnimatedBeamProps) => {51 const [pathD, setPathD] = React.useState("");52 const [svgDimensions, setSvgDimensions] = React.useState({53 width: 0,54 height: 0,55 });56 const uniqueId = React.useId();5758 const updatePath = React.useCallback(() => {59 if (!containerRef.current || !fromRef.current || !toRef.current) return;6061 const containerRect = containerRef.current.getBoundingClientRect();62 const fromRect = fromRef.current.getBoundingClientRect();63 const toRect = toRef.current.getBoundingClientRect();6465 const startX =66 fromRect.left - containerRect.left + fromRect.width / 2 + startXOffset;67 const startY =68 fromRect.top - containerRect.top + fromRect.height / 2 + startYOffset;69 const endX =70 toRect.left - containerRect.left + toRect.width / 2 + endXOffset;71 const endY =72 toRect.top - containerRect.top + toRect.height / 2 + endYOffset;7374 const midX = (startX + endX) / 2;75 const midY = (startY + endY) / 2;7677 // Calculate control point for quadratic bezier curve78 const dx = endX - startX;79 const dy = endY - startY;80 const controlX = midX - dy * curvature;81 const controlY = midY + dx * curvature;8283// … truncated
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps | |
| calendercalender | jolyui/ui | Components | Free | 3 deps |
