-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(circle,line): enable indeterminate mode #216
base: master
Are you sure you want to change the base?
Changes from 1 commit
9ff7712
c22e2af
4202892
502b57b
e645a90
cc2fd04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## indeterminate | ||
|
||
<code src="../examples/indeterminate.tsx"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import { Line, Circle } from 'rc-progress'; | ||
|
||
const Indeterminate = () => { | ||
return ( | ||
<div style={{ margin: 10, width: 200 }}> | ||
<Circle /> | ||
<Line /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Indeterminate; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||
interface IndeterminateOption { | ||||||||||||||||||
percent: number | number[]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export default (options: IndeterminateOption) => { | ||||||||||||||||||
if (options.percent !== null) { | ||||||||||||||||||
return { | ||||||||||||||||||
...options, | ||||||||||||||||||
indeterminateStylePops: {}, | ||||||||||||||||||
indeterminateStyleTag: null, | ||||||||||||||||||
}; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
const animationName = 'circle-indeterminate-animate'; | ||||||||||||||||||
const percent = 40; | ||||||||||||||||||
|
||||||||||||||||||
return { | ||||||||||||||||||
percent, | ||||||||||||||||||
indeterminateStylePops: { | ||||||||||||||||||
transform: 'rotate(0deg)', | ||||||||||||||||||
animation: `${animationName} 1s linear infinite`, | ||||||||||||||||||
}, | ||||||||||||||||||
indeterminateStyleTag: ( | ||||||||||||||||||
<style> | ||||||||||||||||||
{`@keyframes ${animationName} { | ||||||||||||||||||
0 % { transform: rotate(0deg);} | ||||||||||||||||||
100% {transform: rotate(360deg);} | ||||||||||||||||||
}`} | ||||||||||||||||||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修复 keyframes 语法中的空格问题 当前 keyframes 定义中的百分比值与大括号之间存在多余的空格,这可能导致样式解析错误。 建议修改如下: {`@keyframes ${animationName} {
- 0 % { transform: rotate(0deg);}
- 100% {transform: rotate(360deg);}
+ 0% { transform: rotate(0deg); }
+ 100% { transform: rotate(360deg); }
}`} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
</style> | ||||||||||||||||||
), | ||||||||||||||||||
}; | ||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interface IndeterminateOption { | ||
percent: number | number[]; | ||
strokeLinecap: string; | ||
strokeWidth: number; | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议使用更严格的类型定义 strokeLinecap 应使用 StrokeLinecapType 类型而不是 string,以确保类型安全。 建议修改如下: interface IndeterminateOption {
id: string;
loading: boolean;
percent: number;
- strokeLinecap: string;
+ strokeLinecap: 'round' | 'butt' | 'square';
strokeWidth: number;
} |
||
} | ||
|
||
export default (options: IndeterminateOption) => { | ||
if (options.percent !== null) { | ||
return { | ||
percent: options.percent, | ||
indeterminateStylePops: {}, | ||
indeterminateStyleTag: null, | ||
}; | ||
} | ||
const animationName = 'line-indeterminate-animate'; | ||
const percent = 40; | ||
const strokeDashOffset = | ||
100 - (percent + (options.strokeLinecap === 'round' ? options.strokeWidth : 0)); | ||
|
||
return { | ||
percent, | ||
indeterminateStylePops: { | ||
strokeDasharray: `${percent} 100`, | ||
animation: `${animationName} .6s linear alternate infinite`, | ||
strokeDashoffset: 0, | ||
}, | ||
indeterminateStyleTag: ( | ||
<style> | ||
{`@keyframes ${animationName} { | ||
0% { stroke-dashoffset: 0; } | ||
100% { stroke-dashoffset: -${strokeDashOffset}; | ||
}`} | ||
</style> | ||
), | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not hard code this. Follow id generation logic to dynamic create this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zombieJ
Just added could you check please, and one more thing is when we are using useId hook inside Line component it performs another render which changes the transition-duration like in Circle, so that's why i updated the snapshot.
arfter this change i tested on demo and i see no impacts.