File size: 1,152 Bytes
1e92f2d |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
// @flow
import * as React from 'react';
import { Img, FallbackImg, LoadingImg } from './style';
import VisibilitySensor from 'react-visibility-sensor';
type Props = {
src: any,
type: 'user' | 'community',
size: number,
mobilesize?: number,
isClickable?: boolean,
alt: string,
};
export default class Image extends React.Component<Props> {
render() {
const { type, size, mobilesize } = this.props;
const { ...rest } = this.props;
const fallbackSrc =
type === 'user'
? '/img/default_avatar.svg'
: '/img/default_community.svg';
return (
<VisibilitySensor>
<Img
{...rest}
decode={false}
loader={
<LoadingImg
size={size}
mobilesize={mobilesize}
type={type}
src={fallbackSrc}
alt=""
/>
}
unloader={
<FallbackImg
size={size}
mobilesize={mobilesize}
type={type}
src={fallbackSrc}
alt=""
/>
}
/>
</VisibilitySensor>
);
}
}
|