Skip to content

Commit 726ce77

Browse files
committed
docs(stepper): add embedded examples
1 parent 9f48437 commit 726ce77

File tree

7 files changed

+157
-0
lines changed

7 files changed

+157
-0
lines changed

src/lib/stepper/stepper.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ In order to use the custom step states, you must add the `displayDefaultIndicato
202202
})
203203
```
204204

205+
<!-- example(stepper-states) -->
206+
205207
### Error State
206208

207209
The stepper can now show error states by simply providing the `showError` option to the `MAT_STEPPER_GLOBAL_OPTIONS` in your application's root module as mentioned above.
@@ -217,6 +219,8 @@ The stepper can now show error states by simply providing the `showError` option
217219
})
218220
```
219221

222+
<!-- example(stepper-errors) -->
223+
220224
### Keyboard interaction
221225
- <kbd>LEFT_ARROW</kbd>: Focuses the previous step header
222226
- <kbd>RIGHT_ARROW</kbd>: Focuses the next step header

src/material-examples/stepper-errors/stepper-errors-example.css

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<mat-horizontal-stepper linear #stepper>
2+
<mat-step [stepControl]="firstFormGroup" errorMessage="Name is required.">
3+
<form [formGroup]="firstFormGroup">
4+
<ng-template matStepLabel>Fill out your name</ng-template>
5+
<mat-form-field>
6+
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
7+
</mat-form-field>
8+
<div>
9+
<button mat-button matStepperNext>Next</button>
10+
</div>
11+
</form>
12+
</mat-step>
13+
<mat-step [stepControl]="secondFormGroup" errorMessage="Address is required.">
14+
<form [formGroup]="secondFormGroup">
15+
<ng-template matStepLabel>Fill out your address</ng-template>
16+
<mat-form-field>
17+
<input matInput placeholder="Address" formControlName="secondCtrl" required>
18+
</mat-form-field>
19+
<div>
20+
<button mat-button matStepperPrevious>Back</button>
21+
<button mat-button matStepperNext>Next</button>
22+
</div>
23+
</form>
24+
</mat-step>
25+
<mat-step>
26+
<ng-template matStepLabel>Done</ng-template>
27+
You are now done.
28+
<div>
29+
<button mat-button matStepperPrevious>Back</button>
30+
<button mat-button (click)="stepper.reset()">Reset</button>
31+
</div>
32+
</mat-step>
33+
</mat-horizontal-stepper>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {MAT_STEPPER_GLOBAL_OPTIONS} from '@angular/cdk/stepper';
4+
5+
/**
6+
* @title Stepper that displays errors in the steps
7+
*/
8+
@Component({
9+
selector: 'stepper-errors-example',
10+
templateUrl: 'stepper-errors-example.html',
11+
styleUrls: ['stepper-errors-example.css'],
12+
providers: [{
13+
provide: MAT_STEPPER_GLOBAL_OPTIONS, useValue: {showError: true}
14+
}]
15+
})
16+
export class StepperErrorsExample implements OnInit {
17+
firstFormGroup: FormGroup;
18+
secondFormGroup: FormGroup;
19+
20+
constructor(private _formBuilder: FormBuilder) {}
21+
22+
ngOnInit() {
23+
this.firstFormGroup = this._formBuilder.group({
24+
firstCtrl: ['', Validators.required]
25+
});
26+
this.secondFormGroup = this._formBuilder.group({
27+
secondCtrl: ['', Validators.required]
28+
});
29+
}
30+
}

src/material-examples/stepper-states/stepper-states-example.css

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<mat-horizontal-stepper #stepper>
2+
<mat-step [stepControl]="firstFormGroup">
3+
<form [formGroup]="firstFormGroup">
4+
<ng-template matStepLabel>Fill out your name</ng-template>
5+
<mat-form-field>
6+
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
7+
</mat-form-field>
8+
<div>
9+
<button mat-button matStepperNext>Next</button>
10+
</div>
11+
</form>
12+
</mat-step>
13+
<mat-step [stepControl]="secondFormGroup">
14+
<form [formGroup]="secondFormGroup">
15+
<ng-template matStepLabel>Fill out your address</ng-template>
16+
<mat-form-field>
17+
<input matInput placeholder="Address" formControlName="secondCtrl" required>
18+
</mat-form-field>
19+
<div>
20+
<button mat-button matStepperPrevious>Back</button>
21+
<button mat-button matStepperNext>Next</button>
22+
</div>
23+
</form>
24+
</mat-step>
25+
<mat-step>
26+
<ng-template matStepLabel>Done</ng-template>
27+
You are now done.
28+
<div>
29+
<button mat-button matStepperPrevious>Back</button>
30+
<button mat-button (click)="stepper.reset()">Reset</button>
31+
</div>
32+
</mat-step>
33+
</mat-horizontal-stepper>
34+
35+
<mat-horizontal-stepper>
36+
<mat-step label="Step 1" state="phone">
37+
<p>Put down your phones.</p>
38+
<div>
39+
<button mat-button matStepperNext>Next</button>
40+
</div>
41+
</mat-step>
42+
<mat-step label="Step 2" state="chat">
43+
<p>Socialize with each other.</p>
44+
<div>
45+
<button mat-button matStepperPrevious>Back</button>
46+
<button mat-button matStepperNext>Next</button>
47+
</div>
48+
</mat-step>
49+
<mat-step label="Step 3">
50+
<p>You're welcome.</p>
51+
</mat-step>
52+
53+
<!-- Icon overrides. -->
54+
<ng-template matStepperIcon="phone">
55+
<mat-icon>call_end</mat-icon>
56+
</ng-template>
57+
<ng-template matStepperIcon="chat">
58+
<mat-icon>forum</mat-icon>
59+
</ng-template>
60+
</mat-horizontal-stepper>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {MAT_STEPPER_GLOBAL_OPTIONS} from '@angular/cdk/stepper';
4+
5+
/**
6+
* @title Stepper with customized states
7+
*/
8+
@Component({
9+
selector: 'stepper-states-example',
10+
templateUrl: 'stepper-states-example.html',
11+
styleUrls: ['stepper-states-example.css'],
12+
providers: [{
13+
provide: MAT_STEPPER_GLOBAL_OPTIONS, useValue: {displayDefaultIndicatorType: false}
14+
}]
15+
})
16+
export class StepperStatesExample implements OnInit {
17+
firstFormGroup: FormGroup;
18+
secondFormGroup: FormGroup;
19+
20+
constructor(private _formBuilder: FormBuilder) {}
21+
22+
ngOnInit() {
23+
this.firstFormGroup = this._formBuilder.group({
24+
firstCtrl: ['', Validators.required]
25+
});
26+
this.secondFormGroup = this._formBuilder.group({
27+
secondCtrl: ['', Validators.required]
28+
});
29+
}
30+
}

0 commit comments

Comments
 (0)