Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit e1ed43f

Browse files
committed
Adds ProgressButton component
1 parent a2f85bb commit e1ed43f

File tree

8 files changed

+180
-0
lines changed

8 files changed

+180
-0
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ A Storybook demo is available online at https://deskpro.github.io/deskpro-compon
7777
Renders a button with a left side and right side, where clicking the right side opens a popper.
7878
* [Buttons/DropdownButton](docs/components/buttons/dropdown_button.md)
7979
Renders a button with a drop down icon and popper.
80+
* [Buttons/ProgressButton](docs/components/buttons/progress_button.md)
81+
Renders a button which contains a progress bar.
8082

8183
### Columns
8284
* [Columns/Column](docs/components/columns/column.md)

Diff for: docs/assets/images/progress-button-1.png

1.96 KB
Loading

Diff for: docs/components/buttons/progress_button.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Buttons/ProgressButton
2+
======================
3+
Renders a button which contains a progress bar.
4+
5+
![Button example](../../assets/images/progress-button-1.png)
6+
7+
```jsx
8+
<div>
9+
<ProgressButton percent={50} size="large">
10+
6/12
11+
</ProgressButton>
12+
<ProgressButton percent={75} size="large">
13+
9/12
14+
</ProgressButton>
15+
<ProgressButton percent={100} size="large">
16+
12/12
17+
</ProgressButton>
18+
</div>
19+
```
20+
21+
### Props
22+
23+
**percent={number}**
24+
The percentage complete.
25+
26+
**size={string}**
27+
One of "small", "medium", or "large".
28+
29+
30+
### CSS
31+
Adds `dp-progress-button` to the root element.

Diff for: src/Components/Buttons/ProgressButton.jsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import classNames from 'classnames';
4+
import { objectKeyFilter } from 'utils/objects';
5+
import Progress from 'Components/Progress';
6+
import ProgressBar from 'Components/ProgressBar';
7+
8+
/**
9+
* Renders a button which contains a progress bar.
10+
*/
11+
export default class ProgressButton extends React.Component {
12+
static propTypes = {
13+
/**
14+
* The percentage complete.
15+
*/
16+
percent: PropTypes.number,
17+
/**
18+
* The button size.
19+
*/
20+
size: PropTypes.oneOf(['s', 'm', 'l', 'small', 'medium', 'large']),
21+
/**
22+
* CSS classes to apply to the element.
23+
*/
24+
className: PropTypes.string,
25+
/**
26+
* Children to render.
27+
*/
28+
children: PropTypes.node
29+
};
30+
31+
static defaultProps = {
32+
percent: 0,
33+
size: 'large'
34+
};
35+
36+
render() {
37+
const { percent, size, className, children, ...props } = this.props;
38+
39+
return (
40+
<div
41+
className={classNames('dp-progress-button', `dp-progress-button--${size[0]}`, className)}
42+
{...objectKeyFilter(props, ProgressButton.propTypes)}
43+
>
44+
<div className="dp-progress-button__label">
45+
{children}
46+
</div>
47+
<Progress size="small" type={percent < 100 ? 'primary' : 'cta'}>
48+
<ProgressBar percent={percent} />
49+
</Progress>
50+
</div>
51+
);
52+
}
53+
}

Diff for: src/Components/Buttons/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import ConfirmButton from './ConfirmButton';
33
import SplitButton from './SplitButton';
44
import ButtonPopper from './ButtonPopper';
55
import DropdownButton from './DropdownButton';
6+
import ProgressButton from './ProgressButton';
67

78
export {
89
Button,
910
ConfirmButton,
1011
SplitButton,
1112
ButtonPopper,
1213
DropdownButton,
14+
ProgressButton,
1315
};

Diff for: src/styles/components/_buttons.scss

+58
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,61 @@
258258
.dp-button--l.dp-dropdown-button .dp-icon {
259259
margin-left: 15px;
260260
}
261+
262+
263+
/// Progress Button
264+
///
265+
266+
.dp-progress-button {
267+
@extend .dp-button;
268+
@extend .dp-button--secondary;
269+
padding: 0;
270+
cursor: pointer;
271+
display: inline-block;
272+
background-color: $dp-greyscale-150;
273+
border-left: 1px solid $dp-greyscale-300;
274+
font-family: $primary-font;
275+
font-size: $font-size-s;
276+
font-weight: $pf-semi-bold;
277+
color: $dp-greyscale-850;
278+
279+
&, * {
280+
box-sizing: border-box;
281+
}
282+
283+
.dp-progress {
284+
background-color: $dp-greyscale-00;
285+
border-bottom-left-radius: $rad-size-m-l;
286+
border-bottom-right-radius: $rad-size-m-l;
287+
}
288+
}
289+
290+
291+
292+
.dp-progress-button--s {
293+
height: 26px;
294+
295+
.dp-progress-button__label {
296+
padding: 4px 6px;
297+
}
298+
299+
.dp-progress {
300+
height: 2px;
301+
}
302+
}
303+
304+
.dp-progress-button--m {
305+
height: 28px;
306+
307+
.dp-progress-button__label {
308+
padding: 4px 8px;
309+
}
310+
}
311+
312+
.dp-progress-button--l {
313+
height: 36px;
314+
315+
.dp-progress-button__label {
316+
padding: 8px 12px;
317+
}
318+
}

Diff for: tests/storybook/components/buttons/progress.jsx

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { withKnobs } from '@storybook/addon-knobs';
4+
import { ProgressButton } from 'Components/Buttons';
5+
6+
storiesOf('Buttons', module)
7+
.addDecorator(withKnobs)
8+
.add('with progress bar', () => {
9+
const sizes = ['small', 'medium', 'large'];
10+
11+
return (
12+
<div>
13+
{sizes.map(size => (
14+
<div style={{ marginBottom: 10 }}>
15+
<ProgressButton percent={50} size={size}>
16+
6/12
17+
</ProgressButton>
18+
&nbsp;&nbsp;
19+
<ProgressButton percent={75} size={size}>
20+
9/12
21+
</ProgressButton>
22+
&nbsp;&nbsp;
23+
<ProgressButton percent={100} size={size}>
24+
12/12
25+
</ProgressButton>
26+
</div>
27+
))}
28+
</div>
29+
);
30+
}
31+
)
32+
;

Diff for: tests/storybook/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import './components/buttons/icon';
1616
import './components/buttons/square';
1717
import './components/buttons/split';
1818
import './components/buttons/dropdown';
19+
import './components/buttons/progress';
1920
import './components/columns/column';
2021
import './components/common/count';
2122
import './components/common/heading';
@@ -28,3 +29,4 @@ import './components/lists/selectable';
2829
import './components/modal';
2930
import './components/urgency';
3031
import './components/progress';
32+

0 commit comments

Comments
 (0)