Skip to content

Commit 25fdb77

Browse files
TheSharpieOneeddywashere
authored andcommitted
fix(Progress): add custom classNames to progress-bar (#319)
fixes #318 will now be passed through to with prop allows similar pass through on single bars can also be used with prop and will act as in place of for convenience
1 parent faa86a7 commit 25fdb77

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

docs/lib/Components/ProgressPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export default class ProgressPage extends React.Component {
5050
animated: PropTypes.bool,
5151
stripped: PropTypes.bool,
5252
color: PropTypes.string,
53-
className: PropTypes.string
53+
className: PropTypes.string,
54+
barClassName: PropTypes.string // used to add class to the inner progress-bar element
5455
};
5556
5657
Progress.defaultProps = {

src/Progress.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const propTypes = {
2020
striped: PropTypes.bool,
2121
color: PropTypes.string,
2222
className: PropTypes.string,
23+
barClassName: PropTypes.string,
2324
cssModule: PropTypes.object,
2425
};
2526

@@ -33,6 +34,7 @@ const Progress = (props) => {
3334
const {
3435
children,
3536
className,
37+
barClassName,
3638
cssModule,
3739
value,
3840
max,
@@ -54,6 +56,7 @@ const Progress = (props) => {
5456

5557
const progressBarClasses = mapToCssModules(classNames(
5658
'progress-bar',
59+
bar ? className || barClassName : barClassName,
5760
animated ? 'progress-bar-animated' : null,
5861
color ? `bg-${color}` : null,
5962
striped || animated ? 'progress-bar-striped' : null

src/__tests__/Progress.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ describe('Progress', () => {
7777
expect(wrapper.hasClass('progress')).toBe(true);
7878
});
7979

80+
it('should render additional classes on the inner progress bar', () => {
81+
const wrapper = shallow(<Progress barClassName="other" />);
82+
83+
expect(wrapper.hasClass('other')).toBe(false);
84+
expect(wrapper.hasClass('progress')).toBe(true);
85+
expect(wrapper.find('.progress-bar').hasClass('other')).toBe(true);
86+
});
87+
8088
it('should render custom tag', () => {
8189
const wrapper = shallow(<Progress tag="main" />);
8290

@@ -97,6 +105,22 @@ describe('Progress', () => {
97105
expect(wrapper.hasClass('progress-bar')).toBe(true);
98106
});
99107

108+
it('should render additional classes', () => {
109+
const wrapper = shallow(<Progress bar className="yo" />);
110+
111+
expect(wrapper.type()).toBe('div');
112+
expect(wrapper.hasClass('progress-bar')).toBe(true);
113+
expect(wrapper.hasClass('yo')).toBe(true);
114+
});
115+
116+
it('should render additional classes using the barClassName', () => {
117+
const wrapper = shallow(<Progress bar barClassName="yo" />);
118+
119+
expect(wrapper.type()).toBe('div');
120+
expect(wrapper.hasClass('progress-bar')).toBe(true);
121+
expect(wrapper.hasClass('yo')).toBe(true);
122+
});
123+
100124
it('should render the children (label)', () => {
101125
const wrapper = shallow(<Progress>0%</Progress>);
102126

0 commit comments

Comments
 (0)