move inView ref to ImageContainer component

- the separate outer component is unneeded and affects the positioning of some components which rely on the ImageContainer's styling
This commit is contained in:
jeffvli 2025-09-06 17:14:30 -07:00
parent ea122f5a4f
commit 6368137815
2 changed files with 58 additions and 48 deletions

View file

@ -32,3 +32,8 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.view-wrapper {
width: 100%;
height: 100%;
}

View file

@ -1,6 +1,6 @@
import clsx from 'clsx'; import clsx from 'clsx';
import { motion, MotionConfigProps } from 'motion/react'; import { motion, MotionConfigProps } from 'motion/react';
import { type ImgHTMLAttributes } from 'react'; import { ForwardedRef, forwardRef, type ImgHTMLAttributes } from 'react';
import { Img } from 'react-image'; import { Img } from 'react-image';
import { InView } from 'react-intersection-observer'; import { InView } from 'react-intersection-observer';
@ -50,13 +50,13 @@ export function Image({
return ( return (
<InView> <InView>
{({ inView, ref }) => ( {({ inView, ref }) => (
<div ref={ref}>
<Img <Img
className={clsx(styles.image, className)} className={clsx(styles.image, className)}
container={(children) => ( container={(children) => (
<ImageContainer <ImageContainer
className={containerClassName} className={containerClassName}
enableAnimation={enableAnimation} enableAnimation={enableAnimation}
ref={ref}
{...imageContainerProps} {...imageContainerProps}
> >
{children} {children}
@ -78,7 +78,6 @@ export function Image({
) : null ) : null
} }
/> />
</div>
)} )}
</InView> </InView>
); );
@ -87,10 +86,14 @@ export function Image({
return <ImageUnloader />; return <ImageUnloader />;
} }
function ImageContainer({ children, className, enableAnimation, ...props }: ImageContainerProps) { const ImageContainer = forwardRef(
(
{ children, className, enableAnimation, ...props }: ImageContainerProps,
ref: ForwardedRef<HTMLDivElement>,
) => {
if (!enableAnimation) { if (!enableAnimation) {
return ( return (
<div className={clsx(styles.imageContainer, className)} {...props}> <div className={clsx(styles.imageContainer, className)} ref={ref} {...props}>
{children} {children}
</div> </div>
); );
@ -99,13 +102,15 @@ function ImageContainer({ children, className, enableAnimation, ...props }: Imag
return ( return (
<motion.div <motion.div
className={clsx(styles.imageContainer, className)} className={clsx(styles.imageContainer, className)}
ref={ref}
{...animationProps.fadeIn} {...animationProps.fadeIn}
{...props} {...props}
> >
{children} {children}
</motion.div> </motion.div>
); );
} },
);
function ImageLoader({ className }: ImageLoaderProps) { function ImageLoader({ className }: ImageLoaderProps) {
return ( return (
@ -118,7 +123,7 @@ function ImageLoader({ className }: ImageLoaderProps) {
function ImageUnloader({ className }: ImageUnloaderProps) { function ImageUnloader({ className }: ImageUnloaderProps) {
return ( return (
<div className={clsx(styles.unloader, className)}> <div className={clsx(styles.unloader, className)}>
<Icon icon="emptyImage" size="xl" /> <Icon color="default" icon="emptyImage" size="xl" />
</div> </div>
); );
} }