-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
refactor(module:steps): refactor steps #2512
Merged
Merged
Changes from all commits
Commits
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 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,3 @@ | ||
export interface ClassMap { | ||
[ key: string ]: boolean; | ||
} |
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,3 @@ | ||
export function classMapToString(map: { [ key: string ]: boolean }): string { | ||
return Object.keys(map).filter(item => !!map[ item ]).join(' '); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,76 @@ | ||
import { | ||
Component, | ||
ElementRef, | ||
Input, | ||
TemplateRef, | ||
ViewChild | ||
} from '@angular/core'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core'; | ||
|
||
import { NzUpdateHostClassService } from '../core/services/update-host-class.service'; | ||
import { NgClassType } from '../core/types/ng-class'; | ||
|
||
@Component({ | ||
changeDetection : ChangeDetectionStrategy.OnPush, | ||
encapsulation : ViewEncapsulation.None, | ||
selector : 'nz-step', | ||
providers : [ NzUpdateHostClassService ], | ||
preserveWhitespaces: false, | ||
templateUrl : './nz-step.component.html' | ||
templateUrl : './nz-step.component.html', | ||
host : { | ||
'[class.ant-steps-item]' : 'true', | ||
'[class.ant-steps-item-wait]' : 'nzStatus === "wait"', | ||
'[class.ant-steps-item-process]': 'nzStatus === "process"', | ||
'[class.ant-steps-item-finish]' : 'nzStatus === "finish"', | ||
'[class.ant-steps-item-error]' : 'nzStatus === "error"', | ||
'[class.ant-steps-custom]' : '!!nzIcon', | ||
'[class.ant-steps-next-error]' : '(outStatus === "error") && (currentIndex === index + 1)' | ||
} | ||
}) | ||
export class NzStepComponent { | ||
private _status = 'wait'; | ||
private _currentIndex = 0; | ||
private _description: string | TemplateRef<void>; | ||
private _icon: NgClassType | TemplateRef<void>; | ||
private _title: string | TemplateRef<void>; | ||
private el: HTMLElement = this.elementRef.nativeElement; | ||
oldAPIIcon = true; // Make the user defined icon compatible to old API. Should be removed in 2.0. | ||
isCustomStatus = false; | ||
isDescriptionString = true; | ||
isTitleString = true; | ||
isIconString = true; | ||
last = false; | ||
showProcessDot = false; | ||
direction = 'horizontal'; | ||
outStatus = 'process'; | ||
index = 0; | ||
@ViewChild('processDotTemplate') processDotTemplate: TemplateRef<void>; | ||
customProcessTemplate: TemplateRef<{ $implicit: TemplateRef<void>, status: string, index: number }>; | ||
|
||
@Input() | ||
set nzTitle(value: string | TemplateRef<void>) { | ||
this.isTitleString = !(value instanceof TemplateRef); | ||
this._title = value; | ||
} | ||
@Input() nzTitle: string | TemplateRef<void>; | ||
@Input() nzDescription: string | TemplateRef<void>; | ||
|
||
get nzTitle(): string | TemplateRef<void> { | ||
return this._title; | ||
@Input() | ||
get nzStatus(): string { return this._status; } | ||
set nzStatus(status: string) { | ||
this._status = status; | ||
this.isCustomStatus = true; | ||
} | ||
isCustomStatus = false; | ||
private _status = 'wait'; | ||
|
||
@Input() | ||
get nzIcon(): NgClassType | TemplateRef<void> { return this._icon; } | ||
set nzIcon(value: NgClassType | TemplateRef<void>) { | ||
if (!(value instanceof TemplateRef)) { | ||
this.isIconString = true; | ||
if (typeof value === 'string') { | ||
const str = value as string; | ||
this.oldAPIIcon = str.indexOf('anticon') > -1; | ||
} else { | ||
this.oldAPIIcon = true; | ||
} | ||
this.oldAPIIcon = typeof value === 'string' && value.indexOf('anticon') > -1; | ||
} else { | ||
this.isIconString = false; | ||
} | ||
this._icon = value; | ||
} | ||
oldAPIIcon = true; | ||
isIconString = true; | ||
private _icon: NgClassType | TemplateRef<void>; | ||
|
||
get nzIcon(): NgClassType | TemplateRef<void> { | ||
return this._icon; | ||
} | ||
|
||
@Input() | ||
set nzStatus(status: string) { | ||
this._status = status; | ||
this.isCustomStatus = true; | ||
this.updateClassMap(); | ||
} | ||
|
||
get nzStatus(): string { | ||
return this._status; | ||
} | ||
|
||
@Input() | ||
set nzDescription(value: string | TemplateRef<void>) { | ||
this.isDescriptionString = !(value instanceof TemplateRef); | ||
this._description = value; | ||
} | ||
|
||
get nzDescription(): string | TemplateRef<void> { | ||
return this._description; | ||
} | ||
|
||
get currentIndex(): number { | ||
return this._currentIndex; | ||
} | ||
customProcessTemplate: TemplateRef<{ $implicit: TemplateRef<void>, status: string, index: number }>; // Set by parent. | ||
direction = 'horizontal'; | ||
index = 0; | ||
last = false; | ||
outStatus = 'process'; | ||
showProcessDot = false; | ||
|
||
get currentIndex(): number { return this._currentIndex; } | ||
set currentIndex(current: number) { | ||
this._currentIndex = current; | ||
if (!this.isCustomStatus) { | ||
if (current > this.index) { | ||
this._status = 'finish'; | ||
} else if (current === this.index) { | ||
if (this.outStatus) { | ||
this._status = this.outStatus; | ||
} | ||
} else { | ||
this._status = 'wait'; | ||
} | ||
this._status = current > this.index | ||
? 'finish' | ||
: current === this.index | ||
? this.outStatus || '' | ||
: 'wait'; | ||
} | ||
this.updateClassMap(); | ||
} | ||
private _currentIndex = 0; | ||
|
||
updateClassMap(): void { | ||
const classMap = { | ||
[ 'ant-steps-item' ] : true, | ||
[ `ant-steps-item-wait` ] : this.nzStatus === 'wait', | ||
[ `ant-steps-item-process` ]: this.nzStatus === 'process', | ||
[ `ant-steps-item-finish` ] : this.nzStatus === 'finish', | ||
[ `ant-steps-item-error` ] : this.nzStatus === 'error', | ||
[ 'ant-steps-custom' ] : !!this.nzIcon, | ||
[ 'ant-steps-next-error' ] : (this.outStatus === 'error') && (this.currentIndex === this.index + 1) | ||
}; | ||
this.nzUpdateHostClassService.updateHostClass(this.el, classMap); | ||
} | ||
constructor(private cdr: ChangeDetectorRef) {} | ||
|
||
constructor(private elementRef: ElementRef, private nzUpdateHostClassService: NzUpdateHostClassService) { | ||
detectChanges(): void { | ||
this.cdr.detectChanges(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div class="ant-steps" [ngClass]="stepsClassMap"> | ||
<div class="ant-steps" [ngClass]="classMap"> | ||
<ng-content></ng-content> | ||
</div> |
Oops, something went wrong.
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.
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.
all setter should be after getter
https://angular.io/guide/component-interaction#intercept-input-property-changes-with-a-setter