Files
klz-cables.com/components/Reveal.tsx
Marc Mintel 6e34392976
Some checks failed
Build & Deploy / deploy (push) Failing after 3m39s
build
2026-01-19 20:46:39 +01:00

50 lines
1.1 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 }
);
const currentRef = ref.current;
if (currentRef) {
observer.observe(currentRef);
}
return () => {
if (currentRef) {
observer.unobserve(currentRef);
}
};
}, [threshold]);
return (
<div
ref={ref}
className={cn('reveal-on-scroll', isVisible && 'is-visible', className)}
style={{ transitionDelay: `${delay}ms` }}
>
{children}
</div>
);
}