Skip to content

Commit e645a90

Browse files
committed
fix coverage and generate id
1 parent 502b57b commit e645a90

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

src/Circle/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const Circle: React.FC<ProgressProps> = (props) => {
5454
const isConicGradient = gradient && typeof gradient === 'object';
5555
const mergedStrokeLinecap = isConicGradient ? 'butt' : strokeLinecap;
5656
const { indeterminateStyleProps, indeterminateStyleAnimation } = getIndeterminateCircle({
57+
id: mergedId,
5758
loading,
5859
});
5960

src/Line.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import classNames from 'classnames';
33
import { useTransitionDuration, defaultProps } from './common';
44
import type { ProgressProps } from './interface';
55
import getIndeterminateLine from './utils/getIndeterminateLine';
6+
import useId from './hooks/useId';
67

78
const Line: React.FC<ProgressProps> = (props) => {
89
const {
10+
id,
911
className,
1012
percent,
1113
prefixCls,
@@ -23,6 +25,8 @@ const Line: React.FC<ProgressProps> = (props) => {
2325
...props,
2426
};
2527

28+
const mergedId = useId(id);
29+
2630
// eslint-disable-next-line no-param-reassign
2731
delete restProps.gapPosition;
2832
const percentList = Array.isArray(percent) ? percent : [percent];
@@ -37,6 +41,7 @@ const Line: React.FC<ProgressProps> = (props) => {
3741
const viewBoxString = `0 0 100 ${strokeWidth}`;
3842
let stackPtg = 0;
3943
const { indeterminateStyleProps, indeterminateStyleAnimation } = getIndeterminateLine({
44+
id: mergedId,
4045
loading,
4146
percent: percentList[0],
4247
strokeLinecap,

src/common.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,3 @@ export const useTransitionDuration = (): SVGPathElement[] => {
4242

4343
return pathsRef.current;
4444
};
45-
46-
export const toArray = <T>(value: T | T[]): T[] => {
47-
const mergedValue = value ?? [];
48-
return Array.isArray(mergedValue) ? mergedValue : [mergedValue];
49-
};

src/utils/getIndeterminateCircle.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React from 'react';
22

33
interface IndeterminateOption {
4+
id: string;
45
loading: boolean;
56
}
67

7-
export default (options: IndeterminateOption) => {
8-
if (!options.loading) {
8+
export default ({ id, loading }: IndeterminateOption) => {
9+
if (!loading) {
910
return {
1011
indeterminateStyleProps: {},
1112
indeterminateStyleAnimation: null,
1213
};
1314
}
1415

15-
const animationName = 'circle-indeterminate-animate';
16+
const animationName = `${id}-indeterminate-animate`;
1617

1718
return {
1819
indeterminateStyleProps: {

src/utils/getIndeterminateLine.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import React from 'react';
22

33
interface IndeterminateOption {
4+
id: string;
45
loading: boolean;
56
percent: number;
67
strokeLinecap: string;
78
strokeWidth: number;
89
}
910

1011
export default (options: IndeterminateOption) => {
11-
const { percent, strokeLinecap, strokeWidth, loading } = options;
12+
const { id, percent, strokeLinecap, strokeWidth, loading } = options;
1213
if (!loading) {
1314
return {
1415
indeterminateStyleProps: {},
1516
indeterminateStyleAnimation: null,
1617
};
1718
}
18-
const animationName = 'line-indeterminate-animate';
19+
const animationName = `${id}-indeterminate-animate`;
1920
const strokeDashOffset = 100 - (percent + (strokeLinecap === 'round' ? strokeWidth : 0));
2021

2122
return {

tests/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports[` 1`] = `
2424
stroke="#2db7f5"
2525
stroke-linecap="butt"
2626
stroke-width="1"
27-
style="stroke-dasharray: 20px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: .3s, .3s, .3s, .06s;"
27+
style="stroke-dasharray: 20px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: 0s, 0s;"
2828
/>
2929
</svg>
3030
<br />
@@ -50,7 +50,7 @@ exports[` 1`] = `
5050
stroke="#2db7f5"
5151
stroke-linecap="round"
5252
stroke-width="1"
53-
style="stroke-dasharray: 19.8px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: .3s, .3s, .3s, .06s;"
53+
style="stroke-dasharray: 19.8px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: 0s, 0s;"
5454
/>
5555
</svg>
5656
<br />
@@ -76,7 +76,7 @@ exports[` 1`] = `
7676
stroke="#2db7f5"
7777
stroke-linecap="square"
7878
stroke-width="1"
79-
style="stroke-dasharray: 19.9px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: .3s, .3s, .3s, .06s;"
79+
style="stroke-dasharray: 19.9px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: 0s, 0s;"
8080
/>
8181
</svg>
8282
</div>

tests/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ describe('Progress', () => {
259259
const line = wrapper.find(Line);
260260
expect(circle.find('style')).toBeDefined();
261261
expect(circle.find('.rc-progress-circle-path').at(0).getDOMNode().style.animation).toContain(
262-
'circle-indeterminate-animate',
262+
'indeterminate-animate',
263263
);
264264
expect(line.find('style')).toBeDefined();
265265
expect(line.find('.rc-progress-line-path').at(0).getDOMNode().style.animation).toContain(
266-
'line-indeterminate-animate',
266+
'indeterminate-animate',
267267
);
268268
wrapper.unmount();
269269
});

0 commit comments

Comments
 (0)