-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (64 loc) · 1.89 KB
/
Copy pathindex.js
File metadata and controls
70 lines (64 loc) · 1.89 KB
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
import PropTypes from "prop-types";
import React from "react";
import styled, { keyframes } from "styled-components";
const motion = props => keyframes`
0% {
width: ${props.size / 20}${props.sizeUnit}
}
50% {
width: ${props.size / 6}${props.sizeUnit}
}
100% {
width: ${props.size / 20}${props.sizeUnit}
}
`;
const getBars = (countBars, color, size, sizeUnit) => {
const bars = [];
for (let i = 0; i < countBars; i++) {
bars.push(
<Bar
color={color}
size={size}
sizeUnit={sizeUnit}
x={i * (size / 5 + size / 25) - size / 12}
key={i.toString()}
index={i}
/>,
);
}
return bars;
};
export const BarsSpinner = ({ size = 40, color = "#00ff89", loading = true, sizeUnit = "px" }) => {
const countBars = 5;
return (
loading && (
<Wrapper size={size} sizeUnit={sizeUnit}>
{getBars(countBars, color, size, sizeUnit)}
</Wrapper>
)
);
};
const Wrapper = styled.div`
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: ${props => `${props.size}${props.sizeUnit}`};
height: ${props => `${props.size}${props.sizeUnit}`};
`;
const Bar = styled.div`
position: absolute;
top: ${props => `${props.y}${props.sizeUnit}`};
left: ${props => `${props.x}${props.sizeUnit}`};
width: ${props => `${props.size / 20}${props.sizeUnit}`};
height: ${props => `${props.size}${props.sizeUnit}`};
background-color: ${props => props.color};
animation: ${motion} 1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
animation-delay: ${props => props.index * 0.15}s;
`;
BarsSpinner.propTypes = {
loading: PropTypes.bool,
size: PropTypes.number,
color: PropTypes.string,
sizeUnit: PropTypes.string,
};