-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathCircleLoader.tsx
65 lines (56 loc) · 1.61 KB
/
CircleLoader.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
"use client";
import * as React from "react";
import { cssValue, parseLengthAndUnit } from "./helpers/unitConverter";
import { LoaderSizeProps } from "./helpers/props";
import { createAnimation } from "./helpers/animation";
const circle = createAnimation(
"CircleLoader",
"0% {transform: rotate(0deg)} 50% {transform: rotate(180deg)} 100% {transform: rotate(360deg)}",
"circle"
);
function CircleLoader({
loading = true,
color = "#000000",
speedMultiplier = 1,
cssOverride = {},
size = 50,
...additionalprops
}: LoaderSizeProps) {
const wrapper: React.CSSProperties = {
display: "inherit",
position: "relative",
width: cssValue(size),
height: cssValue(size),
...cssOverride,
};
const style = (i: number): React.CSSProperties => {
const { value, unit } = parseLengthAndUnit(size);
return {
position: "absolute",
height: `${value * (1 - i / 10)}${unit}`,
width: `${value * (1 - i / 10)}${unit}`,
borderTop: `1px solid ${color}`,
borderBottom: "none",
borderLeft: `1px solid ${color}`,
borderRight: "none",
borderRadius: "100%",
transition: "2s",
top: `${i * 0.7 * 2.5}%`,
left: `${i * 0.35 * 2.5}%`,
animation: `${circle} ${1 / speedMultiplier}s ${(i * 0.2) / speedMultiplier}s infinite linear`,
};
};
if (!loading) {
return null;
}
return (
<span style={wrapper} {...additionalprops}>
<span style={style(0)} />
<span style={style(1)} />
<span style={style(2)} />
<span style={style(3)} />
<span style={style(4)} />
</span>
);
}
export default CircleLoader;