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