6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { animate , state , style , transition , trigger } from '@angular/animations' ;
10
9
import { CdkStep , CdkStepper } from '@angular/cdk/stepper' ;
11
10
import {
12
11
AfterContentInit ,
13
12
Component ,
14
13
ContentChild ,
15
14
ContentChildren ,
16
- Directive ,
17
15
ElementRef ,
18
16
forwardRef ,
19
17
Inject ,
18
+ Input ,
20
19
QueryList ,
21
20
SkipSelf ,
22
21
ViewChildren ,
23
22
ViewEncapsulation ,
24
23
ChangeDetectionStrategy ,
24
+ OnInit ,
25
25
} from '@angular/core' ;
26
26
import { FormControl , FormGroupDirective , NgForm } from '@angular/forms' ;
27
27
import { ErrorStateMatcher } from '@angular/material/core' ;
28
28
import { MatStepHeader } from './step-header' ;
29
29
import { MatStepLabel } from './step-label' ;
30
+ import { matStepperAnimations } from './stepper-animations' ;
30
31
import { takeUntil } from 'rxjs/operators/takeUntil' ;
31
32
33
+ /** Possible orientations for the Material stepper. */
34
+ export type MatStepperOrientation = 'horizontal' | 'vertical' ;
35
+
32
36
@Component ( {
33
37
moduleId : module . id ,
34
38
selector : 'mat-step' ,
@@ -61,8 +65,23 @@ export class MatStep extends CdkStep implements ErrorStateMatcher {
61
65
}
62
66
}
63
67
64
- @Directive ( {
65
- selector : '[matStepper]'
68
+ @Component ( {
69
+ moduleId : module . id ,
70
+ selector : 'mat-stepper, [matStepper]' ,
71
+ templateUrl : 'stepper.html' ,
72
+ styleUrls : [ 'stepper.css' ] ,
73
+ inputs : [ 'selectedIndex' ] ,
74
+ exportAs : 'matStepper' ,
75
+ encapsulation : ViewEncapsulation . None ,
76
+ preserveWhitespaces : false ,
77
+ changeDetection : ChangeDetectionStrategy . OnPush ,
78
+ animations : matStepperAnimations ,
79
+ host : {
80
+ '[class.mat-stepper-horizontal]' : 'orientation === "horizontal"' ,
81
+ '[class.mat-stepper-vertical]' : 'orientation === "vertical"' ,
82
+ '[attr.aria-orientation]' : 'orientation' ,
83
+ 'role' : 'tablist' ,
84
+ } ,
66
85
} )
67
86
export class MatStepper extends CdkStepper implements AfterContentInit {
68
87
/** The list of step headers of the steps in the stepper. */
@@ -71,6 +90,9 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
71
90
/** Steps that the stepper holds. */
72
91
@ContentChildren ( MatStep ) _steps : QueryList < MatStep > ;
73
92
93
+ /** Orientation of the stepper. */
94
+ @Input ( ) orientation : MatStepperOrientation = 'vertical' ;
95
+
74
96
ngAfterContentInit ( ) {
75
97
// Mark the component for change detection whenever the content children query changes
76
98
this . _steps . changes . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => this . _stateChanged ( ) ) ;
@@ -79,54 +101,46 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
79
101
80
102
@Component ( {
81
103
moduleId : module . id ,
104
+ encapsulation : ViewEncapsulation . None ,
105
+ preserveWhitespaces : false ,
106
+ changeDetection : ChangeDetectionStrategy . OnPush ,
107
+ templateUrl : 'stepper.html' ,
108
+ styleUrls : [ 'stepper.css' ] ,
82
109
selector : 'mat-horizontal-stepper' ,
83
110
exportAs : 'matHorizontalStepper' ,
84
- templateUrl : 'stepper-horizontal.html' ,
85
- styleUrls : [ 'stepper.css' ] ,
86
- inputs : [ 'selectedIndex' ] ,
111
+ animations : matStepperAnimations ,
112
+ providers : [ { provide : MatStepper , useExisting : MatHorizontalStepper } ] ,
87
113
host : {
88
114
'class' : 'mat-stepper-horizontal' ,
89
115
'aria-orientation' : 'horizontal' ,
90
116
'role' : 'tablist' ,
91
117
} ,
92
- animations : [
93
- trigger ( 'stepTransition' , [
94
- state ( 'previous' , style ( { transform : 'translate3d(-100%, 0, 0)' , visibility : 'hidden' } ) ) ,
95
- state ( 'current' , style ( { transform : 'none' , visibility : 'visible' } ) ) ,
96
- state ( 'next' , style ( { transform : 'translate3d(100%, 0, 0)' , visibility : 'hidden' } ) ) ,
97
- transition ( '* => *' , animate ( '500ms cubic-bezier(0.35, 0, 0.25, 1)' ) )
98
- ] )
99
- ] ,
100
- providers : [ { provide : MatStepper , useExisting : MatHorizontalStepper } ] ,
101
- encapsulation : ViewEncapsulation . None ,
102
- preserveWhitespaces : false ,
103
- changeDetection : ChangeDetectionStrategy . OnPush ,
104
118
} )
105
- export class MatHorizontalStepper extends MatStepper { }
119
+ export class MatHorizontalStepper extends MatStepper implements OnInit {
120
+ ngOnInit ( ) {
121
+ this . orientation = 'horizontal' ;
122
+ }
123
+ }
106
124
107
125
@Component ( {
108
126
moduleId : module . id ,
127
+ encapsulation : ViewEncapsulation . None ,
128
+ preserveWhitespaces : false ,
129
+ changeDetection : ChangeDetectionStrategy . OnPush ,
130
+ templateUrl : 'stepper.html' ,
131
+ styleUrls : [ 'stepper.css' ] ,
109
132
selector : 'mat-vertical-stepper' ,
110
133
exportAs : 'matVerticalStepper' ,
111
- templateUrl : 'stepper-vertical.html' ,
112
- styleUrls : [ 'stepper.css' ] ,
113
- inputs : [ 'selectedIndex' ] ,
134
+ providers : [ { provide : MatStepper , useExisting : MatVerticalStepper } ] ,
135
+ animations : matStepperAnimations ,
114
136
host : {
115
137
'class' : 'mat-stepper-vertical' ,
116
138
'aria-orientation' : 'vertical' ,
117
139
'role' : 'tablist' ,
118
140
} ,
119
- animations : [
120
- trigger ( 'stepTransition' , [
121
- state ( 'previous' , style ( { height : '0px' , visibility : 'hidden' } ) ) ,
122
- state ( 'next' , style ( { height : '0px' , visibility : 'hidden' } ) ) ,
123
- state ( 'current' , style ( { height : '*' , visibility : 'visible' } ) ) ,
124
- transition ( '* <=> current' , animate ( '225ms cubic-bezier(0.4, 0.0, 0.2, 1)' ) )
125
- ] )
126
- ] ,
127
- providers : [ { provide : MatStepper , useExisting : MatVerticalStepper } ] ,
128
- encapsulation : ViewEncapsulation . None ,
129
- preserveWhitespaces : false ,
130
- changeDetection : ChangeDetectionStrategy . OnPush ,
131
141
} )
132
- export class MatVerticalStepper extends MatStepper { }
142
+ export class MatVerticalStepper extends MatStepper implements OnInit {
143
+ ngOnInit ( ) {
144
+ this . orientation = 'vertical' ;
145
+ }
146
+ }
0 commit comments