-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code for shared functionality between vertical and horizonta…
…l stepper
- Loading branch information
1 parent
edd0a03
commit 8ddc6db
Showing
15 changed files
with
239 additions
and
86 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,41 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, Input} from '@angular/core'; | ||
import {CdkStep} from './stepper'; | ||
|
||
@Directive({ | ||
selector: 'cdkStepIcon' | ||
}) | ||
export class CdkStepIcon { | ||
/** Step of the icon to be displayed. */ | ||
@Input() | ||
step: CdkStep; | ||
|
||
/** Whether the step of the icon to be displayed is active. */ | ||
@Input() | ||
selected: boolean; | ||
|
||
/** Index of the step. */ | ||
@Input() | ||
index: number; | ||
|
||
/** Whether the user has touched the step that is not selected. */ | ||
get notTouched() { | ||
return this._getIndicatorType() == 'number' && !this.selected; | ||
} | ||
|
||
/** Returns the type of icon to be displayed. */ | ||
_getIndicatorType(): 'number' | 'edit' | 'done' { | ||
if (!this.step.completed || this.selected) { | ||
return 'number'; | ||
} else { | ||
return this.step.editable ? 'edit' : 'done'; | ||
} | ||
} | ||
} |
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,28 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, Input} from '@angular/core'; | ||
import {CdkStep} from './stepper'; | ||
|
||
@Directive({ | ||
selector: 'cdkStepLabelContainer' | ||
}) | ||
export class CdkStepLabelContainer { | ||
/** Step of the label to be displayed. */ | ||
@Input() | ||
step: CdkStep; | ||
|
||
/** Whether the step of label to be displayed is selected. */ | ||
@Input() | ||
selected: boolean; | ||
|
||
/** Whether the label to be displayed is active. */ | ||
get active() { | ||
return this.step.completed || this.selected; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div [ngSwitch]="_getIndicatorType()"> | ||
<span *ngSwitchCase="'number'">{{index + 1}}</span> | ||
<md-icon *ngSwitchCase="'edit'">create</md-icon> | ||
<md-icon *ngSwitchCase="'done'">done</md-icon> | ||
</div> |
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,83 @@ | ||
import {MdStepperModule} from './index'; | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, ViewChild} from '@angular/core'; | ||
import {MdStep, MdStepper} from './stepper'; | ||
import {MdStepIcon} from './step-icon'; | ||
import {By} from '@angular/platform-browser'; | ||
|
||
describe('MdStepIcon', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdStepperModule], | ||
declarations: [SimpleStepIconApp], | ||
providers: [ | ||
{provide: MdStepper, useClass: MdStepper} | ||
] | ||
}); | ||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('setting icon', () => { | ||
let stepIconComponent: MdStepIcon; | ||
let fixture: ComponentFixture<SimpleStepIconApp>; | ||
let testComponent: SimpleStepIconApp; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SimpleStepIconApp); | ||
fixture.detectChanges(); | ||
|
||
stepIconComponent = fixture.debugElement.query(By.css('md-step-icon')).componentInstance; | ||
testComponent = fixture.componentInstance; | ||
}); | ||
|
||
it('should set done icon if step is non-editable and completed', () => { | ||
stepIconComponent.selected = true; | ||
fixture.detectChanges(); | ||
|
||
expect(stepIconComponent._getIndicatorType()).toBe('number'); | ||
|
||
testComponent.mdStep.completed = true; | ||
testComponent.mdStep.editable = false; | ||
stepIconComponent.selected = false; | ||
fixture.detectChanges(); | ||
|
||
expect(stepIconComponent._getIndicatorType()).toBe('done'); | ||
}); | ||
|
||
it('should set create icon if step is editable and completed', () => { | ||
stepIconComponent.selected = true; | ||
fixture.detectChanges(); | ||
|
||
expect(stepIconComponent._getIndicatorType()).toBe('number'); | ||
|
||
testComponent.mdStep.completed = true; | ||
testComponent.mdStep.editable = true; | ||
stepIconComponent.selected = false; | ||
fixture.detectChanges(); | ||
|
||
expect(stepIconComponent._getIndicatorType()).toBe('edit'); | ||
}); | ||
|
||
it('should set "mat-step-icon-not-touched" class if the step ', () => { | ||
let stepIconEl = fixture.debugElement.query(By.css('md-step-icon')).nativeElement; | ||
|
||
testComponent.mdStep.completed = false; | ||
stepIconComponent.selected = false; | ||
fixture.detectChanges(); | ||
|
||
expect(stepIconComponent._getIndicatorType()).toBe('number'); | ||
expect(stepIconEl.classList).toContain('mat-step-icon-not-touched'); | ||
}); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<md-step>step</md-step> | ||
<md-step-icon [step]="mdStep"></md-step-icon> | ||
` | ||
}) | ||
class SimpleStepIconApp { | ||
@ViewChild(MdStep) mdStep: MdStep; | ||
} |
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,20 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
import {CdkStepIcon} from '@angular/cdk/stepper'; | ||
|
||
@Component({ | ||
selector: 'md-step-icon, mat-step-icon', | ||
templateUrl: 'step-icon.html', | ||
host: { | ||
'class': 'mat-step-icon', | ||
'[class.mat-step-icon-not-touched]': 'notTouched' | ||
} | ||
}) | ||
export class MdStepIcon extends CdkStepIcon { } |
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,9 @@ | ||
<div> | ||
<!-- If there is a label template, use it. --> | ||
<ng-container *ngIf="step.stepLabel" [ngTemplateOutlet]="step.stepLabel.template"> | ||
</ng-container> | ||
<!-- It there is no label template, fall back to the text label. --> | ||
<div *ngIf="!step.stepLabel">{{step.label}}</div> | ||
|
||
<div class="mat-step-optional" *ngIf="step.optional">Optional</div> | ||
</div> |
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,20 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
import {CdkStepLabelContainer} from '@angular/cdk/stepper'; | ||
|
||
@Component({ | ||
selector: 'md-step-label-container, mat-step-label-container', | ||
templateUrl: 'step-label-container.html', | ||
host: { | ||
'[class.mat-step-label-active]': 'active', | ||
'[class.mat-step-label-inactive]': '!active' | ||
} | ||
}) | ||
export class MdStepLabelContainer extends CdkStepLabelContainer { } |
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
Oops, something went wrong.