37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useRef } from 'react';
|
|
|
|
/** Lightweight progressive enhancement: content is visible before JavaScript runs. */
|
|
export function SectionEntrance({ children, id }: { children: React.ReactNode; id: string }) {
|
|
const sectionRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
const element = sectionRef.current;
|
|
if (!element || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
|
|
const observer = new IntersectionObserver(
|
|
([entry]) => {
|
|
if (!entry.isIntersecting) return;
|
|
element.dataset.revealed = 'true';
|
|
observer.disconnect();
|
|
},
|
|
{ rootMargin: '0px 0px -6% 0px', threshold: 0.03 }
|
|
);
|
|
|
|
observer.observe(element);
|
|
return () => observer.disconnect();
|
|
}, []);
|
|
|
|
return (
|
|
<div
|
|
ref={sectionRef}
|
|
data-section-entrance={id}
|
|
data-revealed="false"
|
|
className={id === 'hero-section' ? 'section-shell section-shell--hero' : 'section-shell'}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|