1
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _clsx = require("clsx");
|
||||
var _common = require("./common");
|
||||
var _getIndeterminateLine = _interopRequireDefault(require("./utils/getIndeterminateLine"));
|
||||
var _useId = _interopRequireDefault(require("@rc-component/util/lib/hooks/useId"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
||||
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; }
|
||||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
||||
const Line = props => {
|
||||
const {
|
||||
id,
|
||||
className,
|
||||
percent,
|
||||
prefixCls,
|
||||
strokeColor,
|
||||
strokeLinecap,
|
||||
strokeWidth,
|
||||
style,
|
||||
railColor,
|
||||
railWidth,
|
||||
transition,
|
||||
loading,
|
||||
...restProps
|
||||
} = {
|
||||
..._common.defaultProps,
|
||||
...props
|
||||
};
|
||||
const mergedId = (0, _useId.default)(id);
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
delete restProps.gapPosition;
|
||||
const percentList = Array.isArray(percent) ? percent : [percent];
|
||||
const strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
||||
const paths = (0, _common.useTransitionDuration)();
|
||||
const center = strokeWidth / 2;
|
||||
const right = 100 - strokeWidth / 2;
|
||||
const pathString = `M ${strokeLinecap === 'round' ? center : 0},${center}
|
||||
L ${strokeLinecap === 'round' ? right : 100},${center}`;
|
||||
const viewBoxString = `0 0 100 ${strokeWidth}`;
|
||||
let stackPtg = 0;
|
||||
const {
|
||||
indeterminateStyleProps,
|
||||
indeterminateStyleAnimation
|
||||
} = (0, _getIndeterminateLine.default)({
|
||||
id: mergedId,
|
||||
loading,
|
||||
percent: percentList[0],
|
||||
strokeLinecap,
|
||||
strokeWidth
|
||||
});
|
||||
return /*#__PURE__*/React.createElement("svg", _extends({
|
||||
className: (0, _clsx.clsx)(`${prefixCls}-line`, className),
|
||||
viewBox: viewBoxString,
|
||||
preserveAspectRatio: "none",
|
||||
style: style
|
||||
}, restProps), /*#__PURE__*/React.createElement("path", {
|
||||
className: `${prefixCls}-line-rail`,
|
||||
d: pathString,
|
||||
strokeLinecap: strokeLinecap,
|
||||
stroke: railColor,
|
||||
strokeWidth: railWidth || strokeWidth,
|
||||
fillOpacity: "0"
|
||||
}), percentList.map((ptg, index) => {
|
||||
let dashPercent = 1;
|
||||
switch (strokeLinecap) {
|
||||
case 'round':
|
||||
dashPercent = 1 - strokeWidth / 100;
|
||||
break;
|
||||
case 'square':
|
||||
dashPercent = 1 - strokeWidth / 2 / 100;
|
||||
break;
|
||||
default:
|
||||
dashPercent = 1;
|
||||
break;
|
||||
}
|
||||
const pathStyle = {
|
||||
strokeDasharray: `${ptg * dashPercent}px, 100px`,
|
||||
strokeDashoffset: `-${stackPtg}px`,
|
||||
transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear',
|
||||
...indeterminateStyleProps
|
||||
};
|
||||
const color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
||||
stackPtg += ptg;
|
||||
return /*#__PURE__*/React.createElement("path", {
|
||||
key: index,
|
||||
className: `${prefixCls}-line-path`,
|
||||
d: pathString,
|
||||
strokeLinecap: strokeLinecap,
|
||||
stroke: color,
|
||||
strokeWidth: strokeWidth,
|
||||
fillOpacity: "0",
|
||||
ref: elem => {
|
||||
// https://reactjs.org/docs/refs-and-the-dom.html#callback-refs
|
||||
// React will call the ref callback with the DOM element when the component mounts,
|
||||
// and call it with `null` when it unmounts.
|
||||
// Refs are guaranteed to be up-to-date before componentDidMount or componentDidUpdate fires.
|
||||
|
||||
paths[index] = elem;
|
||||
},
|
||||
style: pathStyle
|
||||
});
|
||||
}), indeterminateStyleAnimation);
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Line.displayName = 'Line';
|
||||
}
|
||||
var _default = exports.default = Line;
|
||||
Reference in New Issue
Block a user