|
| 1 | +import React, {Component, PropTypes} from 'react'; |
| 2 | +import classNames from 'classnames'; |
| 3 | +import $ from 'jquery'; |
| 4 | +import META from 'src/utils/Meta'; |
| 5 | +import _ from 'lodash'; |
| 6 | + |
| 7 | +export default class Progress extends Component { |
| 8 | + static propTypes = { |
| 9 | + autoSuccess: PropTypes.bool, |
| 10 | + children: PropTypes.node, |
| 11 | + className: PropTypes.string, |
| 12 | + label: PropTypes.oneOf(['ratio', 'percent']), |
| 13 | + limitValues: PropTypes.bool, |
| 14 | + onActive: PropTypes.func, |
| 15 | + onChange: PropTypes.func, |
| 16 | + onError: PropTypes.func, |
| 17 | + onSuccess: PropTypes.func, |
| 18 | + onWarning: PropTypes.func, |
| 19 | + percent: PropTypes.number, |
| 20 | + precision: PropTypes.number, |
| 21 | + random: PropTypes.bool, |
| 22 | + showActivity: PropTypes.bool, |
| 23 | + total: PropTypes.bool, |
| 24 | + value: PropTypes.bool, |
| 25 | + }; |
| 26 | + |
| 27 | + componentDidMount() { |
| 28 | + this.element = $(this.refs.element); |
| 29 | + this.element.progress({ |
| 30 | + autoSuccess: this.props.autoSuccess, |
| 31 | + label: this.props.label, |
| 32 | + limitValues: this.props.limitValues, |
| 33 | + onActive: this.props.onActive, |
| 34 | + onChange: this.props.onChange, |
| 35 | + onError: this.props.onError, |
| 36 | + onSuccess: this.props.onSuccess, |
| 37 | + onWarning: this.props.onWarning, |
| 38 | + percent: this.props.percent, |
| 39 | + precision: this.props.precision, |
| 40 | + random: this.props.random, |
| 41 | + showActivity: this.props.showActivity, |
| 42 | + total: this.props.total, |
| 43 | + value: this.props.value, |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + static _meta = { |
| 48 | + library: META.library.stardust, |
| 49 | + name: 'Progress', |
| 50 | + type: META.type.module, |
| 51 | + }; |
| 52 | + |
| 53 | + plugin() { |
| 54 | + return this.element.progress(...arguments); |
| 55 | + } |
| 56 | + |
| 57 | + renderAttachedBar = () => { |
| 58 | + return ( |
| 59 | + <div className='bar' /> |
| 60 | + ); |
| 61 | + }; |
| 62 | + |
| 63 | + renderStandardBar = () => { |
| 64 | + const label = ( |
| 65 | + <div className='label'> |
| 66 | + {this.props.children} |
| 67 | + </div> |
| 68 | + ); |
| 69 | + |
| 70 | + return ( |
| 71 | + <div> |
| 72 | + <div className='bar'> |
| 73 | + <div className='progress'/> |
| 74 | + </div> |
| 75 | + {this.props.children && label} |
| 76 | + </div> |
| 77 | + ); |
| 78 | + }; |
| 79 | + |
| 80 | + render() { |
| 81 | + const classes = classNames( |
| 82 | + 'sd-progress', |
| 83 | + 'ui', |
| 84 | + this.props.className, |
| 85 | + 'progress', |
| 86 | + ); |
| 87 | + |
| 88 | + const isAttached = _.contains(this.props.className, 'attached'); |
| 89 | + return ( |
| 90 | + <div {...this.props} className={classes}> |
| 91 | + {isAttached ? this.renderAttachedBar() : this.renderStandardBar()} |
| 92 | + </div> |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments