-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
PixelSpinner.js
109 lines (99 loc) · 3.2 KB
/
PixelSpinner.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 React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const Pixels = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
* {
box-sizing: border-box;
}
.pixel-spinner-inner {
width: ${(props) => props.pixelSize}px;
height: ${(props) => props.pixelSize}px;
background-color: ${(props) => props.color};
color: ${(props) => props.color};
box-shadow: ${(props) => props.pixelSize * 1.5}px
${(props) => props.pixelSize * 1.5}px 0 0,
${(props) => props.pixelSize * -1.5}px
${(props) => props.pixelSize * -1.5}px 0 0,
${(props) => props.pixelSize * 1.5}px
${(props) => props.pixelSize * -1.5}px 0 0,
${(props) => props.pixelSize * -1.5}px
${(props) => props.pixelSize * 1.5}px 0 0,
0 ${(props) => props.pixelSize * 1.5}px 0 0,
${(props) => props.pixelSize * 1.5}px 0 0 0,
${(props) => props.pixelSize * -1.5}px 0 0 0,
0 ${(props) => props.pixelSize * -1.5}px 0 0;
animation: pixel-spinner-animation ${(props) => props.animationDuration}ms
linear infinite;
}
@keyframes pixel-spinner-animation {
50% {
box-shadow: ${(props) => props.pixelSize * 2}px
${(props) => props.pixelSize * 2}px 0 0,
${(props) => props.pixelSize * -2}px
${(props) => props.pixelSize * -2}px 0 0,
${(props) => props.pixelSize * 2}px ${(props) => props.pixelSize * -2}px
0 0,
${(props) => props.pixelSize * -2}px ${(props) => props.pixelSize * 2}px
0 0,
0 ${(props) => props.pixelSize}px 0 0,
${(props) => props.pixelSize}px 0 0 0,
${(props) => props.pixelSize * -1}px 0 0 0,
0 ${(props) => props.pixelSize * -1}px 0 0;
}
75% {
box-shadow: ${(props) => props.pixelSize * 2}px
${(props) => props.pixelSize * 2}px 0 0,
${(props) => props.pixelSize * -2}px
${(props) => props.pixelSize * -2}px 0 0,
${(props) => props.pixelSize * 2}px ${(props) => props.pixelSize * -2}px
0 0,
${(props) => props.pixelSize * -2}px ${(props) => props.pixelSize * 2}px
0 0,
0 ${(props) => props.pixelSize}px 0 0,
${(props) => props.pixelSize}px 0 0 0,
${(props) => props.pixelSize * -1}px 0 0 0,
0 ${(props) => props.pixelSize * -1}px 0 0;
}
100% {
transform: rotate(360deg);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
const PixelSpinner = ({
size = 70,
color = '#fff',
animationDuration = 1500,
className = '',
style,
...props
}) => {
const pixelSize = size / 7;
return (
<Pixels
size={size}
color={color}
animationDuration={animationDuration}
className={`pixel-spinner${className ? ' ' + className : ''}`}
style={style}
pixelSize={pixelSize}
{...props}
>
<div className="pixel-spinner-inner" />
</Pixels>
);
};
PixelSpinner.propTypes = propTypes;
export default PixelSpinner;