-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(module:progress): add indeterminate state #9677
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,14 @@ | ||
| --- | ||
| order: 11 | ||
| title: | ||
| zh-CN: 不确定进度 | ||
| en-US: Indeterminate | ||
| --- | ||
|
|
||
| ## zh-CN | ||
|
|
||
| 当无法确定任务的具体进度时,可以使用不确定状态的进度条,展示持续加载动画。 | ||
|
|
||
| ## en-US | ||
|
|
||
| When the exact progress of a task is unknown, use an indeterminate progress bar to show continuous loading animation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| import { NzFlexModule } from 'ng-zorro-antd/flex'; | ||
| import { NzProgressModule } from 'ng-zorro-antd/progress'; | ||
|
|
||
| @Component({ | ||
| selector: 'nz-demo-progress-indeterminate', | ||
| imports: [NzFlexModule, NzProgressModule], | ||
| template: ` | ||
| <div nz-flex nzVertical nzGap="small"> | ||
| <nz-progress [nzIndeterminate]="true"></nz-progress> | ||
| <nz-progress [nzIndeterminate]="true" nzStatus="exception"></nz-progress> | ||
| <nz-progress [nzIndeterminate]="true" nzStatus="success"></nz-progress> | ||
| <nz-progress [nzIndeterminate]="true" [nzShowInfo]="false"></nz-progress> | ||
| </div> | ||
| ` | ||
| }) | ||
| export class NzDemoProgressIndeterminateComponent {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,19 @@ describe('progress', () => { | |
| ); | ||
| }); | ||
|
|
||
| it('should indeterminate work', () => { | ||
| fixture.detectChanges(); | ||
| expect(progress.nativeElement.firstElementChild!.classList).not.toContain('ant-progress-indeterminate'); | ||
|
|
||
| testComponent.indeterminate = true; | ||
| fixture.detectChanges(); | ||
| expect(progress.nativeElement.firstElementChild!.classList).toContain('ant-progress-indeterminate'); | ||
|
|
||
| // Should only work with line type | ||
| const progressBar = progress.nativeElement.querySelector('.ant-progress-bg'); | ||
| expect(progressBar).toBeTruthy(); | ||
| }); | ||
|
Contributor
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. The test correctly verifies the positive case for You could add this at the end of the test: // Should not work with other types
testComponent.type = 'circle';
fixture.detectChanges();
expect(progress.nativeElement.firstElementChild!.classList).not.toContain('ant-progress-indeterminate');
Comment on lines
+183
to
+194
|
||
|
|
||
| it('should support steps mode', () => { | ||
| testComponent.steps = 5; | ||
| testComponent.percent = 50; | ||
|
|
@@ -447,6 +460,7 @@ describe('progress', () => { | |
| [nzStrokeColor]="strokeColor" | ||
| [nzStrokeLinecap]="strokeLinecap" | ||
| [nzSteps]="steps" | ||
| [nzIndeterminate]="indeterminate" | ||
| ></nz-progress> | ||
| <ng-template #formatterTemplate let-percent>{{ percent }} / 100</ng-template> | ||
| ` | ||
|
|
@@ -463,6 +477,7 @@ export class NzTestProgressLineComponent { | |
| strokeLinecap: NzProgressStrokeLinecapType = 'round'; | ||
| steps?: number; | ||
| strokeColor?: NzProgressStrokeColorType; | ||
| indeterminate = false; | ||
| } | ||
|
|
||
| @Component({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,6 +122,31 @@ | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| &-indeterminate&-line { | ||||||||||
| .@{progress-prefix-cls}-bg { | ||||||||||
| position: relative; | ||||||||||
| width: 100% !important; | ||||||||||
| overflow: hidden; | ||||||||||
|
Comment on lines
+127
to
+129
Contributor
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. The |
||||||||||
|
|
||||||||||
| &::before { | ||||||||||
| position: absolute; | ||||||||||
| top: 0; | ||||||||||
| bottom: 0; | ||||||||||
| left: 0; | ||||||||||
| width: 200%; | ||||||||||
| background-image: repeating-linear-gradient( | ||||||||||
| -45deg, | ||||||||||
| transparent, | ||||||||||
| transparent 8px, | ||||||||||
| rgba(255, 255, 255, 0.25) 8px, | ||||||||||
| rgba(255, 255, 255, 0.25) 16px | ||||||||||
| ); | ||||||||||
| animation: ~'@{ant-prefix}-progress-indeterminate' 1s linear infinite; | ||||||||||
| content: ''; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| &-status-exception { | ||||||||||
| .@{progress-prefix-cls}-bg { | ||||||||||
| background-color: @error-color; | ||||||||||
|
|
@@ -207,4 +232,14 @@ | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @keyframes ~"@{ant-prefix}-progress-indeterminate" { | ||||||||||
| 0% { | ||||||||||
| transform: translateX(0); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| 100% { | ||||||||||
|
||||||||||
| 100% { | |
| 100% { | |
| // 22.627px ≈ 16 * √2: move by one diagonal of the 16px diagonal stripe pattern | |
| // to ensure the indeterminate animation loops seamlessly with the repeating gradient. |
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.
According to the coding guidelines, all components should set
changeDetection: ChangeDetectionStrategy.OnPushin the@Componentdecorator. This is missing from this demo component but is present in all other demo components in the codebase. Adding this will improve performance by reducing unnecessary change detection cycles.