-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ScalingSquaresSpinner.js
110 lines (102 loc) · 2.69 KB
/
ScalingSquaresSpinner.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
110
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const ScalingSquares = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
animation: scaling-squares-animation ${(props) => props.animationDuration}ms;
animation-iteration-count: infinite;
transform: rotate(0deg);
* {
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);
margin-right: auto;
margin-left: auto;
border: calc(${(props) => props.size}px * 0.04 / 1.3) solid
${(props) => props.color};
position: absolute;
animation-duration: ${(props) => props.animationDuration}ms;
animation-iteration-count: infinite;
}
.square:nth-child(1) {
animation-name: scaling-squares-spinner-animation-child-1;
}
.square:nth-child(2) {
animation-name: scaling-squares-spinner-animation-child-2;
}
.square:nth-child(3) {
animation-name: scaling-squares-spinner-animation-child-3;
}
.square:nth-child(4) {
animation-name: scaling-squares-spinner-animation-child-4;
}
@keyframes scaling-squares-animation {
50% {
transform: rotate(90deg);
}
100% {
transform: rotate(180deg);
}
}
@keyframes scaling-squares-spinner-animation-child-1 {
50% {
transform: translate(150%, 150%) scale(2, 2);
}
}
@keyframes scaling-squares-spinner-animation-child-2 {
50% {
transform: translate(-150%, 150%) scale(2, 2);
}
}
@keyframes scaling-squares-spinner-animation-child-3 {
50% {
transform: translate(-150%, -150%) scale(2, 2);
}
}
@keyframes scaling-squares-spinner-animation-child-4 {
50% {
transform: translate(150%, -150%) scale(2, 2);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
function generateSpinners(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="square" />
));
}
const ScalingSquaresSpinner = ({
size = 65,
color = '#fff',
animationDuration = 1250,
className = '',
style,
...props
}) => (
<ScalingSquares
size={size}
color={color}
animationDuration={animationDuration}
className={`scaling-squares-spinner${className ? ' ' + className : ''}`}
style={style}
{...props}
>
{generateSpinners(4)}
</ScalingSquares>
);
ScalingSquaresSpinner.propTypes = propTypes;
export default ScalingSquaresSpinner;