~cytrogen/masto-fe

ref: c8181eb0a41c4f5c1655d4e400cab071aee4182a masto-fe/app/javascript/mastodon/components/image.tsx -rw-r--r-- 696 bytes
c8181eb0 — Renaud Chaput Enforce stricter rules for Typescript files (#24910) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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>
  );
};