2019-09-10 06:59:44 +12:00
|
|
|
import React, { memo } from 'react';
|
|
|
|
|
import Icon from './Icon';
|
|
|
|
|
|
2020-01-24 13:43:03 +13:00
|
|
|
const ProgressRing = ({ radius, stroke, progress }) => {
|
|
|
|
|
const normalizedRadius = radius - stroke * 2;
|
|
|
|
|
const circumference = normalizedRadius * 2 * Math.PI;
|
|
|
|
|
const strokeDashoffset = circumference - progress * circumference;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<svg
|
|
|
|
|
className="loader__spinner__progress"
|
|
|
|
|
height={radius * 2}
|
|
|
|
|
width={radius * 2}
|
|
|
|
|
>
|
|
|
|
|
<circle
|
2020-01-27 16:52:12 +13:00
|
|
|
className="loader__spinner__progress__circle"
|
2020-01-24 13:43:03 +13:00
|
|
|
stroke="white"
|
|
|
|
|
fill="transparent"
|
|
|
|
|
strokeWidth={stroke}
|
|
|
|
|
strokeDasharray={`${circumference} ${circumference}`}
|
|
|
|
|
strokeDashoffset={strokeDashoffset}
|
|
|
|
|
r={normalizedRadius}
|
|
|
|
|
cx={radius}
|
|
|
|
|
cy={radius}
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
export default memo((props) => {
|
2020-01-24 13:43:03 +13:00
|
|
|
const {
|
|
|
|
|
body,
|
|
|
|
|
loading,
|
2020-02-13 10:41:20 +13:00
|
|
|
finished = false,
|
2020-01-24 13:43:03 +13:00
|
|
|
mini,
|
|
|
|
|
lazy,
|
|
|
|
|
white,
|
|
|
|
|
className = '',
|
|
|
|
|
progress = null,
|
|
|
|
|
} = props;
|
|
|
|
|
|
2020-02-13 10:41:20 +13:00
|
|
|
if (!loading && !finished) {
|
2020-01-24 13:43:03 +13:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let classNameString = 'loader';
|
|
|
|
|
if (className) {
|
|
|
|
|
classNameString += ` ${className}`;
|
|
|
|
|
}
|
|
|
|
|
if (mini) {
|
|
|
|
|
classNameString += ' loader--mini';
|
|
|
|
|
}
|
|
|
|
|
if (body) {
|
|
|
|
|
classNameString += ' loader--body';
|
|
|
|
|
}
|
|
|
|
|
if (lazy) {
|
|
|
|
|
classNameString += ' loader--lazy';
|
|
|
|
|
}
|
|
|
|
|
if (white) {
|
|
|
|
|
classNameString += ' loader--white';
|
|
|
|
|
}
|
2019-09-10 06:59:44 +12:00
|
|
|
|
2020-01-24 13:43:03 +13:00
|
|
|
if (!navigator.onLine) {
|
2019-09-10 06:59:44 +12:00
|
|
|
return (
|
2020-01-24 13:43:03 +13:00
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__offline">
|
|
|
|
|
<Icon name="wifi_off" />
|
|
|
|
|
<p> You need to be online load this resource </p>
|
2019-09-10 06:59:44 +12:00
|
|
|
</div>
|
2020-01-24 13:43:03 +13:00
|
|
|
</div>
|
2019-09-10 06:59:44 +12:00
|
|
|
);
|
2020-01-24 13:43:03 +13:00
|
|
|
}
|
|
|
|
|
|
2020-02-13 10:41:20 +13:00
|
|
|
if (finished) {
|
|
|
|
|
classNameString += ' loader--finished';
|
|
|
|
|
return (
|
|
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__spinner">
|
|
|
|
|
<Icon name="check" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 13:43:03 +13:00
|
|
|
if (progress) {
|
|
|
|
|
classNameString += ' loader--progress';
|
|
|
|
|
return (
|
|
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__spinner">
|
|
|
|
|
<ProgressRing
|
|
|
|
|
stroke="2"
|
2020-01-27 16:52:12 +13:00
|
|
|
radius={mini ? '13' : '60'}
|
2020-01-24 13:43:03 +13:00
|
|
|
progress={progress}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__spinner" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2019-09-10 06:59:44 +12:00
|
|
|
});
|