1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _typeof = require("@babel/runtime/helpers/typeof");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports["default"] = exports.handleGradient = exports.sortGradient = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var React = _interopRequireWildcard(require("react"));
|
15 |
|
16 | var _colors = require("@ant-design/colors");
|
17 |
|
18 | var _utils = require("./utils");
|
19 |
|
20 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21 |
|
22 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23 |
|
24 | var __rest = void 0 && (void 0).__rest || function (s, e) {
|
25 | var t = {};
|
26 |
|
27 | for (var p in s) {
|
28 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
29 | }
|
30 |
|
31 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
32 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
33 | }
|
34 | return t;
|
35 | };
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | var sortGradient = function sortGradient(gradients) {
|
48 | var tempArr = [];
|
49 | Object.keys(gradients).forEach(function (key) {
|
50 | var formattedKey = parseFloat(key.replace(/%/g, ''));
|
51 |
|
52 | if (!isNaN(formattedKey)) {
|
53 | tempArr.push({
|
54 | key: formattedKey,
|
55 | value: gradients[key]
|
56 | });
|
57 | }
|
58 | });
|
59 | tempArr = tempArr.sort(function (a, b) {
|
60 | return a.key - b.key;
|
61 | });
|
62 | return tempArr.map(function (_ref) {
|
63 | var key = _ref.key,
|
64 | value = _ref.value;
|
65 | return "".concat(value, " ").concat(key, "%");
|
66 | }).join(', ');
|
67 | };
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | exports.sortGradient = sortGradient;
|
84 |
|
85 | var handleGradient = function handleGradient(strokeColor, directionConfig) {
|
86 | var _strokeColor$from = strokeColor.from,
|
87 | from = _strokeColor$from === void 0 ? _colors.presetPrimaryColors.blue : _strokeColor$from,
|
88 | _strokeColor$to = strokeColor.to,
|
89 | to = _strokeColor$to === void 0 ? _colors.presetPrimaryColors.blue : _strokeColor$to,
|
90 | _strokeColor$directio = strokeColor.direction,
|
91 | direction = _strokeColor$directio === void 0 ? directionConfig === 'rtl' ? 'to left' : 'to right' : _strokeColor$directio,
|
92 | rest = __rest(strokeColor, ["from", "to", "direction"]);
|
93 |
|
94 | if (Object.keys(rest).length !== 0) {
|
95 | var sortedGradients = sortGradient(rest);
|
96 | return {
|
97 | backgroundImage: "linear-gradient(".concat(direction, ", ").concat(sortedGradients, ")")
|
98 | };
|
99 | }
|
100 |
|
101 | return {
|
102 | backgroundImage: "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")")
|
103 | };
|
104 | };
|
105 |
|
106 | exports.handleGradient = handleGradient;
|
107 |
|
108 | var Line = function Line(props) {
|
109 | var prefixCls = props.prefixCls,
|
110 | directionConfig = props.direction,
|
111 | percent = props.percent,
|
112 | strokeWidth = props.strokeWidth,
|
113 | size = props.size,
|
114 | strokeColor = props.strokeColor,
|
115 | strokeLinecap = props.strokeLinecap,
|
116 | children = props.children,
|
117 | trailColor = props.trailColor,
|
118 | success = props.success;
|
119 | var backgroundProps = strokeColor && typeof strokeColor !== 'string' ? handleGradient(strokeColor, directionConfig) : {
|
120 | background: strokeColor
|
121 | };
|
122 | var trailStyle = trailColor ? {
|
123 | backgroundColor: trailColor
|
124 | } : undefined;
|
125 | var percentStyle = (0, _extends2["default"])({
|
126 | width: "".concat((0, _utils.validProgress)(percent), "%"),
|
127 | height: strokeWidth || (size === 'small' ? 6 : 8),
|
128 | borderRadius: strokeLinecap === 'square' ? 0 : ''
|
129 | }, backgroundProps);
|
130 | var successPercent = (0, _utils.getSuccessPercent)(props);
|
131 | var successPercentStyle = {
|
132 | width: "".concat((0, _utils.validProgress)(successPercent), "%"),
|
133 | height: strokeWidth || (size === 'small' ? 6 : 8),
|
134 | borderRadius: strokeLinecap === 'square' ? 0 : '',
|
135 | backgroundColor: success === null || success === void 0 ? void 0 : success.strokeColor
|
136 | };
|
137 | var successSegment = successPercent !== undefined ? React.createElement("div", {
|
138 | className: "".concat(prefixCls, "-success-bg"),
|
139 | style: successPercentStyle
|
140 | }) : null;
|
141 | return React.createElement(React.Fragment, null, React.createElement("div", {
|
142 | className: "".concat(prefixCls, "-outer")
|
143 | }, React.createElement("div", {
|
144 | className: "".concat(prefixCls, "-inner"),
|
145 | style: trailStyle
|
146 | }, React.createElement("div", {
|
147 | className: "".concat(prefixCls, "-bg"),
|
148 | style: percentStyle
|
149 | }), successSegment)), children);
|
150 | };
|
151 |
|
152 | var _default = Line;
|
153 | exports["default"] = _default; |
\ | No newline at end of file |