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