This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2023-05-08 02:12:44 -07:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2023-05-08 18:11:56 -07:00
|
|
|
import { Blurhash } from './blurhash';
|
2023-05-08 02:12:44 -07:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
src: string;
|
|
|
|
srcSet?: string;
|
|
|
|
blurhash?: string;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Image: React.FC<Props> = ({ src, srcSet, blurhash, className }) => {
|
|
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
|
|
|
|
const handleLoad = useCallback(() => {
|
|
|
|
setLoaded(true);
|
|
|
|
}, [setLoaded]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames('image', { loaded }, className)} role='presentation'>
|
|
|
|
{blurhash && <Blurhash hash={blurhash} className='image__preview' />}
|
|
|
|
<img src={src} srcSet={srcSet} alt='' onLoad={handleLoad} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|