acud
Version:
acg react 组件库
77 lines • 3.69 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
/**
* @file 进度条
* @author liuhanwei
*/
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import React, { useContext } from 'react';
import LineProgress from './LineProgress';
import CircleProgress from './CircleProgress';
import SizeContext from '../config-provider/SizeContext';
import { ConfigContext } from '../config-provider';
import { sizeRatioMap, statusColorMap, isHexColor, isNumber } from './common';
var Progress = function Progress(_a) {
var _a$percent = _a.percent,
customizePercent = _a$percent === void 0 ? 0 : _a$percent,
_a$type = _a.type,
type = _a$type === void 0 ? 'line' : _a$type,
_a$size = _a.size,
customizeSize = _a$size === void 0 ? 'middle' : _a$size,
_a$status = _a.status,
customizeStatus = _a$status === void 0 ? 'active' : _a$status,
customizeStrokeColor = _a.strokeColor,
customizeTextColor = _a.textColor,
customizeTextSize = _a.textSize,
_a$successStyle = _a.successStyle,
successStyle = _a$successStyle === void 0 ? {} : _a$successStyle,
format = _a.format,
customizePrefixCls = _a.prefixCls,
restProps = __rest(_a, ["percent", "type", "size", "status", "strokeColor", "textColor", "textSize", "successStyle", "format", "prefixCls"]);
var _useContext = useContext(ConfigContext),
getPrefixCls = _useContext.getPrefixCls;
var prefixCls = getPrefixCls('progress', customizePrefixCls);
var defaultSize = useContext(SizeContext) || 'small';
// size取值异常时,将使用全局size或默认值small
var size = customizeSize in sizeRatioMap ? customizeSize : defaultSize;
// percent取值异常时,将使用默认值0
var percent = isNumber(customizePercent) ? customizePercent : 0;
// status取值异常时,将使用默认值active
var status = customizeStatus in statusColorMap ? customizeStatus : 'active';
// strokeColor取值异常时,将使用status对应的颜色
var strokeColor = isHexColor(customizeStrokeColor) ? customizeStrokeColor : '';
var iconStrokeColor = strokeColor || statusColorMap[status];
// 解构进度100时的样式
var successStrokeColor = successStyle.strokeColor,
successTextColor = successStyle.textColor,
successTextSize = successStyle.textSize;
var textColor = customizeTextColor;
var textSize = customizeTextSize;
// 当进度100时,若存在完成时的样式,则使用该样式
if (percent === 100) {
strokeColor = isHexColor(successStrokeColor) ? successStrokeColor : strokeColor;
textColor = isHexColor(successTextColor) ? successTextColor : textColor;
textSize = isNumber(successTextSize) ? successTextSize : textSize;
}
// 若存在format方法,则格式化文本
var labelText = format instanceof Function ? format(percent) : "".concat(percent, "%");
var props = {
percent: percent,
size: size,
status: status,
strokeColor: strokeColor,
iconStrokeColor: iconStrokeColor,
textColor: textColor,
textSize: textSize,
labelText: labelText,
prefixCls: prefixCls
};
return type === 'circle' ? /*#__PURE__*/React.createElement(CircleProgress, _extends({}, props, restProps)) : /*#__PURE__*/React.createElement(LineProgress, _extends({}, props, restProps));
};
export default Progress;