-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcommon.ts
44 lines (38 loc) · 1.09 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useRef, useEffect } from 'react';
import type { ProgressProps } from './interface';
export const defaultProps: Partial<ProgressProps> = {
className: '',
percent: 0,
prefixCls: 'rc-progress',
strokeColor: '#2db7f5',
strokeLinecap: 'round',
strokeWidth: 1,
style: { overflow: 'visible' },
trailColor: '#D9D9D9',
trailWidth: 1,
};
export const useTransitionDuration = (percentList: number[]) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const paths = percentList.map(() => useRef());
const prevTimeStamp = useRef(null);
useEffect(() => {
const now = Date.now();
let updated = false;
Object.keys(paths).forEach((key) => {
const path = paths[key].current;
if (!path) {
return;
}
updated = true;
const pathStyle = path.style;
pathStyle.transitionDuration = '.3s, .3s, .3s, .06s';
if (prevTimeStamp.current && now - prevTimeStamp.current < 100) {
pathStyle.transitionDuration = '0s, 0s';
}
});
if (updated) {
prevTimeStamp.current = Date.now();
}
});
return [paths];
};