1f3af8f7f5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
780 B
TypeScript
38 lines
780 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, type ReactNode } from "react";
|
|
|
|
export default function Reveal({
|
|
children,
|
|
delay = 0,
|
|
className = "",
|
|
}: {
|
|
children: ReactNode;
|
|
delay?: number;
|
|
className?: string;
|
|
}) {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
const el = ref.current;
|
|
if (!el) return;
|
|
const io = new IntersectionObserver(
|
|
([entry]) => {
|
|
if (entry.isIntersecting) {
|
|
el.classList.add("is-visible");
|
|
io.disconnect();
|
|
}
|
|
},
|
|
{ rootMargin: "0px 0px -10% 0px" },
|
|
);
|
|
io.observe(el);
|
|
return () => io.disconnect();
|
|
}, []);
|
|
|
|
return (
|
|
<div ref={ref} className={`reveal ${className}`} style={{ transitionDelay: `${delay}ms` }}>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|