UNPKG

3.74 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
16var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
17
18var React = _interopRequireWildcard(require("react"));
19
20var _classnames = _interopRequireDefault(require("classnames"));
21
22var _common = require("./common");
23
24var _excluded = ["className", "percent", "prefixCls", "strokeColor", "strokeLinecap", "strokeWidth", "style", "trailColor", "trailWidth", "transition"];
25
26var Line = function Line(_ref) {
27 var className = _ref.className,
28 percent = _ref.percent,
29 prefixCls = _ref.prefixCls,
30 strokeColor = _ref.strokeColor,
31 strokeLinecap = _ref.strokeLinecap,
32 strokeWidth = _ref.strokeWidth,
33 style = _ref.style,
34 trailColor = _ref.trailColor,
35 trailWidth = _ref.trailWidth,
36 transition = _ref.transition,
37 restProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
38 // eslint-disable-next-line no-param-reassign
39 delete restProps.gapPosition;
40 var percentList = Array.isArray(percent) ? percent : [percent];
41 var strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
42
43 var _useTransitionDuratio = (0, _common.useTransitionDuration)(percentList),
44 _useTransitionDuratio2 = (0, _slicedToArray2.default)(_useTransitionDuratio, 1),
45 paths = _useTransitionDuratio2[0];
46
47 var center = strokeWidth / 2;
48 var right = 100 - strokeWidth / 2;
49 var pathString = "M ".concat(strokeLinecap === 'round' ? center : 0, ",").concat(center, "\n L ").concat(strokeLinecap === 'round' ? right : 100, ",").concat(center);
50 var viewBoxString = "0 0 100 ".concat(strokeWidth);
51 var stackPtg = 0;
52 return /*#__PURE__*/React.createElement("svg", (0, _extends2.default)({
53 className: (0, _classnames.default)("".concat(prefixCls, "-line"), className),
54 viewBox: viewBoxString,
55 preserveAspectRatio: "none",
56 style: style
57 }, restProps), /*#__PURE__*/React.createElement("path", {
58 className: "".concat(prefixCls, "-line-trail"),
59 d: pathString,
60 strokeLinecap: strokeLinecap,
61 stroke: trailColor,
62 strokeWidth: trailWidth || strokeWidth,
63 fillOpacity: "0"
64 }), percentList.map(function (ptg, index) {
65 var dashPercent = 1;
66
67 switch (strokeLinecap) {
68 case 'round':
69 dashPercent = 1 - strokeWidth / 100;
70 break;
71
72 case 'square':
73 dashPercent = 1 - strokeWidth / 2 / 100;
74 break;
75
76 default:
77 dashPercent = 1;
78 break;
79 }
80
81 var pathStyle = {
82 strokeDasharray: "".concat(ptg * dashPercent, "px, 100px"),
83 strokeDashoffset: "-".concat(stackPtg, "px"),
84 transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear'
85 };
86 var color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
87 stackPtg += ptg;
88 return /*#__PURE__*/React.createElement("path", {
89 key: index,
90 className: "".concat(prefixCls, "-line-path"),
91 d: pathString,
92 strokeLinecap: strokeLinecap,
93 stroke: color,
94 strokeWidth: strokeWidth,
95 fillOpacity: "0",
96 ref: paths[index],
97 style: pathStyle
98 });
99 }));
100};
101
102Line.defaultProps = _common.defaultProps;
103Line.displayName = 'Line';
104var _default = Line;
105exports.default = _default;
\No newline at end of file