-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathBarLoader.tsx
69 lines (61 loc) · 1.79 KB
/
BarLoader.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
64
65
66
67
68
69
import * as React from "react";
import { cssValue } from "./helpers/unitConverter";
import { createAnimation } from "./helpers/animation";
import { LoaderHeightWidthProps } from "./helpers/props";
import { calculateRgba } from "./helpers/colors";
const long = createAnimation(
"BarLoader",
`0% {left: -35%;right: 100%} 60% {left: 100%;right: -90%} 100% {left: 100%;right: -90%}`,
"long"
);
const short = createAnimation(
"BarLoader",
`0% {left: -200%;right: 100%} 60% {left: 107%;right: -8%} 100% {left: 107%;right: -8%}`,
"short"
);
function BarLoader({
loading = true,
color = "#000000",
speedMultiplier = 1,
cssOverride = {},
height = 4,
width = 100,
...additionalprops
}: LoaderHeightWidthProps): JSX.Element | null {
const wrapper: React.CSSProperties = {
display: "inherit",
position: "relative",
width: cssValue(width),
height: cssValue(height),
overflow: "hidden",
backgroundColor: calculateRgba(color, 0.2),
backgroundClip: "padding-box",
...cssOverride,
};
const style = (i: number): React.CSSProperties => {
return {
position: "absolute",
height: cssValue(height),
overflow: "hidden",
backgroundColor: color,
backgroundClip: "padding-box",
display: "block",
borderRadius: 2,
willChange: "left, right",
animationFillMode: "forwards",
animation: `${i === 1 ? long : short} ${2.1 / speedMultiplier}s ${i === 2 ? `${1.15 / speedMultiplier}s` : ""} ${
i === 1 ? "cubic-bezier(0.65, 0.815, 0.735, 0.395)" : "cubic-bezier(0.165, 0.84, 0.44, 1)"
} infinite`,
};
};
if (!loading) {
return null;
}
return (
<span style={wrapper} {...additionalprops}>
<span style={style(1)} />
<span style={style(2)} />
</span>
);
}
export default BarLoader;