import classNames from 'classnames'
import PropTypes from '../_util/vue-types'
import { getOptionProps, initDefaultProps } from '../_util/props-util'
import Icon from '../icon'
import { Circle } from '../vc-progress'
function addUnit (num, unit) {
const unitType = unit || 'px'
return num ? num + unitType : null
}
const statusColorMap = {
normal: '#108ee9',
exception: '#ff5500',
success: '#87d068',
}
export const ProgressType = PropTypes.oneOf(['line', 'circle', 'dashboard'])
export const ProgressSize = PropTypes.oneOf(['default', 'small'])
export const ProgressProps = {
prefixCls: PropTypes.string,
type: ProgressType,
percent: PropTypes.number,
successPercent: PropTypes.number,
format: PropTypes.func,
status: PropTypes.oneOf(['normal', 'success', 'active', 'exception']),
showInfo: PropTypes.bool,
strokeWidth: PropTypes.number,
strokeLinecap: PropTypes.oneOf(['round', 'square']),
strokeColor: PropTypes.string,
trailColor: PropTypes.string,
width: PropTypes.number,
gapDegree: PropTypes.number,
gapPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
size: ProgressSize,
}
const validProgress = (progress) => {
if (!progress || progress < 0) {
return 0
} else if (progress > 100) {
return 100
}
return progress
}
export default {
name: 'AProgress',
props: initDefaultProps(ProgressProps, {
type: 'line',
percent: 0,
showInfo: true,
trailColor: '#f3f3f3',
prefixCls: 'ant-progress',
size: 'default',
}),
render () {
const props = getOptionProps(this)
const {
prefixCls, percent = 0, status, format, trailColor, size, successPercent,
type, strokeWidth, width, showInfo, gapDegree = 0, gapPosition, strokeColor, strokeLinecap = 'round',
...restProps
} = props
const progressStatus = parseInt((successPercent ? successPercent.toString() : percent.toString()), 10) >= 100 &&
!('status' in props) ? 'success' : (status || 'normal')
let progressInfo
let progress
const textFormatter = format || (percentNumber => `${percentNumber}%`)
if (showInfo) {
let text
const iconType = (type === 'circle' || type === 'dashboard') ? '' : '-circle'
if (format || (progressStatus !== 'exception' && progressStatus !== 'success')) {
text = textFormatter(validProgress(percent), validProgress(successPercent))
} else if (progressStatus === 'exception') {
text =