2025-12-03 16:48:15 +03:30
|
|
|
|
"use client"
|
|
|
|
|
|
|
2026-07-23 17:00:55 +03:30
|
|
|
|
import { motion, useReducedMotion, type Transition } from "motion/react"
|
2025-12-03 16:48:15 +03:30
|
|
|
|
|
|
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
|
|
|
|
|
|
|
|
interface BorderBeamProps {
|
|
|
|
|
|
/**
|
2026-07-23 17:00:55 +03:30
|
|
|
|
* Approximate length of the visible beam. Mapped to conic spread.
|
2025-12-03 16:48:15 +03:30
|
|
|
|
*/
|
|
|
|
|
|
size?: number
|
|
|
|
|
|
/**
|
2026-07-23 17:00:55 +03:30
|
|
|
|
* The duration of one full loop (seconds).
|
2025-12-03 16:48:15 +03:30
|
|
|
|
*/
|
|
|
|
|
|
duration?: number
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The delay of the border beam.
|
|
|
|
|
|
*/
|
|
|
|
|
|
delay?: number
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The color of the border beam from.
|
|
|
|
|
|
*/
|
|
|
|
|
|
colorFrom?: string
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The color of the border beam to.
|
|
|
|
|
|
*/
|
|
|
|
|
|
colorTo?: string
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The motion transition of the border beam.
|
|
|
|
|
|
*/
|
|
|
|
|
|
transition?: Transition
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The class name of the border beam.
|
|
|
|
|
|
*/
|
|
|
|
|
|
className?: string
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The style of the border beam.
|
|
|
|
|
|
*/
|
|
|
|
|
|
style?: React.CSSProperties
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Whether to reverse the animation direction.
|
|
|
|
|
|
*/
|
|
|
|
|
|
reverse?: boolean
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The initial offset position (0-100).
|
|
|
|
|
|
*/
|
|
|
|
|
|
initialOffset?: number
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The border width of the beam.
|
|
|
|
|
|
*/
|
|
|
|
|
|
borderWidth?: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-23 17:00:55 +03:30
|
|
|
|
/**
|
|
|
|
|
|
* Soft beam riding the parent border via a masked rotating conic-gradient.
|
|
|
|
|
|
* Avoids offset-path corner breaks while staying flush with rounded frames.
|
|
|
|
|
|
*/
|
2025-12-03 16:48:15 +03:30
|
|
|
|
export const BorderBeam = ({
|
|
|
|
|
|
className,
|
|
|
|
|
|
size = 50,
|
|
|
|
|
|
delay = 0,
|
|
|
|
|
|
duration = 6,
|
2026-07-23 17:00:55 +03:30
|
|
|
|
colorFrom = "#29A19C",
|
|
|
|
|
|
colorTo = "#044343",
|
2025-12-03 16:48:15 +03:30
|
|
|
|
transition,
|
|
|
|
|
|
style,
|
|
|
|
|
|
reverse = false,
|
|
|
|
|
|
initialOffset = 0,
|
|
|
|
|
|
borderWidth = 1,
|
|
|
|
|
|
}: BorderBeamProps) => {
|
2026-07-23 17:00:55 +03:30
|
|
|
|
const reduceMotion = useReducedMotion()
|
|
|
|
|
|
// Map legacy px "size" → angular span (deg). Clamped so the beam stays a short arc.
|
|
|
|
|
|
const spread = Math.min(48, Math.max(12, size * 0.18))
|
|
|
|
|
|
const startAngle = initialOffset * 3.6
|
|
|
|
|
|
|
2025-12-03 16:48:15 +03:30
|
|
|
|
return (
|
|
|
|
|
|
<div
|
2026-07-23 17:00:55 +03:30
|
|
|
|
className="pointer-events-none absolute overflow-hidden rounded-[inherit] border-(length:--border-beam-width) border-transparent [mask-image:linear-gradient(transparent,transparent),linear-gradient(#000,#000)] [mask-composite:intersect] [mask-clip:padding-box,border-box]"
|
2025-12-03 16:48:15 +03:30
|
|
|
|
style={
|
|
|
|
|
|
{
|
2026-07-23 17:00:55 +03:30
|
|
|
|
// Overlay the parent’s border (e.g. .media-frame 1px).
|
|
|
|
|
|
inset: `-${borderWidth}px`,
|
2025-12-03 16:48:15 +03:30
|
|
|
|
"--border-beam-width": `${borderWidth}px`,
|
|
|
|
|
|
} as React.CSSProperties
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
className={cn(
|
2026-07-23 17:00:55 +03:30
|
|
|
|
"absolute top-1/2 left-1/2 aspect-square w-[max(200%,200vw)]",
|
2025-12-03 16:48:15 +03:30
|
|
|
|
className
|
|
|
|
|
|
)}
|
|
|
|
|
|
style={
|
|
|
|
|
|
{
|
2026-07-23 17:00:55 +03:30
|
|
|
|
x: "-50%",
|
|
|
|
|
|
y: "-50%",
|
|
|
|
|
|
background: `conic-gradient(from ${startAngle}deg, transparent 0deg, ${colorFrom} ${spread * 0.35}deg, ${colorTo} ${spread}deg, transparent ${spread * 1.65}deg)`,
|
2025-12-03 16:48:15 +03:30
|
|
|
|
...style,
|
2026-07-23 17:00:55 +03:30
|
|
|
|
} as React.CSSProperties
|
|
|
|
|
|
}
|
|
|
|
|
|
initial={false}
|
|
|
|
|
|
animate={
|
|
|
|
|
|
reduceMotion
|
|
|
|
|
|
? { rotate: 0 }
|
|
|
|
|
|
: { rotate: reverse ? -360 : 360 }
|
2025-12-03 16:48:15 +03:30
|
|
|
|
}
|
|
|
|
|
|
transition={{
|
|
|
|
|
|
repeat: Infinity,
|
|
|
|
|
|
ease: "linear",
|
|
|
|
|
|
duration,
|
|
|
|
|
|
delay: -delay,
|
|
|
|
|
|
...transition,
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|