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}
|
2020-01-25 22:18:52 +13:00
|
|
|
style={{
|
|
|
|
|
transform: `rotate(-90deg) translate(${stroke}px, -${stroke}px)`,
|
|
|
|
|
}}
|
2020-01-24 13:43:03 +13:00
|
|
|
>
|
|
|
|
|
<circle
|
|
|
|
|
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,
|
|
|
|
|
mini,
|
|
|
|
|
lazy,
|
|
|
|
|
white,
|
|
|
|
|
className = '',
|
|
|
|
|
progress = null,
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
if (!loading) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (progress) {
|
|
|
|
|
classNameString += ' loader--progress';
|
|
|
|
|
return (
|
|
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__spinner">
|
|
|
|
|
<ProgressRing
|
|
|
|
|
stroke="2"
|
|
|
|
|
radius={mini ? '12' : '60'}
|
|
|
|
|
progress={progress}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={classNameString}>
|
|
|
|
|
<div className="loader__spinner" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2019-09-10 06:59:44 +12:00
|
|
|
});
|