Skip to content

Commit 10ee0d1

Browse files
authored
Merge pull request #441 from facultyai/progress-height
Fix progress style argument.
2 parents cd2ddc8 + 563fcc9 commit 10ee0d1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/components/Progress.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import {Progress as RSProgress} from 'reactstrap';
55

6+
const CustomProgressTag = props => {
7+
// This is a little trick to enable us to pass styles to the outer div
8+
const {outer_style, style, ...otherProps} = props;
9+
return <div style={outer_style} {...otherProps} />;
10+
};
11+
612
/**
713
* A component for creating progress bars just with CSS. Control the current
814
* progress with a callback and the `value` prop.
915
*/
1016
const Progress = props => {
11-
const {children, loading_state, ...otherProps} = props;
17+
const {children, loading_state, bar_style, style, ...otherProps} = props;
1218
return (
1319
<RSProgress
1420
{...omit(['setProps'], otherProps)}
1521
data-dash-is-loading={
1622
(loading_state && loading_state.is_loading) || undefined
1723
}
24+
// reactstrap handles these inconsistently atm, have to swap around
25+
style={bar_style}
26+
outer_style={style}
27+
tag={CustomProgressTag}
1828
>
1929
{children}
2030
</RSProgress>
@@ -97,6 +107,11 @@ Progress.propTypes = {
97107
*/
98108
barClassName: PropTypes.string,
99109

110+
/**
111+
* Style arguments to pass to the bar.
112+
*/
113+
bar_style: PropTypes.object,
114+
100115
/**
101116
* Object that holds the loading state object coming from dash-renderer
102117
*/

src/components/__tests__/Progress.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,24 @@ describe('Progress', () => {
8585

8686
expect(progressAnimated.firstChild).toHaveClass('progress-bar-animated');
8787
});
88+
89+
test('sets className and style on the progress container and the bar', () => {
90+
const {
91+
container: {firstChild: progress}
92+
} = render(
93+
<Progress
94+
style={{height: '40px'}}
95+
className="outer"
96+
bar_style={{color: 'chartreuse'}}
97+
barClassName="inner"
98+
/>
99+
);
100+
101+
expect(progress).toHaveClass('outer');
102+
expect(progress).toHaveStyle('height:40px');
103+
104+
expect(progress.firstChild).toHaveClass('progress-bar');
105+
expect(progress.firstChild).toHaveClass('inner');
106+
expect(progress.firstChild).toHaveStyle('color:chartreuse');
107+
});
88108
});

0 commit comments

Comments
 (0)