-
-
Notifications
You must be signed in to change notification settings - Fork 160
feat(circle,line): enable indeterminate mode #216
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
Merged
afc163
merged 8 commits into
react-component:master
from
SaidMarar:feature/indeterminate
Mar 9, 2025
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ff7712
feat(circle,line): enable indeterminate mode
SaidMarar c22e2af
add loading property to enable indeterminate mode
SaidMarar 4202892
merge
SaidMarar 502b57b
update code
SaidMarar e645a90
fix coverage and generate id
SaidMarar cc2fd04
merge master
SaidMarar 4239195
fix: extra space, type and coverage
SaidMarar ef86c31
fix lint
SaidMarar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| title: loading | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/loading.tsx"></code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 Loading = () => { | ||
| return ( | ||
| <div style={{ margin: 10, width: 200 }}> | ||
| <Circle loading percent={10} /> | ||
| <Line loading percent={50} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Loading; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import React from 'react'; | ||
|
|
||
| interface IndeterminateOption { | ||
| id: string; | ||
| loading: boolean; | ||
| } | ||
|
|
||
| export default ({ id, loading }: IndeterminateOption) => { | ||
| if (!loading) { | ||
| return { | ||
| indeterminateStyleProps: {}, | ||
| indeterminateStyleAnimation: null, | ||
| }; | ||
| } | ||
|
|
||
| const animationName = `${id}-indeterminate-animate`; | ||
|
|
||
| return { | ||
| indeterminateStyleProps: { | ||
| transform: 'rotate(0deg)', | ||
| animation: `${animationName} 1s linear infinite`, | ||
| }, | ||
| indeterminateStyleAnimation: ( | ||
| <style> | ||
| {`@keyframes ${animationName} { | ||
| 0% { transform: rotate(0deg);} | ||
| 100% {transform: rotate(360deg);} | ||
| }`} | ||
| </style> | ||
| ), | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { StrokeLinecapType } from '@/interface'; | ||
| import React from 'react'; | ||
|
|
||
| interface IndeterminateOption { | ||
| id: string; | ||
| loading: boolean; | ||
| percent: number; | ||
| strokeLinecap: StrokeLinecapType; | ||
| strokeWidth: number; | ||
| } | ||
|
|
||
| export default (options: IndeterminateOption) => { | ||
| const { id, percent, strokeLinecap, strokeWidth, loading } = options; | ||
| if (!loading) { | ||
| return { | ||
| indeterminateStyleProps: {}, | ||
| indeterminateStyleAnimation: null, | ||
| }; | ||
| } | ||
| const animationName = `${id}-indeterminate-animate`; | ||
| const strokeDashOffset = 100 - (percent + (strokeLinecap === 'round' ? strokeWidth : 0)); | ||
|
|
||
| return { | ||
| indeterminateStyleProps: { | ||
| strokeDasharray: `${percent} 100`, | ||
| animation: `${animationName} .6s linear alternate infinite`, | ||
| strokeDashoffset: 0, | ||
| }, | ||
| indeterminateStyleAnimation: ( | ||
| <style> | ||
| {`@keyframes ${animationName} { | ||
| 0% { stroke-dashoffset: 0; } | ||
| 100% { stroke-dashoffset: -${strokeDashOffset}; | ||
| }`} | ||
| </style> | ||
| ), | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import React from 'react'; | ||
| import { Circle, Line } from '../src'; | ||
| import { render, waitFor } from '@testing-library/react'; | ||
|
|
||
| describe('(Circle | Line).indeterminate', () => { | ||
| describe('Line', () => { | ||
| it('should render indeterminate style', () => { | ||
| const { container, rerender } = render(<Line loading />); | ||
| const line: HTMLElement = container.querySelector('.rc-progress-line-path'); | ||
|
|
||
| expect(line.style.animation).toContain('indeterminate-animate'); | ||
|
|
||
| rerender(<Line />); | ||
|
|
||
| expect(line.style.animation).not.toContain('indeterminate-animate'); | ||
| }); | ||
|
|
||
| it('should render indeterminate with percent and rerennder without it', () => { | ||
| const { container, rerender } = render(<Line percent={20} loading />); | ||
| const line: HTMLElement = container.querySelector('.rc-progress-line-path'); | ||
|
|
||
| expect(line.style.animation).toContain('indeterminate-animate'); | ||
| expect(line.style.strokeDasharray).toEqual('20 100'); | ||
|
|
||
| rerender(<Line percent={20} />); | ||
|
|
||
| expect(line.style.animation).not.toContain('indeterminate-animate'); | ||
| expect(line.style.strokeDasharray).not.toEqual('20 100'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Circle', () => { | ||
| it('should render indeterminate style', () => { | ||
| const { container, rerender } = render(<Circle loading />); | ||
| const circle: HTMLElement = container.querySelector('.rc-progress-circle-path'); | ||
|
|
||
| expect(circle.style.animation).toContain('indeterminate-animate'); | ||
|
|
||
| rerender(<Circle />); | ||
|
|
||
| expect(circle.style.animation).not.toContain('indeterminate-animate'); | ||
| }); | ||
|
|
||
| it('should rerender indeterminate with percent Circle', () => { | ||
| const { container, rerender } = render(<Circle percent={20} loading />); | ||
| const circle: HTMLElement = container.querySelector('.rc-progress-circle-path'); | ||
|
|
||
| expect(circle.style.animation).toContain('indeterminate-animate'); | ||
| expect(circle.style.transform).toEqual('rotate(0deg)'); | ||
|
|
||
| rerender(<Circle percent={20} />); | ||
|
|
||
| expect(circle.style.animation).not.toContain('indeterminate-animate'); | ||
| expect(circle.style.transform).not.toEqual('rotate(0deg)'); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.