-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathRotateLoader.tsx
63 lines (53 loc) · 1.49 KB
/
RotateLoader.tsx
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
53
54
55
56
57
58
59
60
61
62
63
import * as React from "react";
import { cssValue, parseLengthAndUnit } from "./helpers/unitConverter";
import { LoaderSizeMarginProps } from "./helpers/props";
import { createAnimation } from "./helpers/animation";
const rotate = createAnimation(
"RotateLoader",
"0% {transform: rotate(0deg)} 50% {transform: rotate(180deg)} 100% {transform: rotate(360deg)}",
"rotate"
);
function RotateLoader({
loading = true,
color = "#000000",
speedMultiplier = 1,
cssOverride = {},
size = 15,
margin = 2,
...additionalprops
}: LoaderSizeMarginProps): JSX.Element | null {
const { value, unit } = parseLengthAndUnit(margin);
const ball: React.CSSProperties = {
backgroundColor: color,
width: cssValue(size),
height: cssValue(size),
borderRadius: "100%",
};
const wrapper: React.CSSProperties = {
...ball,
display: "inline-block",
position: "relative",
animationFillMode: "both",
animation: `${rotate} ${1 / speedMultiplier}s 0s infinite cubic-bezier(0.7, -0.13, 0.22, 0.86)`,
...cssOverride,
};
const style = (i: number): React.CSSProperties => {
const left = (i % 2 ? -1 : 1) * (26 + value);
return {
opacity: "0.8",
position: "absolute",
top: "0",
left: `${left}${unit}`,
};
};
if (!loading) {
return null;
}
return (
<span style={wrapper} {...additionalprops}>
<span style={{ ...ball, ...style(1) }} />
<span style={{ ...ball, ...style(2) }} />
</span>
);
}
export default RotateLoader;