7
7
*/
8
8
9
9
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
10
- import { take } from 'rxjs/operators/take' ;
11
- import { startWith } from 'rxjs/operators/startWith' ;
12
10
import {
13
11
AfterContentChecked ,
14
12
AfterContentInit ,
@@ -26,21 +24,39 @@ import {
26
24
ViewChild ,
27
25
ViewEncapsulation ,
28
26
} from '@angular/core' ;
29
- import { FloatLabelType , MAT_LABEL_GLOBAL_OPTIONS , LabelOptions } from '@angular/material/core' ;
27
+ import {
28
+ CanColor ,
29
+ FloatLabelType ,
30
+ LabelOptions ,
31
+ MAT_LABEL_GLOBAL_OPTIONS ,
32
+ mixinColor ,
33
+ ThemePalette
34
+ } from '@angular/material/core' ;
30
35
import { fromEvent } from 'rxjs/observable/fromEvent' ;
36
+ import { startWith } from 'rxjs/operators/startWith' ;
37
+ import { take } from 'rxjs/operators/take' ;
31
38
import { MatError } from './error' ;
39
+ import { matFormFieldAnimations } from './form-field-animations' ;
32
40
import { MatFormFieldControl } from './form-field-control' ;
33
41
import {
34
42
getMatFormFieldDuplicatedHintError ,
35
43
getMatFormFieldMissingControlError ,
36
44
getMatFormFieldPlaceholderConflictError ,
37
45
} from './form-field-errors' ;
38
46
import { MatHint } from './hint' ;
39
- import { MatPlaceholder } from './placeholder' ;
40
47
import { MatLabel } from './label' ;
48
+ import { MatPlaceholder } from './placeholder' ;
41
49
import { MatPrefix } from './prefix' ;
42
50
import { MatSuffix } from './suffix' ;
43
- import { matFormFieldAnimations } from './form-field-animations' ;
51
+
52
+
53
+ // Boilerplate for applying mixins to MatFormField.
54
+ /** @docs -private */
55
+ export class MatFormFieldBase {
56
+ constructor ( public _elementRef : ElementRef ) { }
57
+ }
58
+
59
+ export const _MatFormFieldMixinBase = mixinColor ( MatFormFieldBase , 'primary' ) ;
44
60
45
61
46
62
let nextUniqueId = 0 ;
@@ -67,9 +83,6 @@ let nextUniqueId = 0;
67
83
'[class.mat-form-field-hide-placeholder]' : '_hideControlPlaceholder()' ,
68
84
'[class.mat-form-field-disabled]' : '_control.disabled' ,
69
85
'[class.mat-focused]' : '_control.focused' ,
70
- '[class.mat-primary]' : 'color == "primary"' ,
71
- '[class.mat-accent]' : 'color == "accent"' ,
72
- '[class.mat-warn]' : 'color == "warn"' ,
73
86
'[class.ng-untouched]' : '_shouldForward("untouched")' ,
74
87
'[class.ng-touched]' : '_shouldForward("touched")' ,
75
88
'[class.ng-pristine]' : '_shouldForward("pristine")' ,
@@ -78,24 +91,23 @@ let nextUniqueId = 0;
78
91
'[class.ng-invalid]' : '_shouldForward("invalid")' ,
79
92
'[class.ng-pending]' : '_shouldForward("pending")' ,
80
93
} ,
94
+ inputs : [ 'color' ] ,
81
95
encapsulation : ViewEncapsulation . None ,
82
96
preserveWhitespaces : false ,
83
97
changeDetection : ChangeDetectionStrategy . OnPush ,
84
98
} )
85
99
86
- export class MatFormField implements AfterViewInit , AfterContentInit , AfterContentChecked {
100
+ export class MatFormField extends _MatFormFieldMixinBase
101
+ implements AfterContentInit , AfterContentChecked , AfterViewInit , CanColor {
87
102
private _labelOptions : LabelOptions ;
88
103
89
- /** Color of the form field underline, based on the theme. */
90
- @Input ( ) color : 'primary' | 'accent' | 'warn' = 'primary' ;
91
-
92
104
/**
93
105
* @deprecated Use `color` instead.
94
106
* @deletion -target 6.0.0
95
107
*/
96
108
@Input ( )
97
- get dividerColor ( ) : 'primary' | 'accent' | 'warn' { return this . color ; }
98
- set dividerColor ( value ) { this . color = value ; }
109
+ get dividerColor ( ) : ThemePalette { return this . color ; }
110
+ set dividerColor ( value : ThemePalette ) { this . color = value ; }
99
111
100
112
/** Whether the required marker should be hidden. */
101
113
@Input ( )
@@ -168,6 +180,8 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
168
180
public _elementRef : ElementRef ,
169
181
private _changeDetectorRef : ChangeDetectorRef ,
170
182
@Optional ( ) @Inject ( MAT_LABEL_GLOBAL_OPTIONS ) labelOptions : LabelOptions ) {
183
+ super ( _elementRef ) ;
184
+
171
185
this . _labelOptions = labelOptions ? labelOptions : { } ;
172
186
this . floatLabel = this . _labelOptions . float || 'auto' ;
173
187
}
@@ -288,12 +302,12 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
288
302
let startHint : MatHint ;
289
303
let endHint : MatHint ;
290
304
this . _hintChildren . forEach ( ( hint : MatHint ) => {
291
- if ( hint . align == 'start' ) {
305
+ if ( hint . align === 'start' ) {
292
306
if ( startHint || this . hintLabel ) {
293
307
throw getMatFormFieldDuplicatedHintError ( 'start' ) ;
294
308
}
295
309
startHint = hint ;
296
- } else if ( hint . align == 'end' ) {
310
+ } else if ( hint . align === 'end' ) {
297
311
if ( endHint ) {
298
312
throw getMatFormFieldDuplicatedHintError ( 'end' ) ;
299
313
}
0 commit comments