-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:steps): steps support circular progress bar
close #5684
- Loading branch information
1 parent
91e5d49
commit 83be548
Showing
8 changed files
with
204 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,16 @@ | ||
--- | ||
order: 12 | ||
title: | ||
zh-CN: 带有进度的步骤 | ||
en-US: Steps with progress | ||
--- | ||
|
||
## zh-CN | ||
|
||
异步执行的步骤带有圆形进度条。 | ||
|
||
## en-US | ||
|
||
Asynchronous steps with circular progress bar. | ||
|
||
|
This file contains 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,136 @@ | ||
import { Component, OnDestroy } from '@angular/core'; | ||
import { merge, Observable, timer } from 'rxjs'; | ||
import { delay, finalize, map, scan } from 'rxjs/operators'; | ||
|
||
interface SyncStep { | ||
id: number; | ||
title: string; | ||
description: string; | ||
async: false; | ||
percentage: null; | ||
} | ||
|
||
interface AsyncStep { | ||
id: number; | ||
title: string; | ||
description: string; | ||
async: true; | ||
percentage: number; | ||
} | ||
|
||
type Step = SyncStep | AsyncStep; | ||
|
||
function mockAsyncStep(): Observable<number> { | ||
const subStep1 = timer(600).pipe(map(() => 25)); | ||
const subStep2 = subStep1.pipe(delay(600)); | ||
const subStep3 = subStep2.pipe(delay(600)); | ||
const subStep4 = subStep3.pipe(delay(600)); | ||
return merge(subStep1, subStep2, subStep3, subStep4).pipe(scan((a, b) => a + b)); | ||
} | ||
|
||
@Component({ | ||
selector: 'nz-demo-steps-progress', | ||
template: ` | ||
<nz-steps [nzCurrent]="current"> | ||
<nz-step | ||
*ngFor="let step of this.steps; trackBy: trackById" | ||
[nzTitle]="step.title" | ||
[nzDescription]="step.description" | ||
[nzPercentage]="step.async ? step.percentage : null" | ||
></nz-step> | ||
</nz-steps> | ||
<div class="steps-action"> | ||
<button nz-button nzType="default" (click)="pre()" *ngIf="current > 0"> | ||
<span>Previous</span> | ||
</button> | ||
<button nz-button nzType="default" (click)="next()" [nzLoading]="processing" *ngIf="current < 2"> | ||
<span>Next</span> | ||
</button> | ||
<button nz-button nzType="primary" (click)="done()" [nzLoading]="processing" *ngIf="current === 2"> | ||
<span>Done</span> | ||
</button> | ||
</div> | ||
`, | ||
styles: [ | ||
` | ||
.steps-action { | ||
margin-top: 36px; | ||
} | ||
button { | ||
margin-right: 8px; | ||
} | ||
` | ||
] | ||
}) | ||
export class NzDemoStepsProgressComponent implements OnDestroy { | ||
steps: Step[] = [ | ||
{ | ||
id: 1, | ||
title: `Step 1`, | ||
description: `This step is synchronous.`, | ||
async: false, | ||
percentage: null | ||
}, | ||
{ | ||
id: 2, | ||
title: `Step 2`, | ||
description: `This step is asynchronous.`, | ||
async: true, | ||
percentage: 0 | ||
}, | ||
{ | ||
id: 3, | ||
title: `Step 3`, | ||
description: `This step is asynchronous.`, | ||
async: true, | ||
percentage: 0 | ||
} | ||
]; | ||
intervalId = -1; | ||
current = 0; | ||
processing = false; | ||
|
||
pre(): void { | ||
this.current -= 1; | ||
} | ||
|
||
next(): void { | ||
this.loadingAndStep(); | ||
} | ||
|
||
done(): void { | ||
this.loadingAndStep(); | ||
console.log('done'); | ||
} | ||
|
||
trackById(_: number, item: Step): number { | ||
return item.id; | ||
} | ||
|
||
loadingAndStep(): void { | ||
if (this.current < this.steps.length) { | ||
const step = this.steps[this.current]; | ||
if (step.async) { | ||
this.processing = true; | ||
mockAsyncStep() | ||
.pipe( | ||
finalize(() => { | ||
step.percentage = 0; | ||
this.processing = false; | ||
this.current += 1; | ||
}) | ||
) | ||
.subscribe(p => { | ||
step.percentage = p; | ||
}); | ||
} else { | ||
this.current += 1; | ||
} | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
clearInterval(this.intervalId); | ||
} | ||
} |
This file contains 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 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 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 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 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