2023-05-28 15:18:23 +03:00
|
|
|
import { useCallback, useState } from 'react';
|
|
|
|
import * as React from 'react';
|
2023-05-10 13:59:29 +03:00
|
|
|
|
2023-05-08 12:12:44 +03:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2023-05-10 13:59:29 +03:00
|
|
|
import { Blurhash } from './blurhash';
|
|
|
|
|
|
|
|
interface Props {
|
2023-05-08 12:12:44 +03:00
|
|
|
src: string;
|
|
|
|
srcSet?: string;
|
|
|
|
blurhash?: string;
|
|
|
|
className?: string;
|
2023-05-10 13:59:29 +03:00
|
|
|
}
|
2023-05-08 12:12:44 +03:00
|
|
|
|
2023-05-10 00:08:28 +03:00
|
|
|
export const ServerHeroImage: React.FC<Props> = ({
|
2023-05-10 00:41:18 +03:00
|
|
|
src,
|
|
|
|
srcSet,
|
|
|
|
blurhash,
|
|
|
|
className,
|
|
|
|
}) => {
|
2023-05-08 12:12:44 +03:00
|
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
|
|
|
|
const handleLoad = useCallback(() => {
|
|
|
|
setLoaded(true);
|
|
|
|
}, [setLoaded]);
|
|
|
|
|
|
|
|
return (
|
2023-05-10 00:41:18 +03:00
|
|
|
<div
|
|
|
|
className={classNames('image', { loaded }, className)}
|
|
|
|
role='presentation'
|
|
|
|
>
|
2023-05-08 12:12:44 +03:00
|
|
|
{blurhash && <Blurhash hash={blurhash} className='image__preview' />}
|
|
|
|
<img src={src} srcSet={srcSet} alt='' onLoad={handleLoad} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|