"use client"
import { type HTMLAttributes, useEffect, useRef, useState } from "react"
import { cn } from "@/lib/utils"
type SectionRevealProps = HTMLAttributes & {
delay?: number
}
export function SectionReveal({
children,
className,
delay = 0,
style,
...props
}: SectionRevealProps) {
const ref = useRef(null)
const [visible, setVisible] = useState(false)
useEffect(() => {
const node = ref.current
if (!node) {
return
}
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setVisible(true)
observer.disconnect()
}
},
{
threshold: 0.18,
rootMargin: "0px 0px -10% 0px",
}
)
observer.observe(node)
return () => observer.disconnect()
}, [])
return (
{children}
)
}