@@ -3,12 +3,12 @@ import {
3
3
ModuleWithProviders ,
4
4
Component ,
5
5
HostBinding ,
6
- ChangeDetectorRef ,
7
6
ChangeDetectionStrategy ,
8
7
OnDestroy ,
9
8
Input ,
10
9
ElementRef ,
11
- NgZone
10
+ NgZone ,
11
+ Renderer
12
12
} from '@angular/core' ;
13
13
import { DefaultStyleCompatibilityModeModule } from '../core' ;
14
14
@@ -43,10 +43,7 @@ type EasingFn = (currentTime: number, startValue: number,
43
43
host : {
44
44
'role' : 'progressbar' ,
45
45
'[attr.aria-valuemin]' : '_ariaValueMin' ,
46
- '[attr.aria-valuemax]' : '_ariaValueMax' ,
47
- '[class.md-primary]' : 'color == "primary"' ,
48
- '[class.md-accent]' : 'color == "accent"' ,
49
- '[class.md-warn]' : 'color == "warn"' ,
46
+ '[attr.aria-valuemax]' : '_ariaValueMax'
50
47
} ,
51
48
templateUrl : 'progress-spinner.html' ,
52
49
styleUrls : [ 'progress-spinner.css' ] ,
@@ -62,6 +59,10 @@ export class MdProgressSpinner implements OnDestroy {
62
59
/** The SVG <path> node that is used to draw the circle. */
63
60
private _path : SVGPathElement ;
64
61
62
+ private _mode : ProgressSpinnerMode = 'determinate' ;
63
+ private _value : number ;
64
+ private _color : string = 'primary' ;
65
+
65
66
/**
66
67
* Values for aria max and min are only defined as numbers when in a determinate mode. We do this
67
68
* because voiceover does not report the progress indicator as indeterminate if the aria min
@@ -92,8 +93,14 @@ export class MdProgressSpinner implements OnDestroy {
92
93
this . _cleanupIndeterminateAnimation ( ) ;
93
94
}
94
95
96
+ /** The color of the progress-spinner. Can be primary, accent, or warn. */
97
+ @Input ( )
98
+ get color ( ) : string { return this . _color ; }
99
+ set color ( value : string ) {
100
+ this . _updateColor ( value ) ;
101
+ }
102
+
95
103
/** Value of the progress circle. It is bound to the host as the attribute aria-valuenow. */
96
- private _value : number ;
97
104
@Input ( )
98
105
@HostBinding ( 'attr.aria-valuenow' )
99
106
get value ( ) {
@@ -128,14 +135,11 @@ export class MdProgressSpinner implements OnDestroy {
128
135
}
129
136
this . _mode = m ;
130
137
}
131
- private _mode : ProgressSpinnerMode = 'determinate' ;
132
-
133
- @Input ( ) color : 'primary' | 'accent' | 'warn' = 'primary' ;
134
138
135
139
constructor (
136
- private _changeDetectorRef : ChangeDetectorRef ,
137
140
private _ngZone : NgZone ,
138
- private _elementRef : ElementRef
141
+ private _elementRef : ElementRef ,
142
+ private _renderer : Renderer
139
143
) { }
140
144
141
145
@@ -229,6 +233,23 @@ export class MdProgressSpinner implements OnDestroy {
229
233
path . setAttribute ( 'd' , getSvgArc ( currentValue , rotation ) ) ;
230
234
}
231
235
}
236
+
237
+ /**
238
+ * Updates the color of the progress-spinner by adding the new palette class to the element
239
+ * and removing the old one.
240
+ */
241
+ private _updateColor ( newColor : string ) {
242
+ this . _setElementColor ( this . _color , false ) ;
243
+ this . _setElementColor ( newColor , true ) ;
244
+ this . _color = newColor ;
245
+ }
246
+
247
+ /** Sets the given palette class on the component element. */
248
+ private _setElementColor ( color : string , isAdd : boolean ) {
249
+ if ( color != null && color != '' ) {
250
+ this . _renderer . setElementClass ( this . _elementRef . nativeElement , `md-${ color } ` , isAdd ) ;
251
+ }
252
+ }
232
253
}
233
254
234
255
@@ -245,12 +266,15 @@ export class MdProgressSpinner implements OnDestroy {
245
266
'role' : 'progressbar' ,
246
267
'mode' : 'indeterminate' ,
247
268
} ,
269
+ // Due to the class extending we need to explicitly say that the input exists.
270
+ inputs : [ 'color' ] ,
248
271
templateUrl : 'progress-spinner.html' ,
249
272
styleUrls : [ 'progress-spinner.css' ] ,
250
273
} )
251
274
export class MdSpinner extends MdProgressSpinner implements OnDestroy {
252
- constructor ( changeDetectorRef : ChangeDetectorRef , elementRef : ElementRef , ngZone : NgZone ) {
253
- super ( changeDetectorRef , ngZone , elementRef ) ;
275
+
276
+ constructor ( elementRef : ElementRef , ngZone : NgZone , renderer : Renderer ) {
277
+ super ( ngZone , elementRef , renderer ) ;
254
278
this . mode = 'indeterminate' ;
255
279
}
256
280
0 commit comments