Overview
Themoving-border.tsx file exports two components:
Button- A button wrapper with an animated moving border effectMovingBorder- The core animation component that moves an element along an SVG path
Source Location
/workspace/source/src/app/components/ui/moving-border.tsx
Button Component
Overview
A pre-built button component with an animated border effect. The border features a moving radial gradient that travels around the button’s perimeter.Props
Border radius for the button container
Content to display inside the button
Component type to render as (e.g., “button”, “a”, Link, etc.)
Additional classes for the outer button container
Additional classes for the moving gradient element
Animation duration in milliseconds. Passed to
MovingBorder component.Additional classes for the inner content wrapper
All other props are spread to the root component element
Type Definition
From/workspace/source/src/app/components/ui/moving-border.tsx:13-31:
Default Styling
Container
Border Element
Inner Content
Usage Example
As Different Element
MovingBorder Component
Overview
The core animation component that moves children along an SVG path. This is a lower-level component used by theButton component but can be used independently for custom implementations.
Props
Element to animate along the path (typically a gradient or glow effect)
Time in milliseconds for one complete loop around the path
Horizontal corner radius for the SVG rectangle path
Vertical corner radius for the SVG rectangle path
Additional props spread to the SVG element
Type Definition
From/workspace/source/src/app/components/ui/moving-border.tsx:72-84:
Animation Implementation
The animation uses Framer Motion’suseAnimationFrame hook to create smooth, continuous movement along an SVG path.
Key Hooks Used
From/workspace/source/src/app/components/ui/moving-border.tsx:85-105:
How it works:
useAnimationFrameruns on every frame- Calculates current position based on elapsed time
getTotalLength()gets the SVG path’s total lengthgetPointAtLength()gets x,y coordinates at the current position- Transform template positions the child element at those coordinates
SVG Path Structure
From/workspace/source/src/app/components/ui/moving-border.tsx:108-125:
The
rect element with fill="none" creates an invisible path that defines the border shape. The rx and ry props control corner rounding.Custom Usage Example
Performance Notes
Dependencies
framer-motion- Required hooks:motion- For animated divuseAnimationFrame- For continuous animationuseMotionTemplate- For transform template stringuseMotionValue- For animation progress valueuseTransform- For coordinate transformations
@/lib/utils- Providescn()class merging utility- React (
useRef)
Browser Compatibility
The component uses SVG
getTotalLength() and getPointAtLength() methods, which are supported in all modern browsers. For older browsers, consider a polyfill.