1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof3 = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10 | var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
11 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
12 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13 | var React = _interopRequireWildcard(require("react"));
|
14 | var _classnames = _interopRequireDefault(require("classnames"));
|
15 | var _common = require("../common");
|
16 | var _useId = _interopRequireDefault(require("../hooks/useId"));
|
17 | var _PtgCircle = _interopRequireDefault(require("./PtgCircle"));
|
18 | var _util = require("./util");
|
19 | var _excluded = ["id", "prefixCls", "steps", "strokeWidth", "trailWidth", "gapDegree", "gapPosition", "trailColor", "strokeLinecap", "style", "className", "strokeColor", "percent"];
|
20 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
21 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
22 | function toArray(value) {
|
23 | var mergedValue = value !== null && value !== void 0 ? value : [];
|
24 | return Array.isArray(mergedValue) ? mergedValue : [mergedValue];
|
25 | }
|
26 | var Circle = function Circle(props) {
|
27 | var _defaultProps$props = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _common.defaultProps), props),
|
28 | id = _defaultProps$props.id,
|
29 | prefixCls = _defaultProps$props.prefixCls,
|
30 | steps = _defaultProps$props.steps,
|
31 | strokeWidth = _defaultProps$props.strokeWidth,
|
32 | trailWidth = _defaultProps$props.trailWidth,
|
33 | _defaultProps$props$g = _defaultProps$props.gapDegree,
|
34 | gapDegree = _defaultProps$props$g === void 0 ? 0 : _defaultProps$props$g,
|
35 | gapPosition = _defaultProps$props.gapPosition,
|
36 | trailColor = _defaultProps$props.trailColor,
|
37 | strokeLinecap = _defaultProps$props.strokeLinecap,
|
38 | style = _defaultProps$props.style,
|
39 | className = _defaultProps$props.className,
|
40 | strokeColor = _defaultProps$props.strokeColor,
|
41 | percent = _defaultProps$props.percent,
|
42 | restProps = (0, _objectWithoutProperties2.default)(_defaultProps$props, _excluded);
|
43 | var halfSize = _util.VIEW_BOX_SIZE / 2;
|
44 | var mergedId = (0, _useId.default)(id);
|
45 | var gradientId = "".concat(mergedId, "-gradient");
|
46 | var radius = halfSize - strokeWidth / 2;
|
47 | var perimeter = Math.PI * 2 * radius;
|
48 | var rotateDeg = gapDegree > 0 ? 90 + gapDegree / 2 : -90;
|
49 | var perimeterWithoutGap = perimeter * ((360 - gapDegree) / 360);
|
50 | var _ref = (0, _typeof2.default)(steps) === 'object' ? steps : {
|
51 | count: steps,
|
52 | gap: 2
|
53 | },
|
54 | stepCount = _ref.count,
|
55 | stepGap = _ref.gap;
|
56 | var percentList = toArray(percent);
|
57 | var strokeColorList = toArray(strokeColor);
|
58 | var gradient = strokeColorList.find(function (color) {
|
59 | return color && (0, _typeof2.default)(color) === 'object';
|
60 | });
|
61 | var isConicGradient = gradient && (0, _typeof2.default)(gradient) === 'object';
|
62 | var mergedStrokeLinecap = isConicGradient ? 'butt' : strokeLinecap;
|
63 | var circleStyle = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, 0, 100, rotateDeg, gapDegree, gapPosition, trailColor, mergedStrokeLinecap, strokeWidth);
|
64 | var paths = (0, _common.useTransitionDuration)();
|
65 | var getStokeList = function getStokeList() {
|
66 | var stackPtg = 0;
|
67 | return percentList.map(function (ptg, index) {
|
68 | var color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
69 | var circleStyleForStack = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, stackPtg, ptg, rotateDeg, gapDegree, gapPosition, color, mergedStrokeLinecap, strokeWidth);
|
70 | stackPtg += ptg;
|
71 | return React.createElement(_PtgCircle.default, {
|
72 | key: index,
|
73 | color: color,
|
74 | ptg: ptg,
|
75 | radius: radius,
|
76 | prefixCls: prefixCls,
|
77 | gradientId: gradientId,
|
78 | style: circleStyleForStack,
|
79 | strokeLinecap: mergedStrokeLinecap,
|
80 | strokeWidth: strokeWidth,
|
81 | gapDegree: gapDegree,
|
82 | ref: function ref(elem) {
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | paths[index] = elem;
|
89 | },
|
90 | size: _util.VIEW_BOX_SIZE
|
91 | });
|
92 | }).reverse();
|
93 | };
|
94 | var getStepStokeList = function getStepStokeList() {
|
95 |
|
96 | var current = Math.round(stepCount * (percentList[0] / 100));
|
97 | var stepPtg = 100 / stepCount;
|
98 | var stackPtg = 0;
|
99 | return new Array(stepCount).fill(null).map(function (_, index) {
|
100 | var color = index <= current - 1 ? strokeColorList[0] : trailColor;
|
101 | var stroke = color && (0, _typeof2.default)(color) === 'object' ? "url(#".concat(gradientId, ")") : undefined;
|
102 | var circleStyleForStack = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, stackPtg, stepPtg, rotateDeg, gapDegree, gapPosition, color, 'butt', strokeWidth, stepGap);
|
103 | stackPtg += (perimeterWithoutGap - circleStyleForStack.strokeDashoffset + stepGap) * 100 / perimeterWithoutGap;
|
104 | return React.createElement("circle", {
|
105 | key: index,
|
106 | className: "".concat(prefixCls, "-circle-path"),
|
107 | r: radius,
|
108 | cx: halfSize,
|
109 | cy: halfSize,
|
110 | stroke: stroke,
|
111 | strokeWidth: strokeWidth,
|
112 | opacity: 1,
|
113 | style: circleStyleForStack,
|
114 | ref: function ref(elem) {
|
115 | paths[index] = elem;
|
116 | }
|
117 | });
|
118 | });
|
119 | };
|
120 | return React.createElement("svg", (0, _extends2.default)({
|
121 | className: (0, _classnames.default)("".concat(prefixCls, "-circle"), className),
|
122 | viewBox: "0 0 ".concat(_util.VIEW_BOX_SIZE, " ").concat(_util.VIEW_BOX_SIZE),
|
123 | style: style,
|
124 | id: id,
|
125 | role: "presentation"
|
126 | }, restProps), !stepCount && React.createElement("circle", {
|
127 | className: "".concat(prefixCls, "-circle-trail"),
|
128 | r: radius,
|
129 | cx: halfSize,
|
130 | cy: halfSize,
|
131 | stroke: trailColor,
|
132 | strokeLinecap: mergedStrokeLinecap,
|
133 | strokeWidth: trailWidth || strokeWidth,
|
134 | style: circleStyle
|
135 | }), stepCount ? getStepStokeList() : getStokeList());
|
136 | };
|
137 | if (process.env.NODE_ENV !== 'production') {
|
138 | Circle.displayName = 'Circle';
|
139 | }
|
140 | var _default = exports.default = Circle; |
\ | No newline at end of file |