-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelfBuildingSquareSpinner.js
109 lines (101 loc) · 2.76 KB
/
SelfBuildingSquareSpinner.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
const BuildingSquare = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
top: ${(props) => -1 * props.initialTopPosition}px;
* {
box-sizing: border-box;
}
.square {
height: ${(props) => props.size / 4}px;
width: ${(props) => props.size / 4}px;
top: ${(props) => -1 * props.initialTopPosition}px;
margin-right: calc(${(props) => props.size / 4}px / 3);
margin-top: calc(${(props) => props.size / 4}px / 3);
background: ${(props) => props.color};
float: left;
position: relative;
opacity: 0;
animation: self-building-square-spinner
${(props) => props.animationDuration}ms infinite;
}
.square:nth-child(1) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 6);
}
.square:nth-child(2) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 7);
}
.square:nth-child(3) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 8);
}
.square:nth-child(4) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 3);
}
.square:nth-child(5) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 4);
}
.square:nth-child(6) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 5);
}
.square:nth-child(7) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 0);
}
.square:nth-child(8) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 1);
}
.square:nth-child(9) {
animation-delay: calc(${(props) => props.animationDuration * 0.05}ms * 2);
}
.clear {
clear: both;
}
@keyframes self-building-square-spinner {
0% {
opacity: 0;
}
5% {
opacity: 1;
top: 0;
}
50.9% {
opacity: 1;
top: 0;
}
55.9% {
opacity: 0;
top: inherit;
}
}
`;
function generateSpinners(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className={`square${index % 3 === 0 ? ' clear' : ''}`} />
));
}
const SelfBuildingSquareSpinnerBase = ({
size = 40,
color = '#fff',
animationDuration = 6000,
className = '',
innerRef,
...props
}) => {
const initialTopPosition = size / 6;
return (
<BuildingSquare
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`self-building-square-spinner${
className ? ' ' + className : ''
}`}
initialTopPosition={initialTopPosition}
{...props}
>
{generateSpinners(9)}
</BuildingSquare>
);
};
export const SelfBuildingSquareSpinner = addRefProps(SelfBuildingSquareSpinnerBase);