Skip to content

Commit 38cb1b0

Browse files
committed
Migrate ProgressBar to themr
1 parent e5ef5e2 commit 38cb1b0

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

components/progress_bar/ProgressBar.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import ClassNames from 'classnames';
3-
import style from './style';
2+
import classnames from 'classnames';
3+
import { themr } from 'react-css-themr';
44
import prefixer from '../utils/prefixer';
55

66
class ProgressBar extends React.Component {
@@ -9,8 +9,18 @@ class ProgressBar extends React.Component {
99
className: React.PropTypes.string,
1010
max: React.PropTypes.number,
1111
min: React.PropTypes.number,
12-
mode: React.PropTypes.string,
12+
mode: React.PropTypes.oneOf(['determinate', 'indeterminate']),
1313
multicolor: React.PropTypes.bool,
14+
theme: React.PropTypes.shape({
15+
buffer: React.PropTypes.string.isRequired,
16+
circle: React.PropTypes.string.isRequired,
17+
circular: React.PropTypes.string.isRequired,
18+
indeterminate: React.PropTypes.string.isRequired,
19+
linear: React.PropTypes.string.isRequired,
20+
multicolor: React.PropTypes.string.isRequired,
21+
path: React.PropTypes.string.isRequired,
22+
value: React.PropTypes.string.isRequired
23+
}),
1424
type: React.PropTypes.oneOf(['linear', 'circular']),
1525
value: React.PropTypes.number
1626
};
@@ -51,8 +61,8 @@ class ProgressBar extends React.Component {
5161

5262
renderCircular () {
5363
return (
54-
<svg className={style.circle}>
55-
<circle className={style.path} style={this.circularStyle()} cx='30' cy='30' r='25' />
64+
<svg className={this.props.theme.circle}>
65+
<circle className={this.props.theme.path} style={this.circularStyle()} cx='30' cy='30' r='25' />
5666
</svg>
5767
);
5868
}
@@ -61,30 +71,31 @@ class ProgressBar extends React.Component {
6171
const {buffer, value} = this.linearStyle();
6272
return (
6373
<div>
64-
<span ref='buffer' data-ref='buffer' className={style.buffer} style={buffer}></span>
65-
<span ref='value' data-ref='value' className={style.value} style={value}></span>
74+
<span ref='buffer' data-ref='buffer' className={this.props.theme.buffer} style={buffer}></span>
75+
<span ref='value' data-ref='value' className={this.props.theme.value} style={value}></span>
6676
</div>
6777
);
6878
}
6979

7080
render () {
71-
const className = ClassNames(style[this.props.type], {
72-
[style[this.props.mode]]: this.props.mode,
73-
[style.multicolor]: this.props.multicolor
74-
}, this.props.className);
81+
const { className, max, min, mode, multicolor, type, theme, value } = this.props;
82+
const _className = classnames(theme[type], {
83+
[theme[mode]]: mode,
84+
[theme.multicolor]: multicolor
85+
}, className);
7586

7687
return (
7788
<div
7889
data-react-toolbox='progress-bar'
79-
aria-valuenow={this.props.value}
80-
aria-valuemin={this.props.min}
81-
aria-valuemax={this.props.max}
82-
className={className}
90+
aria-valuenow={value}
91+
aria-valuemin={min}
92+
aria-valuemax={max}
93+
className={_className}
8394
>
84-
{this.props.type === 'circular' ? this.renderCircular() : this.renderLinear()}
95+
{type === 'circular' ? this.renderCircular() : this.renderLinear()}
8596
</div>
8697
);
8798
}
8899
}
89100

90-
export default ProgressBar;
101+
export default themr('ToolboxProgress')(ProgressBar);

components/progress_bar/readme.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Minimize visual changes that occur while your app loads content by representing
55
<!-- example -->
66
```jsx
77
import ProgressBar from 'react-toolbox/lib/progress_bar';
8+
import theme from 'react-toolbox/lib/progress_bar/theme';
89

910
const ProgressTest = () => (
1011
<div>
11-
<ProgressBar type="circular" mode="indeterminate" />
12-
<ProgressBar type="linear" mode="determinate" value={83} buffer={90}/>
12+
<ProgressBar type="circular" mode="indeterminate" theme={theme} />
13+
<ProgressBar type="linear" mode="determinate" value={83} buffer={90} theme={theme} />
1314
</div>
1415
);
1516
```
@@ -27,3 +28,17 @@ const ProgressTest = () => (
2728
| `type` | `String` | `linear` | Type of the progress bar, it can be `circular` or `linear`.|
2829
| `value` | `Number` | `0` | Value of the current progress.|
2930

31+
## Theming
32+
33+
You can take a look to the `_config.scss` variables. The themed key for this component is `ToolboxProgress`, it should implement the following interface:
34+
35+
| Name | Description|
36+
|:---------|:-----------|
37+
| `buffer` | Used to style the buffer element in the linear progress.|
38+
| `circle` | Used for the circle element in the circular progress.|
39+
| `circular` | Used for the root element when the type is circular.|
40+
| `indeterminate` | Added to the root element if mode is indeterminate.|
41+
| `linear` | Used for the root element when the type is linear.|
42+
| `multicolor` | Added to the root if the component is multicolor (circular).|
43+
| `path` | Used for the inner path in the circular progress.|
44+
| `value` | Used to style the value element in the linear progress.|

spec/theme.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ToolboxList from '../components/list/theme.scss';
1717
import ToolboxMenu from '../components/menu/theme.scss';
1818
import ToolboxNavigation from '../components/navigation/theme.scss';
1919
import ToolboxOverlay from '../components/overlay/theme.scss';
20+
import ToolboxProgress from '../components/progress_bar/theme.scss';
2021
import ToolboxRipple from '../components/ripple/theme.scss';
2122
import ToolboxTimePicker from '../components/time_picker/theme.scss';
2223

@@ -39,6 +40,7 @@ export default defineTheme({
3940
ToolboxMenu,
4041
ToolboxNavigation,
4142
ToolboxOverlay,
43+
ToolboxProgress,
4244
ToolboxRipple,
4345
ToolboxTimePicker
4446
});

0 commit comments

Comments
 (0)