@@ -4,8 +4,9 @@ import { NgxUiLoaderService } from './ngx-ui-loader.service';
44import { Observable , Subscription } from 'rxjs' ;
55import { NgxUiLoaderConfig } from './ngx-ui-loader-config' ;
66import { DirectionType , PositionType , SpinnerType } from './ngx-ui-loader.types' ;
7- import { NGX_POSITIONS , PB_DIRECTIONS , SPINNER_TYPES } from './ngx-ui-loader.enums' ;
7+ import { POSITION , PB_DIRECTION , SPINNER } from './ngx-ui-loader.enums' ;
88import { SPINNER_CONFIG } from './ngx-ui-loader.contants' ;
9+ import { coerceNumber } from './coercion' ;
910
1011@Component ( {
1112 selector : 'ngx-ui-loader' ,
@@ -98,11 +99,11 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
9899 this . initializeSpinners ( ) ;
99100 this . determinePositions ( ) ;
100101
101- this . bgsPosition = < PositionType > this . validate ( 'bgsPosition' , this . bgsPosition , NGX_POSITIONS , this . defaultConfig . bgsPosition ) ;
102+ this . bgsPosition = < PositionType > this . validate ( 'bgsPosition' , this . bgsPosition , POSITION , this . defaultConfig . bgsPosition ) ;
102103
103104 this . trustedLogoUrl = this . domSanitizer . bypassSecurityTrustResourceUrl ( this . logoUrl ) ;
104105
105- this . pbDirection = < DirectionType > this . validate ( 'pbDirection' , this . pbDirection , PB_DIRECTIONS , this . defaultConfig . pbDirection ) ;
106+ this . pbDirection = < DirectionType > this . validate ( 'pbDirection' , this . pbDirection , PB_DIRECTION , this . defaultConfig . pbDirection ) ;
106107
107108 this . showForegroundWatcher = this . ngxService . showForeground
108109 . subscribe ( data => this . showForeground = data ) ;
@@ -140,24 +141,24 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
140141 this . determinePositions ( ) ;
141142
142143 if ( bgsPositionChange ) {
143- this . bgsPosition = < PositionType > this . validate ( 'bgsPosition' , this . bgsPosition , NGX_POSITIONS , this . defaultConfig . bgsPosition ) ;
144+ this . bgsPosition = < PositionType > this . validate ( 'bgsPosition' , this . bgsPosition , POSITION , this . defaultConfig . bgsPosition ) ;
144145 }
145146
146147 if ( logoUrlChange ) {
147148 this . trustedLogoUrl = this . domSanitizer . bypassSecurityTrustResourceUrl ( this . logoUrl ) ;
148149 }
149150
150151 if ( pbDirectionChange ) {
151- this . pbDirection = < DirectionType > this . validate ( 'pbDirection' , this . pbDirection , PB_DIRECTIONS , this . defaultConfig . pbDirection ) ;
152+ this . pbDirection = < DirectionType > this . validate ( 'pbDirection' , this . pbDirection , PB_DIRECTION , this . defaultConfig . pbDirection ) ;
152153 }
153154 }
154155
155156 /**
156157 * Initialize spinners
157158 */
158159 private initializeSpinners ( ) {
159- this . fgsType = < SpinnerType > this . validate ( 'fgsType' , this . fgsType , SPINNER_TYPES , this . defaultConfig . fgsType ) ;
160- this . bgsType = < SpinnerType > this . validate ( 'bgsType' , this . bgsType , SPINNER_TYPES , this . defaultConfig . bgsType ) ;
160+ this . fgsType = < SpinnerType > this . validate ( 'fgsType' , this . fgsType , SPINNER , this . defaultConfig . fgsType ) ;
161+ this . bgsType = < SpinnerType > this . validate ( 'bgsType' , this . bgsType , SPINNER , this . defaultConfig . bgsType ) ;
161162
162163 this . fgDivs = Array ( SPINNER_CONFIG [ this . fgsType ] . divs ) . fill ( 1 ) ;
163164 this . fgSpinnerClass = SPINNER_CONFIG [ this . fgsType ] . class ;
@@ -169,10 +170,10 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
169170 * Determine the positions of spinner, logo and text
170171 */
171172 private determinePositions ( ) {
172- this . fgsPosition = < PositionType > this . validate ( 'fgsPosition' , this . fgsPosition , NGX_POSITIONS , this . defaultConfig . fgsPosition ) ;
173- this . logoPosition = < PositionType > this . validate ( 'logoPosition' , this . logoPosition , NGX_POSITIONS , this . defaultConfig . logoPosition ) ;
174- this . textPosition = < PositionType > this . validate ( 'textPosition' , this . textPosition , NGX_POSITIONS , this . defaultConfig . textPosition ) ;
175- this . gap = ! isNaN ( parseFloat ( this . gap as any ) ) && ! isNaN ( Number ( this . gap ) ) ? Number ( this . gap ) : 24 ;
173+ this . fgsPosition = < PositionType > this . validate ( 'fgsPosition' , this . fgsPosition , POSITION , this . defaultConfig . fgsPosition ) ;
174+ this . logoPosition = < PositionType > this . validate ( 'logoPosition' , this . logoPosition , POSITION , this . defaultConfig . logoPosition ) ;
175+ this . textPosition = < PositionType > this . validate ( 'textPosition' , this . textPosition , POSITION , this . defaultConfig . textPosition ) ;
176+ this . gap = coerceNumber ( this . gap , this . defaultConfig . gap ) ;
176177
177178 this . logoTop = 'initial' ;
178179 this . spinnerTop = 'initial' ;
@@ -197,9 +198,9 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
197198 this . textTop = '30px' ;
198199 }
199200
200- if ( this . fgsPosition === NGX_POSITIONS . centerCenter ) {
201- if ( this . logoUrl && this . logoPosition === NGX_POSITIONS . centerCenter ) {
202- if ( this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // logo, spinner and text
201+ if ( this . fgsPosition === POSITION . centerCenter ) {
202+ if ( this . logoUrl && this . logoPosition === POSITION . centerCenter ) {
203+ if ( this . text && this . textPosition === POSITION . centerCenter ) { // logo, spinner and text
203204 this . logoTop = this . domSanitizer
204205 . bypassSecurityTrustStyle ( `calc(50% - ${ this . fgsSize / 2 } px - ${ textSize / 2 } px - ${ this . gap } px)` ) ;
205206 this . spinnerTop = this . domSanitizer
@@ -213,16 +214,16 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
213214 . bypassSecurityTrustStyle ( `calc(50% + ${ this . logoSize / 2 } px + ${ this . gap / 2 } px)` ) ;
214215 }
215216 } else {
216- if ( this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // spinner and text
217+ if ( this . text && this . textPosition === POSITION . centerCenter ) { // spinner and text
217218 this . spinnerTop = this . domSanitizer
218219 . bypassSecurityTrustStyle ( `calc(50% - ${ textSize / 2 } px - ${ this . gap / 2 } px)` ) ;
219220 this . textTop = this . domSanitizer
220221 . bypassSecurityTrustStyle ( `calc(50% + ${ this . fgsSize / 2 } px + ${ this . gap / 2 } px)` ) ;
221222 }
222223 }
223224 } else {
224- if ( this . logoUrl && this . logoPosition === NGX_POSITIONS . centerCenter
225- && this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // logo and text
225+ if ( this . logoUrl && this . logoPosition === POSITION . centerCenter
226+ && this . text && this . textPosition === POSITION . centerCenter ) { // logo and text
226227 this . logoTop = this . domSanitizer
227228 . bypassSecurityTrustStyle ( `calc(50% - ${ textSize / 2 } px - ${ this . gap / 2 } px)` ) ;
228229 this . textTop = this . domSanitizer
0 commit comments