-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from TechnologyAdvice/feature/progress
Add Progress Component
- Loading branch information
Showing
5 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
import $ from 'jquery'; | ||
import META from 'src/utils/Meta'; | ||
import _ from 'lodash'; | ||
|
||
export default class Progress extends Component { | ||
static propTypes = { | ||
autoSuccess: PropTypes.bool, | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
label: PropTypes.oneOf(['ratio', 'percent']), | ||
limitValues: PropTypes.bool, | ||
onActive: PropTypes.func, | ||
onChange: PropTypes.func, | ||
onError: PropTypes.func, | ||
onSuccess: PropTypes.func, | ||
onWarning: PropTypes.func, | ||
percent: PropTypes.number, | ||
precision: PropTypes.number, | ||
random: PropTypes.bool, | ||
showActivity: PropTypes.bool, | ||
total: PropTypes.bool, | ||
value: PropTypes.bool, | ||
}; | ||
|
||
componentDidMount() { | ||
this.element = $(this.refs.element); | ||
this.element.progress({ | ||
autoSuccess: this.props.autoSuccess, | ||
label: this.props.label, | ||
limitValues: this.props.limitValues, | ||
onActive: this.props.onActive, | ||
onChange: this.props.onChange, | ||
onError: this.props.onError, | ||
onSuccess: this.props.onSuccess, | ||
onWarning: this.props.onWarning, | ||
percent: this.props.percent, | ||
precision: this.props.precision, | ||
random: this.props.random, | ||
showActivity: this.props.showActivity, | ||
total: this.props.total, | ||
value: this.props.value, | ||
}); | ||
} | ||
|
||
static _meta = { | ||
library: META.library.stardust, | ||
name: 'Progress', | ||
type: META.type.module, | ||
}; | ||
|
||
plugin() { | ||
return this.element.progress(...arguments); | ||
} | ||
|
||
renderAttachedBar = () => { | ||
return ( | ||
<div className='bar' /> | ||
); | ||
}; | ||
|
||
renderStandardBar = () => { | ||
const label = ( | ||
<div className='label'> | ||
{this.props.children} | ||
</div> | ||
); | ||
|
||
return ( | ||
<div> | ||
<div className='bar'> | ||
<div className='progress'/> | ||
</div> | ||
{this.props.children && label} | ||
</div> | ||
); | ||
}; | ||
|
||
render() { | ||
const classes = classNames( | ||
'sd-progress', | ||
'ui', | ||
this.props.className, | ||
'progress', | ||
); | ||
|
||
const isAttached = _.contains(this.props.className, 'attached'); | ||
return ( | ||
<div {...this.props} className={classes}> | ||
{isAttached ? this.renderAttachedBar() : this.renderStandardBar()} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import {Progress} from 'stardust'; | ||
|
||
describe.only('Progress', () => { | ||
it('should be able to receive children', () => { | ||
render( | ||
<Progress> | ||
Child | ||
</Progress> | ||
).assertText('Child'); | ||
}); | ||
|
||
it('should create a div with the class of bar', () => { | ||
render(<Progress />).findClass('bar'); | ||
}); | ||
|
||
it('should create two progress divs if un-attached', () => { | ||
render(<Progress />) | ||
.scryClass('progress') | ||
.should.have.a.lengthOf(2); | ||
}); | ||
|
||
it('should not create extra progress div if attached', () => { | ||
render(<Progress className='attached' />) | ||
.scryClass('progress') | ||
.should.have.a.lengthOf(1); | ||
}); | ||
}); |