@@ -14,6 +14,7 @@ import {
1414 ElementRef ,
1515 ViewEncapsulation ,
1616 Optional ,
17+ InjectionToken ,
1718} from '@angular/core' ;
1819import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
1920import { CanColor , mixinColor } from '@angular/material/core' ;
@@ -43,6 +44,26 @@ export class MatProgressSpinnerBase {
4344}
4445export const _MatProgressSpinnerMixinBase = mixinColor ( MatProgressSpinnerBase , 'primary' ) ;
4546
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+
4667// .0001 percentage difference is necessary in order to avoid unwanted animation frames
4768// for example because the animation duration is 4 seconds, .1% accounts to 4ms
4869// which are enough to see the flicker described in
@@ -98,7 +119,7 @@ const INDETERMINATE_ANIMATION_TEMPLATE = `
98119export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements CanColor {
99120
100121 private _value = 0 ;
101- private _strokeWidth : number ;
122+ private _strokeWidth = this . _defaults ? this . _defaults . strokeWidth : undefined ;
102123 private _fallbackAnimation = false ;
103124
104125 /** Tracks diameters of existing instances to de-dupe generated styles (default d = 100) */
@@ -120,7 +141,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
120141 this . _attachStyleNode ( ) ;
121142 }
122143 }
123- private _diameter = BASE_SIZE ;
144+ private _diameter = this . _defaults && this . _defaults . diameter ?
145+ this . _defaults . diameter : BASE_SIZE ;
124146
125147 /** Stroke width of the progress spinner. */
126148 @Input ( )
@@ -131,7 +153,6 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
131153 this . _strokeWidth = coerceNumberProperty ( value ) ;
132154 }
133155
134-
135156 /** Mode of the progress circle */
136157 @Input ( ) mode : ProgressSpinnerMode = 'determinate' ;
137158
@@ -147,7 +168,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
147168 constructor ( public _elementRef : ElementRef ,
148169 platform : Platform ,
149170 @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 ) {
151175
152176 super ( _elementRef ) ;
153177 this . _fallbackAnimation = platform . EDGE || platform . TRIDENT ;
@@ -249,8 +273,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
249273export class MatSpinner extends MatProgressSpinner {
250274 constructor ( elementRef : ElementRef , platform : Platform ,
251275 @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 ) ;
254281 this . mode = 'indeterminate' ;
255282 }
256283}
0 commit comments