catstodon/app/javascript/flavours/glitch/components/server_hero_image.tsx
fusagiko / takayamaki ea1f9b4223 [Glitch] Rename Image component to ServerHeroImage
Port ab7716cff4 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2023-05-25 20:44:09 +02:00

33 lines
733 B
TypeScript

import React, { useCallback, useState } from 'react';
import { Blurhash } from './blurhash';
import classNames from 'classnames';
type Props = {
src: string;
srcSet?: string;
blurhash?: string;
className?: string;
};
export const ServerHeroImage: 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>
);
};