Files
klz-cables.com/components/Reveal.tsx
Marc Mintel e6651761f3
Some checks failed
Build & Deploy / deploy (push) Failing after 17s
wip
2026-01-17 16:06:16 +01:00

49 lines
1.0 KiB
TypeScript

'use client';
import React, { useEffect, useRef, useState } from 'react';
import { cn } from '@/components/ui';
interface RevealProps {
children: React.ReactNode;
className?: string;
threshold?: number;
delay?: number;
}
export default function Reveal({ children, className, threshold = 0.1, delay = 0 }: RevealProps) {
const [isVisible, setIsVisible] = useState(false);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setIsVisible(true);
observer.unobserve(entry.target);
}
},
{ threshold }
);
if (ref.current) {
observer.observe(ref.current);
}
return () => {
if (ref.current) {
observer.unobserve(ref.current);
}
};
}, [threshold]);
return (
<div
ref={ref}
className={cn('reveal-on-scroll', isVisible && 'is-visible', className)}
style={{ transitionDelay: `${delay}ms` }}
>
{children}
</div>
);
}