@@ -11,6 +11,7 @@ import {
1111} from '@angular/core' ;
1212import { coerceBooleanProperty , FocusOriginMonitor , Platform } from '../core' ;
1313import { mixinDisabled , CanDisable } from '../core/common-behaviors/disabled' ;
14+ import { IsColorable , mixinColor } from '../core/common-behaviors/color' ;
1415
1516
1617// TODO(kara): Convert attribute selectors to classes when attr maps become available
@@ -71,8 +72,10 @@ export class MdMiniFabCssMatStyler {}
7172
7273
7374// Boilerplate for applying mixins to MdButton.
74- export class MdButtonBase { }
75- export const _MdButtonMixinBase = mixinDisabled ( MdButtonBase ) ;
75+ export class MdButtonBase {
76+ constructor ( public _renderer : Renderer2 , public _elementRef : ElementRef ) { }
77+ }
78+ export const _MdButtonMixinBase = mixinColor ( mixinDisabled ( MdButtonBase ) , true ) ;
7679
7780
7881/**
@@ -89,13 +92,11 @@ export const _MdButtonMixinBase = mixinDisabled(MdButtonBase);
8992 } ,
9093 templateUrl : 'button.html' ,
9194 styleUrls : [ 'button.css' ] ,
92- inputs : [ 'disabled' ] ,
95+ inputs : [ 'disabled' , 'color' ] ,
9396 encapsulation : ViewEncapsulation . None ,
9497 changeDetection : ChangeDetectionStrategy . OnPush ,
9598} )
96- export class MdButton extends _MdButtonMixinBase implements OnDestroy , CanDisable {
97- private _color : string ;
98-
99+ export class MdButton extends _MdButtonMixinBase implements OnDestroy , CanDisable , IsColorable {
99100 /** Whether the button is round. */
100101 _isRoundButton : boolean = this . _hasAttributeWithPrefix ( 'fab' , 'mini-fab' ) ;
101102
@@ -110,40 +111,18 @@ export class MdButton extends _MdButtonMixinBase implements OnDestroy, CanDisabl
110111 get disableRipple ( ) { return this . _disableRipple ; }
111112 set disableRipple ( v ) { this . _disableRipple = coerceBooleanProperty ( v ) ; }
112113
113- constructor (
114- private _elementRef : ElementRef ,
115- private _renderer : Renderer2 ,
116- private _platform : Platform ,
117- private _focusOriginMonitor : FocusOriginMonitor ) {
118- super ( ) ;
114+ constructor ( private _platform : Platform ,
115+ private _focusOriginMonitor : FocusOriginMonitor ,
116+ renderer : Renderer2 ,
117+ elementRef : ElementRef ) {
118+ super ( renderer , elementRef ) ;
119119 this . _focusOriginMonitor . monitor ( this . _elementRef . nativeElement , this . _renderer , true ) ;
120120 }
121121
122122 ngOnDestroy ( ) {
123123 this . _focusOriginMonitor . stopMonitoring ( this . _elementRef . nativeElement ) ;
124124 }
125125
126- /** The color of the button. Can be `primary`, `accent`, or `warn`. */
127- @Input ( )
128- get color ( ) : string { return this . _color ; }
129- set color ( value : string ) { this . _updateColor ( value ) ; }
130-
131- _updateColor ( newColor : string ) {
132- this . _setElementColor ( this . _color , false ) ;
133- this . _setElementColor ( newColor , true ) ;
134- this . _color = newColor ;
135- }
136-
137- _setElementColor ( color : string , isAdd : boolean ) {
138- if ( color != null && color != '' ) {
139- if ( isAdd ) {
140- this . _renderer . addClass ( this . _getHostElement ( ) , `mat-${ color } ` ) ;
141- } else {
142- this . _renderer . removeClass ( this . _getHostElement ( ) , `mat-${ color } ` ) ;
143- }
144- }
145- }
146-
147126 /** Focuses the button. */
148127 focus ( ) : void {
149128 this . _getHostElement ( ) . focus ( ) ;
@@ -189,18 +168,18 @@ export class MdButton extends _MdButtonMixinBase implements OnDestroy, CanDisabl
189168 '[attr.aria-disabled]' : '_isAriaDisabled' ,
190169 '(click)' : '_haltDisabledEvents($event)' ,
191170 } ,
192- inputs : [ 'disabled' ] ,
171+ inputs : [ 'disabled' , 'color' ] ,
193172 templateUrl : 'button.html' ,
194173 styleUrls : [ 'button.css' ] ,
195174 encapsulation : ViewEncapsulation . None
196175} )
197176export class MdAnchor extends MdButton {
198177 constructor (
199- elementRef : ElementRef ,
200- renderer : Renderer2 ,
201178 platform : Platform ,
202- focusOriginMonitor : FocusOriginMonitor ) {
203- super ( elementRef , renderer , platform , focusOriginMonitor ) ;
179+ focusOriginMonitor : FocusOriginMonitor ,
180+ elementRef : ElementRef ,
181+ renderer : Renderer2 ) {
182+ super ( platform , focusOriginMonitor , renderer , elementRef ) ;
204183 }
205184
206185 /** @docs -private */
0 commit comments