Skip to content

Commit 34e4ab9

Browse files
Added ProgressBar components
1 parent 74292cf commit 34e4ab9

7 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```js
2+
<ProgressBarFill value={78} />
3+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import PropTypes from 'prop-types';
2+
import styled, { keyframes } from 'react-emotion';
3+
import withTheme from '../../ThemeContext/withTheme';
4+
5+
const bounce = keyframes`
6+
0% {
7+
left: 0;
8+
width: 30%;
9+
}
10+
11+
25% {
12+
width: 40%
13+
}
14+
15+
50% {
16+
left: 70%;
17+
width: 30%;
18+
}
19+
20+
75% {
21+
width: 40%;
22+
}
23+
24+
100% {
25+
left: 0;
26+
width: 30%;
27+
}
28+
`;
29+
30+
const ProgressBarFill = styled('div')({
31+
position: 'absolute',
32+
top: 0,
33+
left: 0,
34+
borderRadius: 100
35+
}, ({ color, value, indeterminate, theme }) => {
36+
const styles = [];
37+
38+
styles.push({
39+
height: theme.fontSize,
40+
backgroundColor: color || theme.primaryColor
41+
});
42+
43+
if (!indeterminate) {
44+
styles.push({
45+
width: `${value}%`
46+
});
47+
}
48+
49+
if (indeterminate) {
50+
styles.push({
51+
animation: `${bounce} 4s ease infinite`
52+
});
53+
}
54+
55+
return styles;
56+
});
57+
58+
ProgressBarFill.propTypes = {
59+
color: PropTypes.string,
60+
backgroundColor: PropTypes.string,
61+
value: PropTypes.number,
62+
indeterminate: PropTypes.bool
63+
};
64+
65+
ProgressBarFill.defaultProps = {
66+
value: 0,
67+
indeterminate: false
68+
};
69+
70+
export default withTheme(ProgressBarFill);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```js
2+
<ProgressBarWrapper>
3+
Foo Bar
4+
</ProgressBarWrapper>
5+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import PropTypes from 'prop-types';
2+
import styled from 'react-emotion';
3+
import { lightGrey } from '../../../colors';
4+
import withTheme from '../../ThemeContext/withTheme';
5+
6+
const ProgressBarWrapper = styled('div')({
7+
position: 'relative',
8+
background: lightGrey,
9+
borderRadius: 100,
10+
overflow: 'hidden'
11+
}, ({ backgroundColor, theme }) => ({
12+
height: theme.fontSize,
13+
backgroundColor
14+
}));
15+
16+
ProgressBarWrapper.propTypes = {
17+
backgroundColor: PropTypes.string
18+
};
19+
20+
ProgressBarWrapper.defaultProps = {
21+
backgroundColor: '#EEEEEE'
22+
};
23+
24+
export default withTheme(ProgressBarWrapper);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```js
2+
<ProgressBar value={57} />
3+
```
4+
5+
```js
6+
<ProgressBar color="#039BE5" value={78} />
7+
```
8+
9+
`indeterminate`:
10+
```js
11+
<ProgressBar indeterminate />
12+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import ProgressBarWrapper from './ProgressBarWrapper';
4+
import ProgressBarFill from './ProgressBarFill';
5+
6+
const ProgressBar = ({
7+
color,
8+
backgroundColor,
9+
value,
10+
fillProps,
11+
indeterminate,
12+
...props
13+
}) => (
14+
<ProgressBarWrapper {...props}>
15+
<ProgressBarFill
16+
color={color}
17+
backgroundColor={backgroundColor}
18+
value={value}
19+
indeterminate={indeterminate}
20+
{...fillProps}
21+
/>
22+
</ProgressBarWrapper>
23+
);
24+
25+
ProgressBar.propTypes = {
26+
color: PropTypes.string,
27+
backgroundColor: PropTypes.string,
28+
value: PropTypes.number,
29+
fillProps: PropTypes.object,
30+
indeterminate: PropTypes.bool
31+
};
32+
33+
ProgressBar.defaultProps = {
34+
backgroundColor: '#EEEEEE',
35+
value: 0,
36+
fillProps: null,
37+
indeterminate: false
38+
};
39+
40+
export default ProgressBar;

styleguide.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module.exports = {
5656
componentSection('Link'),
5757
componentSection('LoadingSpinner'),
5858
componentSection('SimpleLoadingSpinner'),
59+
componentSection('ProgressBar'),
5960
componentSection('Code'),
6061
componentSection('BlockQuote'),
6162
componentSection('Tabs'),

0 commit comments

Comments
 (0)