2019-10-06 07:47:08 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2020-05-28 19:07:04 +02:00
|
|
|
import classnames from 'classnames';
|
2019-10-06 07:47:08 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-10-07 07:22:04 +02:00
|
|
|
import Freezeframe from './FreezeframeLite';
|
2021-04-14 21:02:02 +02:00
|
|
|
import useLazyLoading from 'effects/use-lazy-loading';
|
2019-10-06 07:47:08 +02:00
|
|
|
|
2021-02-16 22:09:20 +01:00
|
|
|
const FreezeframeWrapper = (props) => {
|
2019-10-06 07:47:08 +02:00
|
|
|
const imgRef = React.useRef();
|
|
|
|
const freezeframe = React.useRef();
|
2020-08-04 19:50:33 +02:00
|
|
|
// eslint-disable-next-line
|
|
|
|
const { src, className, children } = props;
|
2019-10-06 07:47:08 +02:00
|
|
|
|
2021-05-14 17:00:07 +02:00
|
|
|
const srcLoaded = useLazyLoading(imgRef);
|
2019-10-06 07:47:08 +02:00
|
|
|
|
2021-05-14 17:00:07 +02:00
|
|
|
useEffect(() => {
|
|
|
|
if (srcLoaded) {
|
|
|
|
freezeframe.current = new Freezeframe(imgRef.current);
|
|
|
|
}
|
|
|
|
}, [srcLoaded]);
|
2021-04-07 07:33:36 +02:00
|
|
|
|
2019-10-06 07:47:08 +02:00
|
|
|
return (
|
2020-05-28 19:07:04 +02:00
|
|
|
<div className={classnames(className, 'freezeframe-wrapper')}>
|
2020-08-04 19:50:33 +02:00
|
|
|
<>
|
2021-04-07 07:33:36 +02:00
|
|
|
<img ref={imgRef} data-src={src} className="freezeframe-img" />
|
2020-08-04 19:50:33 +02:00
|
|
|
{children}
|
|
|
|
</>
|
2019-10-06 07:47:08 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
FreezeframeWrapper.propTypes = {
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
className: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FreezeframeWrapper;
|