-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathProgressBar copy.js
109 lines (100 loc) · 3.12 KB
/
ProgressBar copy.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
/* eslint-disable no-unused-vars */
import React from 'react';
import styled from 'styled-components';
import { COLORS } from '../../constants';
import VisuallyHidden from '../VisuallyHidden';
const SIZES = {
small: {
"--wrapperHeight": "8px",
"--innerHeight": "8px",
"--borderRadius": "4px",
},
medium: {
"--wrapperHeight": "12px",
"--innerHeight": "12px",
"--borderRadius": "4px",
},
large: {
"--wrapperHeight": "24px",
"--innerHeight": "16px",
"--padding": "4px",
"--borderRadius": "8px",
},
}
const ProgressWrapper = styled.div`
max-width: 370px;
width: 100%;
height: var(--wrapperHeight);
color: ${COLORS.transparentGray15};
box-shadow: inset 0px 2px 4px ${COLORS.transparentGray35};
padding: var(--padding);
border-radius: var(--borderRadius);
background-color: ${COLORS.transparentGray15};
`
const ProgressInner = styled(ProgressWrapper)`
background-color: ${COLORS.primary};
width: ${props => props.value}%;
border-radius: ${p => p.value >= 99 ? `4px` : `4px 0 0 4px`};
height: var(--innerHeight);
`
const ProgressAlt = styled.div`
progress[value] {
appearance: none;
-webkit-appearance: none;
width: 100%;
max-width: 370px;
::-webkit-progress-bar {
background-color: ${COLORS.transparentGray15};
border-radius: var(--borderRadius);
box-shadow: inset 0px 2px 4px ${COLORS.transparentGray35};
height: var(--wrapperHeight);
padding: var(--padding);
}
::-webkit-progress-value {
background-color: ${COLORS.primary};
border-radius: ${p => p.value >= 99 ? `4px` : `4px 0 0 4px`};
height: var(--innerHeight);
width: ${props => props.value}%;
}
}
`
const ProgressAlt2 = styled.progress`
&[value] {
appearance: none;
-webkit-appearance: none;
width: 100%;
max-width: 370px;
::-webkit-progress-bar {
background-color: ${COLORS.transparentGray15};
border-radius: var(--borderRadius);
box-shadow: inset 0px 2px 4px ${COLORS.transparentGray35};
height: var(--wrapperHeight);
padding: var(--padding);
}
::-webkit-progress-value {
background-color: ${COLORS.primary};
border-radius: ${p => p.value >= 99 ? `4px` : `4px 0 0 4px`};
height: var(--innerHeight);
width: ${props => props.value}%;
}
}
`
const ProgressBar = ({ value, size }) => {
const styles = SIZES[size];
return <>
Three different solutions. All work. However, the third appears to be the "simplest".
<p>First solution - `div` wrapping a `div`</p>
<ProgressWrapper style={styles} role="progressbar" aria-valuenow={value} >
<ProgressInner style={styles} value={value} />
</ProgressWrapper>
<p>Second solution - `div` wrapping a `progress` element </p>
<ProgressAlt value={value}>
<progress style={styles} value={value} max={100} aria-valuenow={value}/>
</ProgressAlt>
<div style={{height: '10px'}}></div>
<p>A "pure" `progress` element. </p>
<ProgressAlt2 value={value} style={styles} max={100} aria-valuenow={value}/>
<VisuallyHidden>{value}%</VisuallyHidden>
</>;
};
export default ProgressBar;