-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HollowDotsSpinner.js
77 lines (69 loc) · 1.82 KB
/
HollowDotsSpinner.js
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
70
71
72
73
74
75
76
77
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
const HollowSpinner = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => 2 * props.size * props.dotsNum}px;
* {
box-sizing: border-box;
}
.dot {
width: ${(props) => props.size}px;
height: ${(props) => props.size}px;
margin: 0 calc(${(props) => props.size}px / 2);
border: calc(${(props) => props.size}px / 5) solid ${(props) => props.color};
border-radius: 50%;
float: left;
transform: scale(0);
animation: hollow-dots-spinner-animation
${(props) => props.animationDuration}ms ease infinite 0ms;
}
.dot:nth-child(1) {
animation-delay: calc(${(props) => props.animationDelay}ms * 1);
}
.dot:nth-child(2) {
animation-delay: calc(${(props) => props.animationDelay}ms * 2);
}
.dot:nth-child(3) {
animation-delay: calc(${(props) => props.animationDelay}ms * 3);
}
@keyframes hollow-dots-spinner-animation {
50% {
transform: scale(1);
opacity: 1;
}
100% {
opacity: 0;
}
}
`;
function generateDots(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="dot" />
));
}
const HollowDotsSpinnerBase = ({
size = 15,
color = '#fff',
animationDuration = 1000,
className = '',
innerRef,
...props
}) => {
const dotsNum = 3;
const animationDelay = animationDuration * 0.3;
return (
<HollowSpinner
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`hollow-dots-spinner${className ? ' ' + className : ''}`}
dotsNum={dotsNum}
animationDelay={animationDelay}
{...props}
>
{generateDots(dotsNum)}
</HollowSpinner>
);
};
export const HollowDotsSpinner = addRefProps(HollowDotsSpinnerBase);