-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathProgressBar.js
77 lines (67 loc) · 1.5 KB
/
ProgressBar.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
/* eslint-disable no-unused-vars */
import React from 'react';
import styled from 'styled-components';
import { COLORS } from '../../constants';
import VisuallyHidden from '../VisuallyHidden';
const STYLES = {
small: {
height: 8,
padding: 0,
radius: 4,
},
medium: {
height: 12,
padding: 0,
radius: 4,
},
large: {
height: 16,
padding: 4,
radius: 8,
},
};
const ProgressBar = ({ value, size }) => {
const styles = STYLES[size];
if (!styles) {
throw new Error(`Unknown size passed to ProgressBar: ${size}`);
}
return (
<Wrapper
role="progressbar"
aria-valuenow={value}
aria-valuemin="0"
aria-valuemax="100"
style={{
'--padding': styles.padding + 'px',
'--radius': styles.radius + 'px',
}}
>
<VisuallyHidden>{value}%</VisuallyHidden>
<BarWrapper>
<Bar
style={{
'--width': value + '%',
'--height': styles.height + 'px',
}}
/>
</BarWrapper>
</Wrapper>
);
};
const Wrapper = styled.div`
background-color: ${COLORS.transparentGray15};
box-shadow: inset 0px 2px 4px ${COLORS.transparentGray35};
border-radius: var(--radius);
padding: var(--padding);
`;
const BarWrapper = styled.div`
border-radius: 4px;
/* Trim off corners when progress bar is near-full. */
overflow: hidden;
`;
const Bar = styled.div`
width: var(--width);
height: var(--height);
background-color: ${COLORS.primary};
`;
export default ProgressBar;