({
children,
duration = 2000,
rx,
ry,
...otherProps
}: {
children: React.ReactNode
duration?: number
rx?: string
ry?: string
[key: string]: any
})
| 57 | } |
| 58 | |
| 59 | const MovingBorder = ({ |
| 60 | children, |
| 61 | duration = 2000, |
| 62 | rx, |
| 63 | ry, |
| 64 | ...otherProps |
| 65 | }: { |
| 66 | children: React.ReactNode |
| 67 | duration?: number |
| 68 | rx?: string |
| 69 | ry?: string |
| 70 | [key: string]: any |
| 71 | }) => { |
| 72 | const pathRef = useRef<any>(null) |
| 73 | const progress = useMotionValue<number>(0) |
| 74 | |
| 75 | useAnimationFrame((time) => { |
| 76 | const length = pathRef.current?.getTotalLength() |
| 77 | if (length) { |
| 78 | const pxPerMillisecond = length / duration |
| 79 | progress.set((time * pxPerMillisecond) % length) |
| 80 | } |
| 81 | }) |
| 82 | |
| 83 | const x = useTransform(progress, (val) => pathRef.current?.getPointAtLength(val).x) |
| 84 | const y = useTransform(progress, (val) => pathRef.current?.getPointAtLength(val).y) |
| 85 | |
| 86 | const transform = useMotionTemplate`translateX(${x}px) translateY(${y}px) translateX(-50%) translateY(-50%)` |
| 87 | |
| 88 | return ( |
| 89 | <> |
| 90 | <svg |
| 91 | xmlns="http://www.w3.org/2000/svg" |
| 92 | preserveAspectRatio="none" |
| 93 | className="absolute h-full w-full" |
| 94 | width="100%" |
| 95 | height="100%" |
| 96 | {...otherProps} |
| 97 | > |
| 98 | <rect fill="none" width="100%" height="100%" rx={rx} ry={ry} ref={pathRef} /> |
| 99 | </svg> |
| 100 | <motion.div |
| 101 | style={{ |
| 102 | position: "absolute", |
| 103 | top: 0, |
| 104 | left: 0, |
| 105 | display: "inline-block", |
| 106 | transform, |
| 107 | }} |
| 108 | > |
| 109 | {children} |
| 110 | </motion.div> |
| 111 | </> |
| 112 | ) |
| 113 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…