1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof = 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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
12 | var React = _interopRequireWildcard(require("react"));
|
13 | var _classnames = _interopRequireDefault(require("classnames"));
|
14 | var _common = require("./common");
|
15 | var _excluded = ["className", "percent", "prefixCls", "strokeColor", "strokeLinecap", "strokeWidth", "style", "trailColor", "trailWidth", "transition"];
|
16 | 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); }
|
17 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(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; }
|
18 | var Line = function Line(props) {
|
19 | var _defaultProps$props = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _common.defaultProps), props),
|
20 | className = _defaultProps$props.className,
|
21 | percent = _defaultProps$props.percent,
|
22 | prefixCls = _defaultProps$props.prefixCls,
|
23 | strokeColor = _defaultProps$props.strokeColor,
|
24 | strokeLinecap = _defaultProps$props.strokeLinecap,
|
25 | strokeWidth = _defaultProps$props.strokeWidth,
|
26 | style = _defaultProps$props.style,
|
27 | trailColor = _defaultProps$props.trailColor,
|
28 | trailWidth = _defaultProps$props.trailWidth,
|
29 | transition = _defaultProps$props.transition,
|
30 | restProps = (0, _objectWithoutProperties2.default)(_defaultProps$props, _excluded);
|
31 |
|
32 |
|
33 | delete restProps.gapPosition;
|
34 | var percentList = Array.isArray(percent) ? percent : [percent];
|
35 | var strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
36 | var paths = (0, _common.useTransitionDuration)();
|
37 | var center = strokeWidth / 2;
|
38 | var right = 100 - strokeWidth / 2;
|
39 | var pathString = "M ".concat(strokeLinecap === 'round' ? center : 0, ",").concat(center, "\n L ").concat(strokeLinecap === 'round' ? right : 100, ",").concat(center);
|
40 | var viewBoxString = "0 0 100 ".concat(strokeWidth);
|
41 | var stackPtg = 0;
|
42 | return React.createElement("svg", (0, _extends2.default)({
|
43 | className: (0, _classnames.default)("".concat(prefixCls, "-line"), className),
|
44 | viewBox: viewBoxString,
|
45 | preserveAspectRatio: "none",
|
46 | style: style
|
47 | }, restProps), React.createElement("path", {
|
48 | className: "".concat(prefixCls, "-line-trail"),
|
49 | d: pathString,
|
50 | strokeLinecap: strokeLinecap,
|
51 | stroke: trailColor,
|
52 | strokeWidth: trailWidth || strokeWidth,
|
53 | fillOpacity: "0"
|
54 | }), percentList.map(function (ptg, index) {
|
55 | var dashPercent = 1;
|
56 | switch (strokeLinecap) {
|
57 | case 'round':
|
58 | dashPercent = 1 - strokeWidth / 100;
|
59 | break;
|
60 | case 'square':
|
61 | dashPercent = 1 - strokeWidth / 2 / 100;
|
62 | break;
|
63 | default:
|
64 | dashPercent = 1;
|
65 | break;
|
66 | }
|
67 | var pathStyle = {
|
68 | strokeDasharray: "".concat(ptg * dashPercent, "px, 100px"),
|
69 | strokeDashoffset: "-".concat(stackPtg, "px"),
|
70 | transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear'
|
71 | };
|
72 | var color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
73 | stackPtg += ptg;
|
74 | return React.createElement("path", {
|
75 | key: index,
|
76 | className: "".concat(prefixCls, "-line-path"),
|
77 | d: pathString,
|
78 | strokeLinecap: strokeLinecap,
|
79 | stroke: color,
|
80 | strokeWidth: strokeWidth,
|
81 | fillOpacity: "0",
|
82 | ref: function ref(elem) {
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | paths[index] = elem;
|
89 | },
|
90 | style: pathStyle
|
91 | });
|
92 | }));
|
93 | };
|
94 | if (process.env.NODE_ENV !== 'production') {
|
95 | Line.displayName = 'Line';
|
96 | }
|
97 | var _default = exports.default = Line; |
\ | No newline at end of file |