@@ -21,6 +21,7 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
2121 @Input ( ) fgsPosition : string ;
2222 @Input ( ) fgsSize : number ;
2323 @Input ( ) fgsType : string ;
24+ @Input ( ) gap : number ;
2425 @Input ( ) logoPosition : string ;
2526 @Input ( ) logoSize : number ;
2627 @Input ( ) logoUrl : string ;
@@ -41,9 +42,10 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
4142 foregroundClosing : boolean ;
4243 backgroundClosing : boolean ;
4344
44- realTextPosition : string ;
45- realLogoPosition : string ;
4645 trustedLogoUrl : any ;
46+ logoTop : any ;
47+ spinnerTop : any ;
48+ textTop : any ;
4749
4850 showForegroundWatcher : Subscription ;
4951 showBackgroundWatcher : Subscription ;
@@ -69,6 +71,7 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
6971 this . fgsPosition = this . defaultConfig . fgsPosition ;
7072 this . fgsSize = this . defaultConfig . fgsSize ;
7173 this . fgsType = this . defaultConfig . fgsType ;
74+ this . gap = this . defaultConfig . gap ;
7275 this . logoPosition = this . defaultConfig . logoPosition ;
7376 this . logoSize = this . defaultConfig . logoSize ;
7477 this . logoUrl = this . defaultConfig . logoUrl ;
@@ -79,8 +82,6 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
7982 this . text = this . defaultConfig . text ;
8083 this . textColor = this . defaultConfig . textColor ;
8184 this . textPosition = this . defaultConfig . textPosition ;
82- this . realLogoPosition = this . logoPosition ;
83- this . realTextPosition = this . textPosition ;
8485 }
8586
8687 ngOnInit ( ) {
@@ -110,21 +111,15 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
110111
111112 const fgsTypeChange : SimpleChange = changes . fgsType ;
112113 const bgsTypeChange : SimpleChange = changes . bgsType ;
113- const fgsPositionChange : SimpleChange = changes . fgsPosition ;
114114 const bgsPositionChange : SimpleChange = changes . bgsPosition ;
115- const logoPositionChange : SimpleChange = changes . logoPosition ;
116115 const logoUrlChange : SimpleChange = changes . logoUrl ;
117- const textPositionChange : SimpleChange = changes . textPosition ;
118- const textChange : SimpleChange = changes . text ;
119116 const progressBarDirectionChange : SimpleChange = changes . pbDirection ;
120117
121118 if ( fgsTypeChange || bgsTypeChange ) {
122119 this . initializeSpinners ( ) ;
123120 }
124121
125- if ( fgsPositionChange || logoPositionChange || logoUrlChange || textChange || textPositionChange ) {
126- this . determinePositions ( ) ;
127- }
122+ this . determinePositions ( ) ;
128123
129124 if ( logoUrlChange ) {
130125 this . trustedLogoUrl = this . domSanitizer . bypassSecurityTrustResourceUrl ( this . logoUrl ) ;
@@ -155,22 +150,59 @@ export class NgxUiLoaderComponent implements OnChanges, OnDestroy, OnInit {
155150 this . logoPosition = this . helperService . validatePosition ( 'logoPosition' , this . logoPosition , this . defaultConfig . logoPosition ) ;
156151 this . textPosition = this . helperService . validatePosition ( 'textPosition' , this . textPosition , this . defaultConfig . textPosition ) ;
157152
158- this . realLogoPosition = this . logoPosition ;
159- this . realTextPosition = this . textPosition ;
153+ this . logoTop = 'initial' ;
154+ this . spinnerTop = 'initial' ;
155+ this . textTop = 'initial' ;
156+ const textSize = 24 ;
157+
158+ if ( this . logoPosition . startsWith ( 'center' ) ) {
159+ this . logoTop = '50%' ;
160+ } else if ( this . logoPosition . startsWith ( 'top' ) ) {
161+ this . logoTop = '30px' ;
162+ }
163+
164+ if ( this . fgsPosition . startsWith ( 'center' ) ) {
165+ this . spinnerTop = '50%' ;
166+ } else if ( this . fgsPosition . startsWith ( 'top' ) ) {
167+ this . spinnerTop = '30px' ;
168+ }
169+
170+ if ( this . textPosition . startsWith ( 'center' ) ) {
171+ this . textTop = '50%' ;
172+ } else if ( this . textPosition . startsWith ( 'top' ) ) {
173+ this . textTop = '30px' ;
174+ }
175+
160176 if ( this . fgsPosition === NGX_POSITIONS . centerCenter ) {
161177 if ( this . logoUrl && this . logoPosition === NGX_POSITIONS . centerCenter ) {
162- if ( this . textPosition === NGX_POSITIONS . centerCenter ) {
163- this . realTextPosition = 'ngx-loading-text-center-with-spinner' ;
178+ if ( this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // logo, spinner and text
179+ this . logoTop = this . domSanitizer
180+ . bypassSecurityTrustStyle ( `calc(50% - ${ this . fgsSize / 2 } px - ${ textSize / 2 } px - ${ this . gap } px)` ) ;
181+ this . spinnerTop = this . domSanitizer
182+ . bypassSecurityTrustStyle ( `calc(50% + ${ this . logoSize / 2 } px - ${ textSize / 2 } px)` ) ;
183+ this . textTop = this . domSanitizer
184+ . bypassSecurityTrustStyle ( `calc(50% + ${ this . logoSize / 2 } px + ${ this . gap } px + ${ this . fgsSize / 2 } px)` ) ;
185+ } else { // logo and spinner
186+ this . logoTop = this . domSanitizer
187+ . bypassSecurityTrustStyle ( `calc(50% - ${ this . fgsSize / 2 } px - ${ this . gap / 2 } px)` ) ;
188+ this . spinnerTop = this . domSanitizer
189+ . bypassSecurityTrustStyle ( `calc(50% + ${ this . logoSize / 2 } px + ${ this . gap / 2 } px)` ) ;
164190 }
165- this . realLogoPosition = 'ngx-loading-logo-center-with-spinner' ;
166191 } else {
167- if ( this . textPosition === NGX_POSITIONS . centerCenter ) {
168- this . realTextPosition = 'ngx-loading-text-center-with-spinner' ;
192+ if ( this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // spinner and text
193+ this . spinnerTop = this . domSanitizer
194+ . bypassSecurityTrustStyle ( `calc(50% - ${ textSize / 2 } px - ${ this . gap / 2 } px)` ) ;
195+ this . textTop = this . domSanitizer
196+ . bypassSecurityTrustStyle ( `calc(50% + ${ this . fgsSize / 2 } px + ${ this . gap / 2 } px)` ) ;
169197 }
170198 }
171199 } else {
172- if ( this . logoUrl && this . logoPosition === NGX_POSITIONS . centerCenter && this . textPosition === NGX_POSITIONS . centerCenter ) {
173- this . realTextPosition = 'ngx-loading-text-center-with-logo' ;
200+ if ( this . logoUrl && this . logoPosition === NGX_POSITIONS . centerCenter
201+ && this . text && this . textPosition === NGX_POSITIONS . centerCenter ) { // logo and text
202+ this . logoTop = this . domSanitizer
203+ . bypassSecurityTrustStyle ( `calc(50% - ${ textSize / 2 } px - ${ this . gap / 2 } px)` ) ;
204+ this . textTop = this . domSanitizer
205+ . bypassSecurityTrustStyle ( `calc(50% + ${ this . logoSize / 2 } px + ${ this . gap / 2 } px)` ) ;
174206 }
175207 }
176208 }
0 commit comments