1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4 | var __rest = this && this.__rest || function (s, e) {
|
5 | var t = {};
|
6 | for (var p in s) {
|
7 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
8 | }
|
9 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
10 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
11 | }
|
12 | return t;
|
13 | };
|
14 | import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
|
15 | import CheckOutlined from "@ant-design/icons/es/icons/CheckOutlined";
|
16 | import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
|
17 | import CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined";
|
18 | import classNames from 'classnames';
|
19 | import omit from "rc-util/es/omit";
|
20 | import * as React from 'react';
|
21 | import { ConfigContext } from '../config-provider';
|
22 | import { tuple } from '../_util/type';
|
23 | import warning from '../_util/warning';
|
24 | import Circle from './Circle';
|
25 | import Line from './Line';
|
26 | import Steps from './Steps';
|
27 | import { getSuccessPercent, validProgress } from './utils';
|
28 | import useStyle from './style';
|
29 | var ProgressTypes = tuple('line', 'circle', 'dashboard');
|
30 | var ProgressStatuses = tuple('normal', 'exception', 'active', 'success');
|
31 | var Progress = function Progress(props) {
|
32 | var _classNames;
|
33 | var customizePrefixCls = props.prefixCls,
|
34 | className = props.className,
|
35 | steps = props.steps,
|
36 | strokeColor = props.strokeColor,
|
37 | _props$percent = props.percent,
|
38 | percent = _props$percent === void 0 ? 0 : _props$percent,
|
39 | _props$size = props.size,
|
40 | size = _props$size === void 0 ? 'default' : _props$size,
|
41 | _props$showInfo = props.showInfo,
|
42 | showInfo = _props$showInfo === void 0 ? true : _props$showInfo,
|
43 | _props$type = props.type,
|
44 | type = _props$type === void 0 ? 'line' : _props$type,
|
45 | status = props.status,
|
46 | format = props.format,
|
47 | restProps = __rest(props, ["prefixCls", "className", "steps", "strokeColor", "percent", "size", "showInfo", "type", "status", "format"]);
|
48 | var percentNumber = React.useMemo(function () {
|
49 | var successPercent = getSuccessPercent(props);
|
50 | return parseInt(successPercent !== undefined ? successPercent.toString() : percent.toString(), 10);
|
51 | }, [percent, props.success, props.successPercent]);
|
52 | var progressStatus = React.useMemo(function () {
|
53 | if (!ProgressStatuses.includes(status) && percentNumber >= 100) {
|
54 | return 'success';
|
55 | }
|
56 | return status || 'normal';
|
57 | }, [status, percentNumber]);
|
58 | var _React$useContext = React.useContext(ConfigContext),
|
59 | getPrefixCls = _React$useContext.getPrefixCls,
|
60 | direction = _React$useContext.direction;
|
61 | var prefixCls = getPrefixCls('progress', customizePrefixCls);
|
62 | var _useStyle = useStyle(prefixCls),
|
63 | _useStyle2 = _slicedToArray(_useStyle, 2),
|
64 | wrapSSR = _useStyle2[0],
|
65 | hashId = _useStyle2[1];
|
66 | var progressInfo = React.useMemo(function () {
|
67 | if (!showInfo) {
|
68 | return null;
|
69 | }
|
70 | var successPercent = getSuccessPercent(props);
|
71 | var text;
|
72 | var textFormatter = format || function (number) {
|
73 | return number + "%";
|
74 | };
|
75 | var isLineType = type === 'line';
|
76 | if (format || progressStatus !== 'exception' && progressStatus !== 'success') {
|
77 | text = textFormatter(validProgress(percent), validProgress(successPercent));
|
78 | } else if (progressStatus === 'exception') {
|
79 | text = isLineType ? React.createElement(CloseCircleFilled, null) : React.createElement(CloseOutlined, null);
|
80 | } else if (progressStatus === 'success') {
|
81 | text = isLineType ? React.createElement(CheckCircleFilled, null) : React.createElement(CheckOutlined, null);
|
82 | }
|
83 | return React.createElement("span", {
|
84 | className: prefixCls + "-text",
|
85 | title: typeof text === 'string' ? text : undefined
|
86 | }, text);
|
87 | }, [showInfo, percentNumber, progressStatus, type, prefixCls, format]);
|
88 | process.env.NODE_ENV !== "production" ? warning(!('successPercent' in props), 'Progress', '`successPercent` is deprecated. Please use `success.percent` instead.') : void 0;
|
89 | var strokeColorNotArray = Array.isArray(strokeColor) ? strokeColor[0] : strokeColor;
|
90 | var strokeColorNotGradient = typeof strokeColor === 'string' || Array.isArray(strokeColor) ? strokeColor : undefined;
|
91 | var progress;
|
92 |
|
93 | if (type === 'line') {
|
94 | progress = steps ? React.createElement(Steps, _extends({}, props, {
|
95 | strokeColor: strokeColorNotGradient,
|
96 | prefixCls: prefixCls,
|
97 | steps: steps
|
98 | }), progressInfo) : React.createElement(Line, _extends({}, props, {
|
99 | strokeColor: strokeColorNotArray,
|
100 | prefixCls: prefixCls,
|
101 | direction: direction
|
102 | }), progressInfo);
|
103 | } else if (type === 'circle' || type === 'dashboard') {
|
104 | progress = React.createElement(Circle, _extends({}, props, {
|
105 | strokeColor: strokeColorNotArray,
|
106 | prefixCls: prefixCls,
|
107 | progressStatus: progressStatus
|
108 | }), progressInfo);
|
109 | }
|
110 | var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, prefixCls + "-inline-circle", type === 'circle' && props.width <= 20), _defineProperty(_classNames, prefixCls + "-" + (type === 'dashboard' && 'circle' || steps && 'steps' || type), true), _defineProperty(_classNames, prefixCls + "-status-" + progressStatus, true), _defineProperty(_classNames, prefixCls + "-show-info", showInfo), _defineProperty(_classNames, prefixCls + "-" + size, size), _defineProperty(_classNames, prefixCls + "-rtl", direction === 'rtl'), _classNames), className, hashId);
|
111 | return wrapSSR( React.createElement("div", _extends({
|
112 | className: classString,
|
113 | role: "progressbar"
|
114 | }, omit(restProps, ['trailColor', 'strokeWidth', 'width', 'gapDegree', 'gapPosition', 'strokeLinecap', 'success', 'successPercent'])), progress));
|
115 | };
|
116 | export default Progress; |
\ | No newline at end of file |