@@ -15,6 +15,7 @@ import {
15
15
Input ,
16
16
OnDestroy ,
17
17
Optional ,
18
+ ViewChild ,
18
19
ViewEncapsulation
19
20
} from '@angular/core' ;
20
21
import {
@@ -27,10 +28,9 @@ import {
27
28
MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS ,
28
29
MatProgressSpinnerDefaultOptions
29
30
} from '@angular/material/progress-spinner' ;
30
- import { coerceNumberProperty } from '@angular/cdk/coercion' ;
31
+ import { coerceNumberProperty , NumberInput } from '@angular/cdk/coercion' ;
31
32
32
33
// Boilerplate for applying mixins to MatProgressBar.
33
- /** @docs -private */
34
34
class MatProgressSpinnerBase {
35
35
constructor ( public _elementRef : ElementRef ) {
36
36
}
@@ -44,16 +44,15 @@ export type ProgressSpinnerMode = 'determinate' | 'indeterminate';
44
44
45
45
/**
46
46
* Base reference size of the spinner.
47
- * @docs -private
48
47
*/
49
48
const BASE_SIZE = 100 ;
50
49
51
50
/**
52
51
* Base reference stroke width of the spinner.
53
- * @docs -private
54
52
*/
55
53
const BASE_STROKE_WIDTH = 10 ;
56
54
55
+
57
56
@Component ( {
58
57
selector : 'mat-progress-spinner' ,
59
58
exportAs : 'matProgressSpinner' ,
@@ -77,27 +76,29 @@ const BASE_STROKE_WIDTH = 10;
77
76
export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements AfterViewInit ,
78
77
OnDestroy ,
79
78
CanColor {
79
+ static ngAcceptInputType_diameter : NumberInput ;
80
+ static ngAcceptInputType_strokeWidth : NumberInput ;
81
+ static ngAcceptInputType_value : NumberInput ;
82
+
80
83
/** Whether the _mat-animation-noopable class should be applied, disabling animations. */
81
84
_noopAnimations : boolean ;
82
85
/** Implements all of the logic of the MDC circular progress. */
83
- private _foundation : MDCCircularProgressFoundation | undefined ;
84
- private _rootElement : HTMLElement ;
85
- private _determinateCircle : HTMLElement ;
86
- /** Adapter used by MDC to interact with the DOM. */
86
+ _foundation : MDCCircularProgressFoundation ;
87
+ @ ViewChild ( 'spinnerRoot' ) _rootElement : ElementRef < HTMLElement > ;
88
+ @ ViewChild ( 'determinateSpinner' ) _determinateCircle : ElementRef < HTMLElement > ;
89
+
87
90
private _adapter : MDCCircularProgressAdapter = {
88
- addClass : ( className : string ) => this . _rootElement . classList . add ( className ) ,
89
- hasClass : ( className : string ) => this . _rootElement . classList . contains ( className ) ,
90
- removeClass : ( className : string ) => this . _rootElement . classList . remove ( className ) ,
91
- removeAttribute : ( name : string ) => this . _rootElement . removeAttribute ( name ) ,
92
- setAttribute : ( name : string , value : string ) => this . _rootElement . setAttribute ( name , value ) ,
93
- getDeterminateCircleAttribute : ( attributeName : string ) => this . _determinateCircle . getAttribute (
94
- attributeName ) ,
95
- setDeterminateCircleAttribute : ( attributeName : string ,
96
- value : string ) => this . _determinateCircle . setAttribute (
97
- attributeName ,
98
- value ) ,
91
+ addClass : ( className : string ) => this . _rootElement . nativeElement . classList . add ( className ) ,
92
+ hasClass : ( className : string ) => this . _rootElement . nativeElement . classList . contains ( className ) ,
93
+ removeClass : ( className : string ) => this . _rootElement . nativeElement . classList . remove ( className ) ,
94
+ removeAttribute : ( name : string ) => this . _rootElement . nativeElement . removeAttribute ( name ) ,
95
+ setAttribute : ( name : string , value : string ) =>
96
+ this . _rootElement . nativeElement . setAttribute ( name , value ) ,
97
+ getDeterminateCircleAttribute : ( attributeName : string ) =>
98
+ this . _determinateCircle . nativeElement . getAttribute ( attributeName ) ,
99
+ setDeterminateCircleAttribute : ( attributeName : string , value : string ) =>
100
+ this . _determinateCircle . nativeElement . setAttribute ( attributeName , value ) ,
99
101
} ;
100
-
101
102
constructor ( public _elementRef : ElementRef < HTMLElement > ,
102
103
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode : string ,
103
104
@Inject ( MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS )
@@ -160,7 +161,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
160
161
}
161
162
162
163
set diameter ( size : number ) {
163
- this . _diameter = size ;
164
+ this . _diameter = coerceNumberProperty ( size ) ;
164
165
this . _syncFoundation ( ) ;
165
166
}
166
167
@@ -169,50 +170,43 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
169
170
/** Stroke width of the progress spinner. */
170
171
@Input ( )
171
172
get strokeWidth ( ) : number {
172
- return this . _strokeWidth || this . diameter / 10 ;
173
+ return this . _strokeWidth ?? this . diameter / 10 ;
173
174
}
174
175
175
176
set strokeWidth ( value : number ) {
176
177
this . _strokeWidth = coerceNumberProperty ( value ) ;
177
178
}
178
179
179
180
/** The radius of the spinner, adjusted for stroke width. */
180
- get _circleRadius ( ) {
181
+ _circleRadius ( ) : number {
181
182
return ( this . diameter - BASE_STROKE_WIDTH ) / 2 ;
182
183
}
183
184
184
185
/** The view box of the spinner's svg element. */
185
- get _viewBox ( ) {
186
- const viewBox = this . _circleRadius * 2 + this . strokeWidth ;
186
+ _viewBox ( ) {
187
+ const viewBox = this . _circleRadius ( ) * 2 + this . strokeWidth ;
187
188
return `0 0 ${ viewBox } ${ viewBox } ` ;
188
189
}
189
190
190
191
/** The stroke circumference of the svg circle. */
191
- get _strokeCircumference ( ) : number {
192
- return 2 * Math . PI * this . _circleRadius ;
192
+ _strokeCircumference ( ) : number {
193
+ return 2 * Math . PI * this . _circleRadius ( ) ;
193
194
}
194
195
195
196
/** The dash offset of the svg circle. */
196
- get _strokeDashOffset ( ) {
197
+ _strokeDashOffset ( ) {
197
198
if ( this . mode === 'determinate' ) {
198
- return this . _strokeCircumference * ( 100 - this . _value ) / 100 ;
199
+ return this . _strokeCircumference ( ) * ( 100 - this . _value ) / 100 ;
199
200
}
200
-
201
201
return null ;
202
202
}
203
203
204
204
/** Stroke width of the circle in percent. */
205
- get _circleStrokeWidth ( ) {
205
+ _circleStrokeWidth ( ) {
206
206
return this . strokeWidth / this . diameter * 100 ;
207
207
}
208
208
209
209
ngAfterViewInit ( ) {
210
- const element = this . _elementRef . nativeElement ;
211
-
212
- this . _rootElement = element . querySelector ( '.mdc-circular-progress' ) as HTMLElement ;
213
- this . _determinateCircle =
214
- element . querySelector ( '.mdc-circular-progress__determinate-container' ) as HTMLElement ;
215
-
216
210
this . _foundation = new MDCCircularProgressFoundation ( this . _adapter ) ;
217
211
this . _foundation . init ( ) ;
218
212
this . _syncFoundation ( ) ;
0 commit comments