-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathPulseLoader.tsx
55 lines (48 loc) · 1.33 KB
/
PulseLoader.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
import * as React from "react";
import { cssValue } from "./helpers/unitConverter";
import { LoaderSizeMarginProps } from "./helpers/props";
import { createAnimation } from "./helpers/animation";
const pulse = createAnimation(
"PulseLoader",
"0% {transform: scale(1); opacity: 1} 45% {transform: scale(0.1); opacity: 0.7} 80% {transform: scale(1); opacity: 1}",
"pulse"
);
function PulseLoader({
loading = true,
color = "#000000",
speedMultiplier = 1,
cssOverride = {},
size = 15,
margin = 2,
...additionalprops
}: LoaderSizeMarginProps): JSX.Element | null {
const wrapper: React.CSSProperties = {
display: "inherit",
...cssOverride,
};
const style = (i: number): React.CSSProperties => {
return {
backgroundColor: color,
width: cssValue(size),
height: cssValue(size),
margin: cssValue(margin),
borderRadius: "100%",
display: "inline-block",
animation: `${pulse} ${0.75 / speedMultiplier}s ${
(i * 0.12) / speedMultiplier
}s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08)`,
animationFillMode: "both",
};
};
if (!loading) {
return null;
}
return (
<span style={wrapper} {...additionalprops}>
<span style={style(1)} />
<span style={style(2)} />
<span style={style(3)} />
</span>
);
}
export default PulseLoader;