-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwappingSquaresSpinner.js
93 lines (86 loc) · 2.36 KB
/
SwappingSquaresSpinner.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
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
const SwappingSquare = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
* {
box-sizing: border-box;
}
.square {
height: calc(${(props) => props.size}px * 0.25 / 1.3);
width: calc(${(props) => props.size}px * 0.25 / 1.3);
animation-duration: ${(props) => props.animationDuration}ms;
border: calc(${(props) => props.size}px * 0.04 / 1.3) solid
${(props) => props.color};
margin-right: auto;
margin-left: auto;
position: absolute;
animation-iteration-count: infinite;
}
.square:nth-child(1) {
animation-name: swapping-squares-animation-child-1;
animation-delay: ${(props) => props.animationDuration * 0.5}ms;
}
.square:nth-child(2) {
animation-name: swapping-squares-animation-child-2;
animation-delay: 0ms;
}
.square:nth-child(3) {
animation-name: swapping-squares-animation-child-3;
animation-delay: ${(props) => props.animationDuration * 0.5}ms;
}
.square:nth-child(4) {
animation-name: swapping-squares-animation-child-4;
animation-delay: 0ms;
}
@keyframes swapping-squares-animation-child-1 {
50% {
transform: translate(150%, 150%) scale(2, 2);
}
}
@keyframes swapping-squares-animation-child-2 {
50% {
transform: translate(-150%, 150%) scale(2, 2);
}
}
@keyframes swapping-squares-animation-child-3 {
50% {
transform: translate(-150%, -150%) scale(2, 2);
}
}
@keyframes swapping-squares-animation-child-4 {
50% {
transform: translate(150%, -150%) scale(2, 2);
}
}
`;
function generateSpinners(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="square" />
));
}
const SwappingSquaresSpinnerBase = ({
size = 65,
color = '#fff',
animationDuration = 1000,
className = '',
innerRef,
...props
}) => (
<SwappingSquare
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`swapping-squares-spinner${className ? ' ' + className : ''}`}
{...props}
>
{generateSpinners(4)}
</SwappingSquare>
);
export const SwappingSquaresSpinner = addRefProps(SwappingSquaresSpinnerBase);