fix(recovery): restore source removed by production documentation merge
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import Image, { type ImageProps } from "next/image";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
interface FadeImageProps extends Omit<ImageProps, "onLoad"> {
|
||||
fadeDelay?: number;
|
||||
}
|
||||
|
||||
export function FadeImage({ className, fadeDelay = 0, ...props }: FadeImageProps) {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
if (entry.isIntersecting) {
|
||||
setTimeout(() => {
|
||||
setIsVisible(true);
|
||||
}, fadeDelay);
|
||||
observer.disconnect();
|
||||
}
|
||||
},
|
||||
{
|
||||
threshold: 0.1,
|
||||
rootMargin: "50px",
|
||||
}
|
||||
);
|
||||
|
||||
if (ref.current) {
|
||||
observer.observe(ref.current);
|
||||
}
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [fadeDelay]);
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative h-full w-full">
|
||||
<Image
|
||||
{...props}
|
||||
className={`${className || ""} transition-all duration-700 ease-out ${
|
||||
isVisible && isLoaded ? "opacity-100 scale-100" : "opacity-0 scale-[1.02]"
|
||||
}`}
|
||||
onLoad={() => setIsLoaded(true)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user