Border Trail
Animated border effect that moves along the edges of its parent container.
Examples
Border Trail Card
Border Trail Loading Card
Border Trail Textarea
Code
'use client';
import { cn } from '@/lib/utils';
import { motion, Transition } from 'framer-motion';
type BorderTrailProps = {
className?: string;
size?: number;
transition?: Transition;
delay?: number;
onAnimationComplete?: () => void;
style?: React.CSSProperties;
};
export function BorderTrail({
className,
size = 60,
transition,
delay,
onAnimationComplete,
style,
}: BorderTrailProps) {
const BASE_TRANSITION = {
repeat: Infinity,
duration: 5,
ease: 'linear',
};
return (
<div className='pointer-events-none absolute inset-0 rounded-[inherit] border border-transparent [mask-clip:padding-box,border-box] [mask-composite:intersect] [mask-image:linear-gradient(transparent,transparent),linear-gradient(#000,#000)]'>
<motion.div
className={cn('absolute aspect-square bg-zinc-500', className)}
style={{
width: size,
offsetPath: `rect(0 auto auto 0 round ${size}px)`,
...style,
}}
animate={{
offsetDistance: ['0%', '100%'],
}}
transition={{
...(transition ?? BASE_TRANSITION),
delay: delay,
}}
onAnimationComplete={onAnimationComplete}
/>
</div>
);
}
Component API
Border Trail
Prop | Type | Default | Description |
---|---|---|---|
className | string | Additional CSS classes for styling the border trail. | |
size | number | 60 | Size of the animated border effect. |
transition | Transition | Custom transition settings for the animation. | |
delay | number | Delay before the animation starts. | |
onAnimationComplete | () => void | Callback function triggered when the animation completes. |