/* eslint-disable @next/next/no-img-element */ import React, { useRef, useEffect } from 'react' import { LazyImageFull, ImageState } from 'react-lazy-images' import objectFitImages from 'object-fit-images' import { BlurhashCanvas } from 'react-blurhash' import classNames from 'classnames' import styles from './index.module.scss' type LazyImageProps = { src: string srcRetina?: string placeholderHash?: string alt: string aspectRatio: string stretch?: boolean rounded?: boolean } & React.DetailedHTMLProps, HTMLDivElement> const LazyImage = ({ src, srcRetina = src, placeholderHash, alt, aspectRatio, stretch = false, rounded = false, ...props }: LazyImageProps) => { const [widthString, heightString] = aspectRatio.split('/') const width = parseInt(widthString) const height = parseInt(heightString) const imgRef = useRef(null) useEffect(() => { if (imgRef.current) { objectFitImages(imgRef.current) } }, [imgRef]) return ( {({ imageProps, imageState, ref }) => { const loaded = imageState === ImageState.LoadSuccess return (
{placeholderHash ? ( ) : null} {imageProps.alt}
) }}
) } export { LazyImage }