1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | var _excluded = ["className", "percent", "prefixCls", "strokeColor", "strokeLinecap", "strokeWidth", "style", "trailColor", "trailWidth", "transition"];
|
5 | import * as React from 'react';
|
6 | import classNames from 'classnames';
|
7 | import { useTransitionDuration, defaultProps } from './common';
|
8 |
|
9 | var Line = function Line(_ref) {
|
10 | var className = _ref.className,
|
11 | percent = _ref.percent,
|
12 | prefixCls = _ref.prefixCls,
|
13 | strokeColor = _ref.strokeColor,
|
14 | strokeLinecap = _ref.strokeLinecap,
|
15 | strokeWidth = _ref.strokeWidth,
|
16 | style = _ref.style,
|
17 | trailColor = _ref.trailColor,
|
18 | trailWidth = _ref.trailWidth,
|
19 | transition = _ref.transition,
|
20 | restProps = _objectWithoutProperties(_ref, _excluded);
|
21 |
|
22 |
|
23 | delete restProps.gapPosition;
|
24 | var percentList = Array.isArray(percent) ? percent : [percent];
|
25 | var strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
26 |
|
27 | var _useTransitionDuratio = useTransitionDuration(percentList),
|
28 | _useTransitionDuratio2 = _slicedToArray(_useTransitionDuratio, 1),
|
29 | paths = _useTransitionDuratio2[0];
|
30 |
|
31 | var center = strokeWidth / 2;
|
32 | var right = 100 - strokeWidth / 2;
|
33 | var pathString = "M ".concat(strokeLinecap === 'round' ? center : 0, ",").concat(center, "\n L ").concat(strokeLinecap === 'round' ? right : 100, ",").concat(center);
|
34 | var viewBoxString = "0 0 100 ".concat(strokeWidth);
|
35 | var stackPtg = 0;
|
36 | return React.createElement("svg", _extends({
|
37 | className: classNames("".concat(prefixCls, "-line"), className),
|
38 | viewBox: viewBoxString,
|
39 | preserveAspectRatio: "none",
|
40 | style: style
|
41 | }, restProps), React.createElement("path", {
|
42 | className: "".concat(prefixCls, "-line-trail"),
|
43 | d: pathString,
|
44 | strokeLinecap: strokeLinecap,
|
45 | stroke: trailColor,
|
46 | strokeWidth: trailWidth || strokeWidth,
|
47 | fillOpacity: "0"
|
48 | }), percentList.map(function (ptg, index) {
|
49 | var dashPercent = 1;
|
50 |
|
51 | switch (strokeLinecap) {
|
52 | case 'round':
|
53 | dashPercent = 1 - strokeWidth / 100;
|
54 | break;
|
55 |
|
56 | case 'square':
|
57 | dashPercent = 1 - strokeWidth / 2 / 100;
|
58 | break;
|
59 |
|
60 | default:
|
61 | dashPercent = 1;
|
62 | break;
|
63 | }
|
64 |
|
65 | var pathStyle = {
|
66 | strokeDasharray: "".concat(ptg * dashPercent, "px, 100px"),
|
67 | strokeDashoffset: "-".concat(stackPtg, "px"),
|
68 | transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear'
|
69 | };
|
70 | var color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
71 | stackPtg += ptg;
|
72 | return React.createElement("path", {
|
73 | key: index,
|
74 | className: "".concat(prefixCls, "-line-path"),
|
75 | d: pathString,
|
76 | strokeLinecap: strokeLinecap,
|
77 | stroke: color,
|
78 | strokeWidth: strokeWidth,
|
79 | fillOpacity: "0",
|
80 | ref: paths[index],
|
81 | style: pathStyle
|
82 | });
|
83 | }));
|
84 | };
|
85 |
|
86 | Line.defaultProps = defaultProps;
|
87 | Line.displayName = 'Line';
|
88 | export default Line; |
\ | No newline at end of file |