-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathClockLoader.tsx
64 lines (55 loc) · 1.61 KB
/
ClockLoader.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
import * as React from "react";
import { parseLengthAndUnit } from "./helpers/unitConverter";
import { LoaderSizeProps } from "./helpers/props";
import { createAnimation } from "./helpers/animation";
const rotate = createAnimation("ClockLoader", "100% { transform: rotate(360deg) }", "rotate");
function ClockLoader({
loading = true,
color = "#000000",
speedMultiplier = 1,
cssOverride = {},
size = 50,
...additionalprops
}: LoaderSizeProps): JSX.Element | null {
const { value, unit } = parseLengthAndUnit(size);
const wrapper: React.CSSProperties = {
display: "inherit",
position: "relative",
width: `${value}${unit}`,
height: `${value}${unit}`,
backgroundColor: "transparent",
boxShadow: `inset 0px 0px 0px 2px ${color}`,
borderRadius: "50%",
...cssOverride,
};
const minute: React.CSSProperties = {
position: "absolute",
backgroundColor: color,
width: `${value / 3}px`,
height: "2px",
top: `${value / 2 - 1}px`,
left: `${value / 2 - 1}px`,
transformOrigin: "1px 1px",
animation: `${rotate} ${8 / speedMultiplier}s linear infinite`,
};
const hour: React.CSSProperties = {
position: "absolute",
backgroundColor: color,
width: `${value / 2.4}px`,
height: "2px",
top: `${value / 2 - 1}px`,
left: `${value / 2 - 1}px`,
transformOrigin: "1px 1px",
animation: `${rotate} ${2 / speedMultiplier}s linear infinite`,
};
if (!loading) {
return null;
}
return (
<span style={wrapper} {...additionalprops}>
<span style={hour} />
<span style={minute} />
</span>
);
}
export default ClockLoader;