({
children,
container,
blur = false,
duration = 1000,
ease = 'power2.out',
delay = 0,
threshold = 0.1,
initialOpacity = 0,
disappearAfter = 0,
disappearDuration = 0.5,
disappearEase = 'power2.in',
onComplete,
onDisappearanceComplete,
className = '',
style,
...props
})
| 5 | gsap.registerPlugin(ScrollTrigger); |
| 6 | |
| 7 | const FadeContent = ({ |
| 8 | children, |
| 9 | container, |
| 10 | blur = false, |
| 11 | duration = 1000, |
| 12 | ease = 'power2.out', |
| 13 | delay = 0, |
| 14 | threshold = 0.1, |
| 15 | initialOpacity = 0, |
| 16 | disappearAfter = 0, |
| 17 | disappearDuration = 0.5, |
| 18 | disappearEase = 'power2.in', |
| 19 | onComplete, |
| 20 | onDisappearanceComplete, |
| 21 | className = '', |
| 22 | style, |
| 23 | ...props |
| 24 | }) => { |
| 25 | const ref = useRef(null); |
| 26 | |
| 27 | useEffect(() => { |
| 28 | const el = ref.current; |
| 29 | if (!el) return; |
| 30 | |
| 31 | let scrollerTarget = container || document.getElementById('snap-main-container') || null; |
| 32 | if (typeof scrollerTarget === 'string') { |
| 33 | scrollerTarget = document.querySelector(scrollerTarget); |
| 34 | } |
| 35 | |
| 36 | const startPct = (1 - threshold) * 100; |
| 37 | |
| 38 | const getSeconds = val => (typeof val === 'number' && val > 10 ? val / 1000 : val); |
| 39 | |
| 40 | gsap.set(el, { |
| 41 | autoAlpha: initialOpacity, |
| 42 | filter: blur ? 'blur(10px)' : 'blur(0px)', |
| 43 | willChange: 'opacity, filter, transform' |
| 44 | }); |
| 45 | |
| 46 | const tl = gsap.timeline({ |
| 47 | paused: true, |
| 48 | delay: getSeconds(delay), |
| 49 | onComplete: () => { |
| 50 | if (onComplete) onComplete(); |
| 51 | if (disappearAfter > 0) { |
| 52 | gsap.to(el, { |
| 53 | autoAlpha: initialOpacity, |
| 54 | filter: blur ? 'blur(10px)' : 'blur(0px)', |
| 55 | delay: getSeconds(disappearAfter), |
| 56 | duration: getSeconds(disappearDuration), |
| 57 | ease: disappearEase, |
| 58 | onComplete: () => onDisappearanceComplete?.() |
| 59 | }); |
| 60 | } |
| 61 | } |
| 62 | }); |
| 63 | |
| 64 | tl.to(el, { |
nothing calls this directly
no test coverage detected