2021-06-14 15:24:21 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import type { Node } from 'react';
|
|
|
|
import useLazyLoading from 'effects/use-lazy-loading';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
thumb: string,
|
2021-08-02 14:33:31 +02:00
|
|
|
fallback: ?string,
|
2021-06-14 15:24:21 +02:00
|
|
|
children?: Node,
|
2021-07-29 09:53:56 +02:00
|
|
|
className?: string,
|
2021-06-14 15:24:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const Thumb = (props: Props) => {
|
2021-08-02 14:33:31 +02:00
|
|
|
const { thumb, fallback, children, className } = props;
|
2021-06-14 15:24:21 +02:00
|
|
|
const thumbnailRef = React.useRef(null);
|
2021-08-02 14:33:31 +02:00
|
|
|
|
|
|
|
useLazyLoading(thumbnailRef, fallback || '');
|
2021-06-14 15:24:21 +02:00
|
|
|
|
|
|
|
return (
|
2021-07-29 09:53:56 +02:00
|
|
|
<div ref={thumbnailRef} data-background-image={thumb} className={classnames('media__thumb', className)}>
|
2021-06-14 15:24:21 +02:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Thumb;
|