77 */
88
99import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
10- import { take } from 'rxjs/operators/take' ;
11- import { startWith } from 'rxjs/operators/startWith' ;
1210import {
1311 AfterContentChecked ,
1412 AfterContentInit ,
@@ -26,21 +24,39 @@ import {
2624 ViewChild ,
2725 ViewEncapsulation ,
2826} 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' ;
3035import { fromEvent } from 'rxjs/observable/fromEvent' ;
36+ import { startWith } from 'rxjs/operators/startWith' ;
37+ import { take } from 'rxjs/operators/take' ;
3138import { MatError } from './error' ;
39+ import { matFormFieldAnimations } from './form-field-animations' ;
3240import { MatFormFieldControl } from './form-field-control' ;
3341import {
3442 getMatFormFieldDuplicatedHintError ,
3543 getMatFormFieldMissingControlError ,
3644 getMatFormFieldPlaceholderConflictError ,
3745} from './form-field-errors' ;
3846import { MatHint } from './hint' ;
39- import { MatPlaceholder } from './placeholder' ;
4047import { MatLabel } from './label' ;
48+ import { MatPlaceholder } from './placeholder' ;
4149import { MatPrefix } from './prefix' ;
4250import { 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' ) ;
4460
4561
4662let nextUniqueId = 0 ;
@@ -67,9 +83,6 @@ let nextUniqueId = 0;
6783 '[class.mat-form-field-hide-placeholder]' : '_hideControlPlaceholder()' ,
6884 '[class.mat-form-field-disabled]' : '_control.disabled' ,
6985 '[class.mat-focused]' : '_control.focused' ,
70- '[class.mat-primary]' : 'color == "primary"' ,
71- '[class.mat-accent]' : 'color == "accent"' ,
72- '[class.mat-warn]' : 'color == "warn"' ,
7386 '[class.ng-untouched]' : '_shouldForward("untouched")' ,
7487 '[class.ng-touched]' : '_shouldForward("touched")' ,
7588 '[class.ng-pristine]' : '_shouldForward("pristine")' ,
@@ -78,24 +91,23 @@ let nextUniqueId = 0;
7891 '[class.ng-invalid]' : '_shouldForward("invalid")' ,
7992 '[class.ng-pending]' : '_shouldForward("pending")' ,
8093 } ,
94+ inputs : [ 'color' ] ,
8195 encapsulation : ViewEncapsulation . None ,
8296 preserveWhitespaces : false ,
8397 changeDetection : ChangeDetectionStrategy . OnPush ,
8498} )
8599
86- export class MatFormField implements AfterViewInit , AfterContentInit , AfterContentChecked {
100+ export class MatFormField extends _MatFormFieldMixinBase
101+ implements AfterContentInit , AfterContentChecked , AfterViewInit , CanColor {
87102 private _labelOptions : LabelOptions ;
88103
89- /** Color of the form field underline, based on the theme. */
90- @Input ( ) color : 'primary' | 'accent' | 'warn' = 'primary' ;
91-
92104 /**
93105 * @deprecated Use `color` instead.
94106 * @deletion -target 6.0.0
95107 */
96108 @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 ; }
99111
100112 /** Whether the required marker should be hidden. */
101113 @Input ( )
@@ -168,6 +180,8 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
168180 public _elementRef : ElementRef ,
169181 private _changeDetectorRef : ChangeDetectorRef ,
170182 @Optional ( ) @Inject ( MAT_LABEL_GLOBAL_OPTIONS ) labelOptions : LabelOptions ) {
183+ super ( _elementRef ) ;
184+
171185 this . _labelOptions = labelOptions ? labelOptions : { } ;
172186 this . floatLabel = this . _labelOptions . float || 'auto' ;
173187 }
@@ -288,12 +302,12 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
288302 let startHint : MatHint ;
289303 let endHint : MatHint ;
290304 this . _hintChildren . forEach ( ( hint : MatHint ) => {
291- if ( hint . align == 'start' ) {
305+ if ( hint . align === 'start' ) {
292306 if ( startHint || this . hintLabel ) {
293307 throw getMatFormFieldDuplicatedHintError ( 'start' ) ;
294308 }
295309 startHint = hint ;
296- } else if ( hint . align == 'end' ) {
310+ } else if ( hint . align === 'end' ) {
297311 if ( endHint ) {
298312 throw getMatFormFieldDuplicatedHintError ( 'end' ) ;
299313 }
0 commit comments