@@ -14,6 +14,7 @@ import {
14
14
ElementRef ,
15
15
ViewEncapsulation ,
16
16
Optional ,
17
+ InjectionToken ,
17
18
} from '@angular/core' ;
18
19
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
19
20
import { CanColor , mixinColor } from '@angular/material/core' ;
@@ -43,6 +44,26 @@ export class MatProgressSpinnerBase {
43
44
}
44
45
export const _MatProgressSpinnerMixinBase = mixinColor ( MatProgressSpinnerBase , 'primary' ) ;
45
46
47
+ /** Default `mat-progress-spinner` options that can be overridden. */
48
+ export interface MatProgressSpinnerDefaultOptions {
49
+ /** Diameter of the spinner. */
50
+ diameter ?: number ;
51
+ /** Width of the spinner's stroke. */
52
+ strokeWidth ?: number ;
53
+ }
54
+
55
+ /** Injection token to be used to override the default options for `mat-progress-spinner`. */
56
+ export const MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS =
57
+ new InjectionToken < MatProgressSpinnerDefaultOptions > ( 'mat-progress-spinner-default-options' , {
58
+ providedIn : 'root' ,
59
+ factory : MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY ,
60
+ } ) ;
61
+
62
+ /** @docs -private */
63
+ export function MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY ( ) : MatProgressSpinnerDefaultOptions {
64
+ return { diameter : BASE_SIZE } ;
65
+ }
66
+
46
67
// .0001 percentage difference is necessary in order to avoid unwanted animation frames
47
68
// for example because the animation duration is 4 seconds, .1% accounts to 4ms
48
69
// which are enough to see the flicker described in
@@ -98,7 +119,7 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
98
119
export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements CanColor {
99
120
100
121
private _value = 0 ;
101
- private _strokeWidth : number ;
122
+ private _strokeWidth = this . _defaults ? this . _defaults . strokeWidth : undefined ;
102
123
private _fallbackAnimation = false ;
103
124
104
125
/** Tracks diameters of existing instances to de-dupe generated styles (default d = 100) */
@@ -120,7 +141,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
120
141
this . _attachStyleNode ( ) ;
121
142
}
122
143
}
123
- private _diameter = BASE_SIZE ;
144
+ private _diameter = this . _defaults && this . _defaults . diameter ?
145
+ this . _defaults . diameter : BASE_SIZE ;
124
146
125
147
/** Stroke width of the progress spinner. */
126
148
@Input ( )
@@ -131,7 +153,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
131
153
this . _strokeWidth = coerceNumberProperty ( value ) ;
132
154
}
133
155
134
-
135
156
/** Mode of the progress circle */
136
157
@Input ( ) mode : ProgressSpinnerMode = 'determinate' ;
137
158
@@ -147,7 +168,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
147
168
constructor ( public _elementRef : ElementRef ,
148
169
platform : Platform ,
149
170
@Optional ( ) @Inject ( DOCUMENT ) private _document : any ,
150
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ) {
171
+ // @deletion -target 7.0.0 _animationMode and _defaults parameters to be made required.
172
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
173
+ @Inject ( MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS )
174
+ private _defaults ?: MatProgressSpinnerDefaultOptions ) {
151
175
152
176
super ( _elementRef ) ;
153
177
this . _fallbackAnimation = platform . EDGE || platform . TRIDENT ;
@@ -249,8 +273,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
249
273
export class MatSpinner extends MatProgressSpinner {
250
274
constructor ( elementRef : ElementRef , platform : Platform ,
251
275
@Optional ( ) @Inject ( DOCUMENT ) document : any ,
252
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) _animationMode ?: string ) {
253
- super ( elementRef , platform , document , _animationMode ) ;
276
+ // @deletion -targets 7.0.0 animationMode and defaults parameters to be made required.
277
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
278
+ @Inject ( MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS )
279
+ defaults ?: MatProgressSpinnerDefaultOptions ) {
280
+ super ( elementRef , platform , document , animationMode , defaults ) ;
254
281
this . mode = 'indeterminate' ;
255
282
}
256
283
}
0 commit comments