@rc-component/progress 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +163 -0
- package/es/Circle/PtgCircle.d.ts +18 -0
- package/es/Circle/PtgCircle.js +79 -0
- package/es/Circle/index.d.ts +4 -0
- package/es/Circle/index.js +153 -0
- package/es/Circle/util.d.ts +5 -0
- package/es/Circle/util.js +30 -0
- package/es/Line.d.ts +4 -0
- package/es/Line.js +105 -0
- package/es/common.d.ts +3 -0
- package/es/common.js +35 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +3 -0
- package/es/interface.d.ts +30 -0
- package/es/interface.js +1 -0
- package/es/utils/getIndeterminateCircle.d.ts +19 -0
- package/es/utils/getIndeterminateCircle.js +23 -0
- package/es/utils/getIndeterminateLine.d.ts +25 -0
- package/es/utils/getIndeterminateLine.js +29 -0
- package/lib/Circle/PtgCircle.d.ts +18 -0
- package/lib/Circle/PtgCircle.js +88 -0
- package/lib/Circle/index.d.ts +4 -0
- package/lib/Circle/index.js +162 -0
- package/lib/Circle/util.d.ts +5 -0
- package/lib/Circle/util.js +37 -0
- package/lib/Line.d.ts +4 -0
- package/lib/Line.js +114 -0
- package/lib/common.d.ts +3 -0
- package/lib/common.js +42 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +20 -0
- package/lib/interface.d.ts +30 -0
- package/lib/interface.js +5 -0
- package/lib/utils/getIndeterminateCircle.d.ts +19 -0
- package/lib/utils/getIndeterminateCircle.js +31 -0
- package/lib/utils/getIndeterminateLine.d.ts +25 -0
- package/lib/utils/getIndeterminateLine.js +37 -0
- package/package.json +73 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IndeterminateOption {
|
|
3
|
+
id: string;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ id, loading }: IndeterminateOption) => {
|
|
7
|
+
indeterminateStyleProps: {
|
|
8
|
+
transform?: undefined;
|
|
9
|
+
animation?: undefined;
|
|
10
|
+
};
|
|
11
|
+
indeterminateStyleAnimation: any;
|
|
12
|
+
} | {
|
|
13
|
+
indeterminateStyleProps: {
|
|
14
|
+
transform: string;
|
|
15
|
+
animation: string;
|
|
16
|
+
};
|
|
17
|
+
indeterminateStyleAnimation: React.JSX.Element;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default (({
|
|
3
|
+
id,
|
|
4
|
+
loading
|
|
5
|
+
}) => {
|
|
6
|
+
if (!loading) {
|
|
7
|
+
return {
|
|
8
|
+
indeterminateStyleProps: {},
|
|
9
|
+
indeterminateStyleAnimation: null
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const animationName = `${id}-indeterminate-animate`;
|
|
13
|
+
return {
|
|
14
|
+
indeterminateStyleProps: {
|
|
15
|
+
transform: 'rotate(0deg)',
|
|
16
|
+
animation: `${animationName} 1s linear infinite`
|
|
17
|
+
},
|
|
18
|
+
indeterminateStyleAnimation: /*#__PURE__*/React.createElement("style", null, `@keyframes ${animationName} {
|
|
19
|
+
0% { transform: rotate(0deg); }
|
|
20
|
+
100% { transform: rotate(360deg); }
|
|
21
|
+
}`)
|
|
22
|
+
};
|
|
23
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StrokeLinecapType } from "../interface";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface IndeterminateOption {
|
|
4
|
+
id: string;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
percent: number;
|
|
7
|
+
strokeLinecap: StrokeLinecapType;
|
|
8
|
+
strokeWidth: number;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: (options: IndeterminateOption) => {
|
|
11
|
+
indeterminateStyleProps: {
|
|
12
|
+
strokeDasharray?: undefined;
|
|
13
|
+
animation?: undefined;
|
|
14
|
+
strokeDashoffset?: undefined;
|
|
15
|
+
};
|
|
16
|
+
indeterminateStyleAnimation: any;
|
|
17
|
+
} | {
|
|
18
|
+
indeterminateStyleProps: {
|
|
19
|
+
strokeDasharray: string;
|
|
20
|
+
animation: string;
|
|
21
|
+
strokeDashoffset: number;
|
|
22
|
+
};
|
|
23
|
+
indeterminateStyleAnimation: React.JSX.Element;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default (options => {
|
|
3
|
+
const {
|
|
4
|
+
id,
|
|
5
|
+
percent,
|
|
6
|
+
strokeLinecap,
|
|
7
|
+
strokeWidth,
|
|
8
|
+
loading
|
|
9
|
+
} = options;
|
|
10
|
+
if (!loading) {
|
|
11
|
+
return {
|
|
12
|
+
indeterminateStyleProps: {},
|
|
13
|
+
indeterminateStyleAnimation: null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const animationName = `${id}-indeterminate-animate`;
|
|
17
|
+
const strokeDashOffset = 100 - (percent + (strokeLinecap === 'round' ? strokeWidth : 0));
|
|
18
|
+
return {
|
|
19
|
+
indeterminateStyleProps: {
|
|
20
|
+
strokeDasharray: `${percent} 100`,
|
|
21
|
+
animation: `${animationName} .6s linear alternate infinite`,
|
|
22
|
+
strokeDashoffset: 0
|
|
23
|
+
},
|
|
24
|
+
indeterminateStyleAnimation: /*#__PURE__*/React.createElement("style", null, `@keyframes ${animationName} {
|
|
25
|
+
0% { stroke-dashoffset: 0; }
|
|
26
|
+
100% { stroke-dashoffset: -${strokeDashOffset};
|
|
27
|
+
}`)
|
|
28
|
+
};
|
|
29
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ProgressProps } from '..';
|
|
3
|
+
import type { StrokeColorObject } from '../interface';
|
|
4
|
+
export interface ColorGradientProps {
|
|
5
|
+
prefixCls: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
gradientId: string;
|
|
8
|
+
style: React.CSSProperties;
|
|
9
|
+
ptg: number;
|
|
10
|
+
radius: number;
|
|
11
|
+
strokeLinecap: ProgressProps['strokeLinecap'];
|
|
12
|
+
strokeWidth: ProgressProps['strokeWidth'];
|
|
13
|
+
size: number;
|
|
14
|
+
color: string | StrokeColorObject;
|
|
15
|
+
gapDegree: number;
|
|
16
|
+
}
|
|
17
|
+
declare const PtgCircle: React.ForwardRefExoticComponent<ColorGradientProps & React.RefAttributes<SVGCircleElement>>;
|
|
18
|
+
export default PtgCircle;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
const Block = ({
|
|
13
|
+
bg,
|
|
14
|
+
children
|
|
15
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
16
|
+
style: {
|
|
17
|
+
width: '100%',
|
|
18
|
+
height: '100%',
|
|
19
|
+
background: bg
|
|
20
|
+
}
|
|
21
|
+
}, children);
|
|
22
|
+
function getPtgColors(color, scale) {
|
|
23
|
+
return Object.keys(color).map(key => {
|
|
24
|
+
const parsedKey = parseFloat(key);
|
|
25
|
+
const ptgKey = `${Math.floor(parsedKey * scale)}%`;
|
|
26
|
+
return `${color[key]} ${ptgKey}`;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const PtgCircle = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
30
|
+
const {
|
|
31
|
+
prefixCls,
|
|
32
|
+
color,
|
|
33
|
+
gradientId,
|
|
34
|
+
radius,
|
|
35
|
+
className,
|
|
36
|
+
style: circleStyleForStack,
|
|
37
|
+
ptg,
|
|
38
|
+
strokeLinecap,
|
|
39
|
+
strokeWidth,
|
|
40
|
+
size,
|
|
41
|
+
gapDegree
|
|
42
|
+
} = props;
|
|
43
|
+
const isGradient = color && typeof color === 'object';
|
|
44
|
+
const stroke = isGradient ? `#FFF` : undefined;
|
|
45
|
+
|
|
46
|
+
// ========================== Circle ==========================
|
|
47
|
+
const halfSize = size / 2;
|
|
48
|
+
const circleNode = /*#__PURE__*/React.createElement("circle", {
|
|
49
|
+
className: (0, _classnames.default)(`${prefixCls}-circle-path`, className),
|
|
50
|
+
r: radius,
|
|
51
|
+
cx: halfSize,
|
|
52
|
+
cy: halfSize,
|
|
53
|
+
stroke: stroke,
|
|
54
|
+
strokeLinecap: strokeLinecap,
|
|
55
|
+
strokeWidth: strokeWidth,
|
|
56
|
+
opacity: ptg === 0 ? 0 : 1,
|
|
57
|
+
style: circleStyleForStack,
|
|
58
|
+
ref: ref
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ========================== Render ==========================
|
|
62
|
+
if (!isGradient) {
|
|
63
|
+
return circleNode;
|
|
64
|
+
}
|
|
65
|
+
const maskId = `${gradientId}-conic`;
|
|
66
|
+
const fromDeg = gapDegree ? `${180 + gapDegree / 2}deg` : '0deg';
|
|
67
|
+
const conicColors = getPtgColors(color, (360 - gapDegree) / 360);
|
|
68
|
+
const linearColors = getPtgColors(color, 1);
|
|
69
|
+
const conicColorBg = `conic-gradient(from ${fromDeg}, ${conicColors.join(', ')})`;
|
|
70
|
+
const linearColorBg = `linear-gradient(to ${gapDegree ? 'bottom' : 'top'}, ${linearColors.join(', ')})`;
|
|
71
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("mask", {
|
|
72
|
+
id: maskId
|
|
73
|
+
}, circleNode), /*#__PURE__*/React.createElement("foreignObject", {
|
|
74
|
+
x: 0,
|
|
75
|
+
y: 0,
|
|
76
|
+
width: size,
|
|
77
|
+
height: size,
|
|
78
|
+
mask: `url(#${maskId})`
|
|
79
|
+
}, /*#__PURE__*/React.createElement(Block, {
|
|
80
|
+
bg: linearColorBg
|
|
81
|
+
}, /*#__PURE__*/React.createElement(Block, {
|
|
82
|
+
bg: conicColorBg
|
|
83
|
+
}))));
|
|
84
|
+
});
|
|
85
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
86
|
+
PtgCircle.displayName = 'PtgCircle';
|
|
87
|
+
}
|
|
88
|
+
var _default = exports.default = PtgCircle;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
var _common = require("../common");
|
|
10
|
+
var _useId = _interopRequireDefault(require("@rc-component/util/lib/hooks/useId"));
|
|
11
|
+
var _PtgCircle = _interopRequireDefault(require("./PtgCircle"));
|
|
12
|
+
var _util = require("./util");
|
|
13
|
+
var _getIndeterminateCircle = _interopRequireDefault(require("../utils/getIndeterminateCircle"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
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); }
|
|
18
|
+
function toArray(value) {
|
|
19
|
+
const mergedValue = value ?? [];
|
|
20
|
+
return Array.isArray(mergedValue) ? mergedValue : [mergedValue];
|
|
21
|
+
}
|
|
22
|
+
const Circle = props => {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
prefixCls,
|
|
26
|
+
classNames = {},
|
|
27
|
+
styles = {},
|
|
28
|
+
steps,
|
|
29
|
+
strokeWidth,
|
|
30
|
+
trailWidth,
|
|
31
|
+
gapDegree = 0,
|
|
32
|
+
gapPosition,
|
|
33
|
+
trailColor,
|
|
34
|
+
strokeLinecap,
|
|
35
|
+
style,
|
|
36
|
+
className,
|
|
37
|
+
strokeColor,
|
|
38
|
+
percent,
|
|
39
|
+
loading,
|
|
40
|
+
...restProps
|
|
41
|
+
} = {
|
|
42
|
+
..._common.defaultProps,
|
|
43
|
+
...props
|
|
44
|
+
};
|
|
45
|
+
const halfSize = _util.VIEW_BOX_SIZE / 2;
|
|
46
|
+
const mergedId = (0, _useId.default)(id);
|
|
47
|
+
const gradientId = `${mergedId}-gradient`;
|
|
48
|
+
const radius = halfSize - strokeWidth / 2;
|
|
49
|
+
const perimeter = Math.PI * 2 * radius;
|
|
50
|
+
const rotateDeg = gapDegree > 0 ? 90 + gapDegree / 2 : -90;
|
|
51
|
+
const perimeterWithoutGap = perimeter * ((360 - gapDegree) / 360);
|
|
52
|
+
const {
|
|
53
|
+
count: stepCount,
|
|
54
|
+
gap: stepGap
|
|
55
|
+
} = typeof steps === 'object' ? steps : {
|
|
56
|
+
count: steps,
|
|
57
|
+
gap: 2
|
|
58
|
+
};
|
|
59
|
+
const percentList = toArray(percent);
|
|
60
|
+
const strokeColorList = toArray(strokeColor);
|
|
61
|
+
const gradient = strokeColorList.find(color => color && typeof color === 'object');
|
|
62
|
+
const isConicGradient = gradient && typeof gradient === 'object';
|
|
63
|
+
const mergedStrokeLinecap = isConicGradient ? 'butt' : strokeLinecap;
|
|
64
|
+
const {
|
|
65
|
+
indeterminateStyleProps,
|
|
66
|
+
indeterminateStyleAnimation
|
|
67
|
+
} = (0, _getIndeterminateCircle.default)({
|
|
68
|
+
id: mergedId,
|
|
69
|
+
loading
|
|
70
|
+
});
|
|
71
|
+
const circleStyle = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, 0, 100, rotateDeg, gapDegree, gapPosition, trailColor, mergedStrokeLinecap, strokeWidth);
|
|
72
|
+
const paths = (0, _common.useTransitionDuration)();
|
|
73
|
+
const getStokeList = () => {
|
|
74
|
+
let stackPtg = 0;
|
|
75
|
+
return percentList.map((ptg, index) => {
|
|
76
|
+
const color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
|
77
|
+
const circleStyleForStack = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, stackPtg, ptg, rotateDeg, gapDegree, gapPosition, color, mergedStrokeLinecap, strokeWidth);
|
|
78
|
+
stackPtg += ptg;
|
|
79
|
+
return /*#__PURE__*/React.createElement(_PtgCircle.default, {
|
|
80
|
+
key: index,
|
|
81
|
+
color: color,
|
|
82
|
+
ptg: ptg,
|
|
83
|
+
radius: radius,
|
|
84
|
+
prefixCls: prefixCls,
|
|
85
|
+
gradientId: gradientId,
|
|
86
|
+
className: classNames.track,
|
|
87
|
+
style: {
|
|
88
|
+
...circleStyleForStack,
|
|
89
|
+
...indeterminateStyleProps,
|
|
90
|
+
...styles.track
|
|
91
|
+
},
|
|
92
|
+
strokeLinecap: mergedStrokeLinecap,
|
|
93
|
+
strokeWidth: strokeWidth,
|
|
94
|
+
gapDegree: gapDegree,
|
|
95
|
+
ref: elem => {
|
|
96
|
+
// https://reactjs.org/docs/refs-and-the-dom.html#callback-refs
|
|
97
|
+
// React will call the ref callback with the DOM element when the component mounts,
|
|
98
|
+
// and call it with `null` when it unmounts.
|
|
99
|
+
// Refs are guaranteed to be up-to-date before componentDidMount or componentDidUpdate fires.
|
|
100
|
+
|
|
101
|
+
paths[index] = elem;
|
|
102
|
+
},
|
|
103
|
+
size: _util.VIEW_BOX_SIZE
|
|
104
|
+
});
|
|
105
|
+
}).reverse();
|
|
106
|
+
};
|
|
107
|
+
const getStepStokeList = () => {
|
|
108
|
+
// only show the first percent when pass steps
|
|
109
|
+
const current = Math.round(stepCount * (percentList[0] / 100));
|
|
110
|
+
const stepPtg = 100 / stepCount;
|
|
111
|
+
let stackPtg = 0;
|
|
112
|
+
return new Array(stepCount).fill(null).map((_, index) => {
|
|
113
|
+
const color = index <= current - 1 ? strokeColorList[0] : trailColor;
|
|
114
|
+
const stroke = color && typeof color === 'object' ? `url(#${gradientId})` : undefined;
|
|
115
|
+
const circleStyleForStack = (0, _util.getCircleStyle)(perimeter, perimeterWithoutGap, stackPtg, stepPtg, rotateDeg, gapDegree, gapPosition, color, 'butt', strokeWidth, stepGap);
|
|
116
|
+
stackPtg += (perimeterWithoutGap - circleStyleForStack.strokeDashoffset + stepGap) * 100 / perimeterWithoutGap;
|
|
117
|
+
return /*#__PURE__*/React.createElement("circle", {
|
|
118
|
+
key: index,
|
|
119
|
+
className: (0, _classnames.default)(`${prefixCls}-circle-path`, classNames.track),
|
|
120
|
+
r: radius,
|
|
121
|
+
cx: halfSize,
|
|
122
|
+
cy: halfSize,
|
|
123
|
+
stroke: stroke,
|
|
124
|
+
strokeWidth: strokeWidth,
|
|
125
|
+
opacity: 1,
|
|
126
|
+
style: {
|
|
127
|
+
...circleStyleForStack,
|
|
128
|
+
...styles.track
|
|
129
|
+
},
|
|
130
|
+
ref: elem => {
|
|
131
|
+
paths[index] = elem;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
137
|
+
className: (0, _classnames.default)(`${prefixCls}-circle`, classNames.root, className),
|
|
138
|
+
viewBox: `0 0 ${_util.VIEW_BOX_SIZE} ${_util.VIEW_BOX_SIZE}`,
|
|
139
|
+
style: {
|
|
140
|
+
...styles.root,
|
|
141
|
+
...style
|
|
142
|
+
},
|
|
143
|
+
id: id,
|
|
144
|
+
role: "presentation"
|
|
145
|
+
}, restProps), !stepCount && /*#__PURE__*/React.createElement("circle", {
|
|
146
|
+
className: (0, _classnames.default)(`${prefixCls}-circle-trail`, classNames.rail),
|
|
147
|
+
r: radius,
|
|
148
|
+
cx: halfSize,
|
|
149
|
+
cy: halfSize,
|
|
150
|
+
stroke: trailColor,
|
|
151
|
+
strokeLinecap: mergedStrokeLinecap,
|
|
152
|
+
strokeWidth: trailWidth || strokeWidth,
|
|
153
|
+
style: {
|
|
154
|
+
...circleStyle,
|
|
155
|
+
...styles.rail
|
|
156
|
+
}
|
|
157
|
+
}), stepCount ? getStepStokeList() : getStokeList(), indeterminateStyleAnimation);
|
|
158
|
+
};
|
|
159
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
160
|
+
Circle.displayName = 'Circle';
|
|
161
|
+
}
|
|
162
|
+
var _default = exports.default = Circle;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StrokeColorType } from '../interface';
|
|
2
|
+
import type { ProgressProps } from '..';
|
|
3
|
+
import type React from 'react';
|
|
4
|
+
export declare const VIEW_BOX_SIZE = 100;
|
|
5
|
+
export declare const getCircleStyle: (perimeter: number, perimeterWithoutGap: number, offset: number, percent: number, rotateDeg: number, gapDegree: number, gapPosition: ProgressProps['gapPosition'] | undefined, strokeColor: StrokeColorType, strokeLinecap: ProgressProps['strokeLinecap'], strokeWidth: number, stepSpace?: number) => React.CSSProperties;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCircleStyle = exports.VIEW_BOX_SIZE = void 0;
|
|
7
|
+
const VIEW_BOX_SIZE = exports.VIEW_BOX_SIZE = 100;
|
|
8
|
+
const getCircleStyle = (perimeter, perimeterWithoutGap, offset, percent, rotateDeg, gapDegree, gapPosition, strokeColor, strokeLinecap, strokeWidth, stepSpace = 0) => {
|
|
9
|
+
const offsetDeg = offset / 100 * 360 * ((360 - gapDegree) / 360);
|
|
10
|
+
const positionDeg = gapDegree === 0 ? 0 : {
|
|
11
|
+
bottom: 0,
|
|
12
|
+
top: 180,
|
|
13
|
+
left: 90,
|
|
14
|
+
right: -90
|
|
15
|
+
}[gapPosition];
|
|
16
|
+
let strokeDashoffset = (100 - percent) / 100 * perimeterWithoutGap;
|
|
17
|
+
// Fix percent accuracy when strokeLinecap is round
|
|
18
|
+
// https://github.com/ant-design/ant-design/issues/35009
|
|
19
|
+
if (strokeLinecap === 'round' && percent !== 100) {
|
|
20
|
+
strokeDashoffset += strokeWidth / 2;
|
|
21
|
+
// when percent is small enough (<= 1%), keep smallest value to avoid it's disappearance
|
|
22
|
+
if (strokeDashoffset >= perimeterWithoutGap) {
|
|
23
|
+
strokeDashoffset = perimeterWithoutGap - 0.01;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const halfSize = VIEW_BOX_SIZE / 2;
|
|
27
|
+
return {
|
|
28
|
+
stroke: typeof strokeColor === 'string' ? strokeColor : undefined,
|
|
29
|
+
strokeDasharray: `${perimeterWithoutGap}px ${perimeter}`,
|
|
30
|
+
strokeDashoffset: strokeDashoffset + stepSpace,
|
|
31
|
+
transform: `rotate(${rotateDeg + offsetDeg + positionDeg}deg)`,
|
|
32
|
+
transformOrigin: `${halfSize}px ${halfSize}px`,
|
|
33
|
+
transition: 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s, opacity .3s ease 0s',
|
|
34
|
+
fillOpacity: 0
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.getCircleStyle = getCircleStyle;
|
package/lib/Line.d.ts
ADDED
package/lib/Line.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
var _common = require("./common");
|
|
10
|
+
var _getIndeterminateLine = _interopRequireDefault(require("./utils/getIndeterminateLine"));
|
|
11
|
+
var _useId = _interopRequireDefault(require("@rc-component/util/lib/hooks/useId"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
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); }
|
|
16
|
+
const Line = props => {
|
|
17
|
+
const {
|
|
18
|
+
id,
|
|
19
|
+
className,
|
|
20
|
+
percent,
|
|
21
|
+
prefixCls,
|
|
22
|
+
strokeColor,
|
|
23
|
+
strokeLinecap,
|
|
24
|
+
strokeWidth,
|
|
25
|
+
style,
|
|
26
|
+
trailColor,
|
|
27
|
+
trailWidth,
|
|
28
|
+
transition,
|
|
29
|
+
loading,
|
|
30
|
+
...restProps
|
|
31
|
+
} = {
|
|
32
|
+
..._common.defaultProps,
|
|
33
|
+
...props
|
|
34
|
+
};
|
|
35
|
+
const mergedId = (0, _useId.default)(id);
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line no-param-reassign
|
|
38
|
+
delete restProps.gapPosition;
|
|
39
|
+
const percentList = Array.isArray(percent) ? percent : [percent];
|
|
40
|
+
const strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
|
41
|
+
const paths = (0, _common.useTransitionDuration)();
|
|
42
|
+
const center = strokeWidth / 2;
|
|
43
|
+
const right = 100 - strokeWidth / 2;
|
|
44
|
+
const pathString = `M ${strokeLinecap === 'round' ? center : 0},${center}
|
|
45
|
+
L ${strokeLinecap === 'round' ? right : 100},${center}`;
|
|
46
|
+
const viewBoxString = `0 0 100 ${strokeWidth}`;
|
|
47
|
+
let stackPtg = 0;
|
|
48
|
+
const {
|
|
49
|
+
indeterminateStyleProps,
|
|
50
|
+
indeterminateStyleAnimation
|
|
51
|
+
} = (0, _getIndeterminateLine.default)({
|
|
52
|
+
id: mergedId,
|
|
53
|
+
loading,
|
|
54
|
+
percent: percentList[0],
|
|
55
|
+
strokeLinecap,
|
|
56
|
+
strokeWidth
|
|
57
|
+
});
|
|
58
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
59
|
+
className: (0, _classnames.default)(`${prefixCls}-line`, className),
|
|
60
|
+
viewBox: viewBoxString,
|
|
61
|
+
preserveAspectRatio: "none",
|
|
62
|
+
style: style
|
|
63
|
+
}, restProps), /*#__PURE__*/React.createElement("path", {
|
|
64
|
+
className: `${prefixCls}-line-trail`,
|
|
65
|
+
d: pathString,
|
|
66
|
+
strokeLinecap: strokeLinecap,
|
|
67
|
+
stroke: trailColor,
|
|
68
|
+
strokeWidth: trailWidth || strokeWidth,
|
|
69
|
+
fillOpacity: "0"
|
|
70
|
+
}), percentList.map((ptg, index) => {
|
|
71
|
+
let dashPercent = 1;
|
|
72
|
+
switch (strokeLinecap) {
|
|
73
|
+
case 'round':
|
|
74
|
+
dashPercent = 1 - strokeWidth / 100;
|
|
75
|
+
break;
|
|
76
|
+
case 'square':
|
|
77
|
+
dashPercent = 1 - strokeWidth / 2 / 100;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
dashPercent = 1;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const pathStyle = {
|
|
84
|
+
strokeDasharray: `${ptg * dashPercent}px, 100px`,
|
|
85
|
+
strokeDashoffset: `-${stackPtg}px`,
|
|
86
|
+
transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear',
|
|
87
|
+
...indeterminateStyleProps
|
|
88
|
+
};
|
|
89
|
+
const color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
|
90
|
+
stackPtg += ptg;
|
|
91
|
+
return /*#__PURE__*/React.createElement("path", {
|
|
92
|
+
key: index,
|
|
93
|
+
className: `${prefixCls}-line-path`,
|
|
94
|
+
d: pathString,
|
|
95
|
+
strokeLinecap: strokeLinecap,
|
|
96
|
+
stroke: color,
|
|
97
|
+
strokeWidth: strokeWidth,
|
|
98
|
+
fillOpacity: "0",
|
|
99
|
+
ref: elem => {
|
|
100
|
+
// https://reactjs.org/docs/refs-and-the-dom.html#callback-refs
|
|
101
|
+
// React will call the ref callback with the DOM element when the component mounts,
|
|
102
|
+
// and call it with `null` when it unmounts.
|
|
103
|
+
// Refs are guaranteed to be up-to-date before componentDidMount or componentDidUpdate fires.
|
|
104
|
+
|
|
105
|
+
paths[index] = elem;
|
|
106
|
+
},
|
|
107
|
+
style: pathStyle
|
|
108
|
+
});
|
|
109
|
+
}), indeterminateStyleAnimation);
|
|
110
|
+
};
|
|
111
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
112
|
+
Line.displayName = 'Line';
|
|
113
|
+
}
|
|
114
|
+
var _default = exports.default = Line;
|
package/lib/common.d.ts
ADDED
package/lib/common.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTransitionDuration = exports.defaultProps = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const defaultProps = exports.defaultProps = {
|
|
9
|
+
percent: 0,
|
|
10
|
+
prefixCls: 'rc-progress',
|
|
11
|
+
strokeColor: '#2db7f5',
|
|
12
|
+
strokeLinecap: 'round',
|
|
13
|
+
strokeWidth: 1,
|
|
14
|
+
trailColor: '#D9D9D9',
|
|
15
|
+
trailWidth: 1,
|
|
16
|
+
gapPosition: 'bottom',
|
|
17
|
+
loading: false
|
|
18
|
+
};
|
|
19
|
+
const useTransitionDuration = () => {
|
|
20
|
+
const pathsRef = (0, _react.useRef)([]);
|
|
21
|
+
const prevTimeStamp = (0, _react.useRef)(null);
|
|
22
|
+
(0, _react.useEffect)(() => {
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
let updated = false;
|
|
25
|
+
pathsRef.current.forEach(path => {
|
|
26
|
+
if (!path) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
updated = true;
|
|
30
|
+
const pathStyle = path.style;
|
|
31
|
+
pathStyle.transitionDuration = '.3s, .3s, .3s, .06s';
|
|
32
|
+
if (prevTimeStamp.current && now - prevTimeStamp.current < 100) {
|
|
33
|
+
pathStyle.transitionDuration = '0s, 0s';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (updated) {
|
|
37
|
+
prevTimeStamp.current = Date.now();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return pathsRef.current;
|
|
41
|
+
};
|
|
42
|
+
exports.useTransitionDuration = useTransitionDuration;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Circle", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _Circle.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Line", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Line.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _Line = _interopRequireDefault(require("./Line"));
|
|
19
|
+
var _Circle = _interopRequireDefault(require("./Circle"));
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type SemanticName = 'root' | 'rail' | 'track';
|
|
3
|
+
export interface ProgressProps {
|
|
4
|
+
id?: string;
|
|
5
|
+
strokeWidth?: number;
|
|
6
|
+
trailWidth?: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
classNames?: Partial<Record<SemanticName, string>>;
|
|
9
|
+
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
|
|
10
|
+
percent?: number | number[];
|
|
11
|
+
strokeColor?: StrokeColorType;
|
|
12
|
+
trailColor?: string;
|
|
13
|
+
strokeLinecap?: StrokeLinecapType;
|
|
14
|
+
prefixCls?: string;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
gapDegree?: number;
|
|
17
|
+
gapPosition?: GapPositionType;
|
|
18
|
+
transition?: string;
|
|
19
|
+
onClick?: React.MouseEventHandler;
|
|
20
|
+
steps?: number | {
|
|
21
|
+
count: number;
|
|
22
|
+
gap: number;
|
|
23
|
+
};
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type StrokeColorObject = Record<string, string | boolean>;
|
|
27
|
+
export type BaseStrokeColorType = string | StrokeColorObject;
|
|
28
|
+
export type StrokeColorType = BaseStrokeColorType | BaseStrokeColorType[];
|
|
29
|
+
export type GapPositionType = 'top' | 'right' | 'bottom' | 'left';
|
|
30
|
+
export type StrokeLinecapType = 'round' | 'butt' | 'square';
|
package/lib/interface.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IndeterminateOption {
|
|
3
|
+
id: string;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ id, loading }: IndeterminateOption) => {
|
|
7
|
+
indeterminateStyleProps: {
|
|
8
|
+
transform?: undefined;
|
|
9
|
+
animation?: undefined;
|
|
10
|
+
};
|
|
11
|
+
indeterminateStyleAnimation: any;
|
|
12
|
+
} | {
|
|
13
|
+
indeterminateStyleProps: {
|
|
14
|
+
transform: string;
|
|
15
|
+
animation: string;
|
|
16
|
+
};
|
|
17
|
+
indeterminateStyleAnimation: React.JSX.Element;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|