Skip to content

Commit ec3993a

Browse files
committed
Simplify code based on review
1 parent a1f1977 commit ec3993a

19 files changed

+175
-271
lines changed

src/cdk/stepper/public_api.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ import {CdkStepper, CdkStep} from './stepper';
1111
import {CommonModule} from '@angular/common';
1212
import {CdkStepLabel} from './step-label';
1313
import {CdkStepperNext, CdkStepperPrevious} from './stepper-button';
14-
import {CdkStepHeader} from './step-header';
15-
import {CdkStepContent} from './step-content';
1614

1715
@NgModule({
1816
imports: [CommonModule],
19-
exports: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious, CdkStepHeader,
20-
CdkStepContent],
21-
declarations: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious,
22-
CdkStepHeader, CdkStepContent]
17+
exports: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious],
18+
declarations: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious]
2319
})
2420
export class CdkStepperModule {}
2521

2622
export * from './stepper';
2723
export * from './step-label';
2824
export * from './stepper-button';
29-
export * from './step-header';
30-
export * from './step-content';

src/cdk/stepper/step-content.ts

-61
This file was deleted.

src/cdk/stepper/step-header.ts

-71
This file was deleted.

src/cdk/stepper/stepper.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
Component,
2121
ContentChild,
2222
ViewChild,
23-
TemplateRef
23+
TemplateRef,
24+
ViewEncapsulation
2425
} from '@angular/core';
2526
import {LEFT_ARROW, RIGHT_ARROW, ENTER, SPACE} from '@angular/cdk/keycodes';
2627
import {CdkStepLabel} from './step-label';
@@ -53,7 +54,8 @@ export class StepperSelectionEvent {
5354

5455
@Component({
5556
selector: 'cdk-step',
56-
templateUrl: 'step.html'
57+
templateUrl: 'step.html',
58+
encapsulation: ViewEncapsulation.None
5759
})
5860
export class CdkStep {
5961
/** Template for step label if it exists. */
@@ -138,8 +140,8 @@ export class CdkStepper {
138140
@Input()
139141
get selectedIndex() { return this._selectedIndex; }
140142
set selectedIndex(index: number) {
141-
if (index < this._selectedIndex && !this._steps.toArray()[index].editable) { return; }
142-
if (this._anyControlsInvalid(index)) {
143+
if (this._anyControlsInvalid(index)
144+
|| index < this._selectedIndex && !this._steps.toArray()[index].editable) {
143145
// remove focus from clicked step header if the step is not able to be selected
144146
this._stepHeader.toArray()[index].nativeElement.blur();
145147
} else if (this._selectedIndex != index) {
@@ -202,6 +204,16 @@ export class CdkStepper {
202204
}
203205
}
204206

207+
/** Returns the type of icon to be displayed. */
208+
_getIndicatorType(index: number): 'number' | 'edit' | 'done' {
209+
const step = this._steps.toArray()[index];
210+
if (!step.completed || this._selectedIndex == index) {
211+
return 'number';
212+
} else {
213+
return step.editable ? 'edit' : 'done';
214+
}
215+
}
216+
205217
private _emitStepperSelectionEvent(newIndex: number): void {
206218
const stepsArray = this._steps.toArray();
207219
this.selectionChange.emit({

src/lib/stepper/_stepper-theme.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
background-color: mat-color($background, hover);
1414
}
1515
}
16-
.mat-step-header {
1716

17+
.mat-step-header {
1818
.mat-step-label-active {
1919
color: mat-color($foreground, text);
2020
}

src/lib/stepper/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {MdStepLabel} from './step-label';
1919
import {MdStepperNext, MdStepperPrevious} from './stepper-button';
2020
import {MdIconModule} from '../icon/index';
2121
import {MdStepHeader} from './step-header';
22-
import {MdStepContent} from './step-content';
2322

2423
@NgModule({
2524
imports: [
@@ -31,9 +30,9 @@ import {MdStepContent} from './step-content';
3130
MdIconModule
3231
],
3332
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
34-
MdStepperNext, MdStepperPrevious, MdStepHeader, MdStepContent],
33+
MdStepperNext, MdStepperPrevious, MdStepHeader],
3534
declarations: [MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
36-
MdStepperNext, MdStepperPrevious, MdStepHeader, MdStepContent],
35+
MdStepperNext, MdStepperPrevious, MdStepHeader],
3736
})
3837
export class MdStepperModule {}
3938

@@ -43,4 +42,3 @@ export * from './step-label';
4342
export * from './stepper';
4443
export * from './stepper-button';
4544
export * from './step-header';
46-
export * from './step-content';

src/lib/stepper/step-content.html

-3
This file was deleted.

src/lib/stepper/step-content.scss

-6
This file was deleted.

src/lib/stepper/step-content.ts

-30
This file was deleted.

src/lib/stepper/step-header.html

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
<div [class.mat-horizontal-stepper-header]="horizontal"
2-
[class.mat-vertical-stepper-header]="!horizontal">
3-
<div [class.mat-step-icon]="_getIndicatorType() != 'number' || selected"
4-
[class.mat-step-icon-not-touched]="_getIndicatorType() == 'number' && !selected"
5-
[ngSwitch]="_getIndicatorType()">
6-
<span *ngSwitchCase="'number'">{{index + 1}}</span>
7-
<md-icon *ngSwitchCase="'edit'">create</md-icon>
8-
<md-icon *ngSwitchCase="'done'">done</md-icon>
9-
</div>
10-
<div [class.mat-step-label-active]="step.completed || selected"
11-
[class.mat-step-label-inactive]="!step.completed && !selected">
12-
<!-- If there is a label template, use it. -->
13-
<ng-container *ngIf="step.stepLabel" [ngTemplateOutlet]="step.stepLabel.template">
14-
</ng-container>
15-
<!-- It there is no label template, fall back to the text label. -->
16-
<div class="text-label" *ngIf="!step.stepLabel">{{step.label}}</div>
1+
<div [class.mat-step-icon]="icon != 'number' || selected"
2+
[class.mat-step-icon-not-touched]="icon == 'number' && !selected">
3+
<span *ngIf="icon == 'number'">{{index + 1}}</span>
4+
<md-icon *ngIf="icon == 'edit'">create</md-icon>
5+
<md-icon *ngIf="icon == 'done'">done</md-icon>
6+
</div>
7+
<div [class.mat-step-label-active]="active"
8+
[class.mat-step-label-inactive]="!active">
9+
<!-- If there is a label template, use it. -->
10+
<ng-container *ngIf="stepLabel" [ngTemplateOutlet]="stepLabel.template">
11+
</ng-container>
12+
<!-- It there is no label template, fall back to the text label. -->
13+
<div class="mat-step-text-label" *ngIf="!stepLabel">{{label}}</div>
1714

18-
<div class="mat-step-optional" *ngIf="step.optional">Optional</div>
19-
</div>
15+
<div class="mat-step-optional" *ngIf="optional">Optional</div>
2016
</div>
17+

src/lib/stepper/step-header.scss

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
$mat-horizontal-stepper-header-height: 72px !default;
21
$mat-stepper-label-header-height: 24px !default;
32
$mat-stepper-label-min-width: 50px !default;
43
$mat-stepper-side-gap: 24px !default;
@@ -10,32 +9,6 @@ $mat-step-optional-font-size: 12px;
109
display: flex;
1110
}
1211

13-
.mat-horizontal-stepper-header {
14-
display: flex;
15-
height: $mat-horizontal-stepper-header-height;
16-
overflow: hidden;
17-
align-items: center;
18-
padding: 0 $mat-stepper-side-gap;
19-
20-
.mat-step-icon,
21-
.mat-step-icon-not-touched {
22-
margin-right: $mat-stepper-line-gap;
23-
flex: none;
24-
}
25-
}
26-
27-
.mat-vertical-stepper-header {
28-
display: flex;
29-
align-items: center;
30-
padding: $mat-stepper-side-gap;
31-
max-height: $mat-stepper-label-header-height;
32-
33-
.mat-step-icon,
34-
.mat-step-icon-not-touched {
35-
margin-right: $mat-vertical-stepper-content-margin - $mat-stepper-side-gap;
36-
}
37-
}
38-
3912
.mat-step-optional {
4013
font-size: $mat-step-optional-font-size;
4114
}
@@ -60,7 +33,7 @@ $mat-step-optional-font-size: 12px;
6033
vertical-align: middle;
6134
}
6235

63-
.text-label {
36+
.mat-step-text-label {
6437
text-overflow: ellipsis;
6538
overflow: hidden;
6639
}

0 commit comments

Comments
 (0)