diff --git a/src/shared/components/image/image.module.css b/src/shared/components/image/image.module.css index 2fbb2eef..835ae0b7 100644 --- a/src/shared/components/image/image.module.css +++ b/src/shared/components/image/image.module.css @@ -1,3 +1,13 @@ +@keyframes fade-in { + from { + opacity: 0; + } + + to { + opacity: 1; + } +} + .image { width: 100%; height: 100%; @@ -5,6 +15,11 @@ border-radius: var(--theme-radius-md); } +.image.animated { + opacity: 1; + animation: fade-in 0.2s ease-in; +} + .loader { width: 100%; height: 100%; diff --git a/src/shared/components/image/image.tsx b/src/shared/components/image/image.tsx index d4f2e910..d5aa81c7 100644 --- a/src/shared/components/image/image.tsx +++ b/src/shared/components/image/image.tsx @@ -1,14 +1,13 @@ import clsx from 'clsx'; -import { motion, MotionConfigProps } from 'motion/react'; +import { MotionConfigProps } from 'motion/react'; import { ForwardedRef, forwardRef, type ImgHTMLAttributes } from 'react'; import { Img } from 'react-image'; -import { InView } from 'react-intersection-observer'; import styles from './image.module.css'; -import { animationProps } from '/@/shared/components/animations/animation-props'; import { Icon } from '/@/shared/components/icon/icon'; import { Skeleton } from '/@/shared/components/skeleton/skeleton'; +import { useInViewport } from '/@/shared/hooks/use-in-viewport'; interface ImageContainerProps extends MotionConfigProps { children: React.ReactNode; @@ -46,40 +45,40 @@ export function Image({ includeUnloader = true, src, }: ImageProps) { + const { inViewport, ref } = useInViewport(); + if (src) { return ( - - {({ inView, ref }) => ( - ( - - {children} - - )} - loader={ - includeLoader ? ( - - - - ) : null - } - src={inView ? src : FALLBACK_SVG} - unloader={ - includeUnloader ? ( - - - - ) : null - } - /> + ( + + {children} + )} - + loader={ + includeLoader ? ( + + + + ) : null + } + src={inViewport ? src : FALLBACK_SVG} + unloader={ + includeUnloader ? ( + + + + ) : null + } + /> ); } @@ -100,24 +99,15 @@ const ImageContainer = forwardRef( } return ( - +
{children} - +
); }, ); function ImageLoader({ className }: ImageLoaderProps) { - return ( -
- -
- ); + return ; } function ImageUnloader({ className }: ImageUnloaderProps) {