mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-25 17:44:14 -05:00
bd851d3b58
Port a65d2d1045
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
28 lines
715 B
TypeScript
28 lines
715 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 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>
|
|
);
|
|
};
|
|
|
|
export default Image;
|