Skip to content

Commit d914103

Browse files
committed
Correctly center logo, foreground spinner and text - can set the gap
1 parent 5fc1e88 commit d914103

File tree

9 files changed

+90
-60
lines changed

9 files changed

+90
-60
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class AppModule { }
169169
| `fgsPosition` | *string* | optional | `center-center` | Foreground spinner position. All available positions can be accessed via `NGX_POSITIONS` |
170170
| `fgsSize` | *number* | optional | `60` | Foreground spinner size. |
171171
| `fgsType` | *string* | optional | `rectangle-bounce`| Foreground spinner type. All available types can be accessed via `SPINNER_TYPES` |
172+
| `gap` | *number* | optional | `24` | The gap between logo, foreground spinner and text when their position are `center-center` |
172173
| `logoPosition` | *string* | optional | `center-center` | Logo position. All available positions can be accessed via `NGX_POSITIONS` |
173174
| `logoSize` | *number* | optional | `120` | Logo size (px) |
174175
| `logoUrl` | *string* | optional | (*empty string*) | Logo url |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-ui-loader-app",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

projects/ngx-ui-loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ngx-ui-loader",
33
"description": "A fully customizable loader/spinner and progress bar for Angular 4, 5(tested) and 6+(tested) applications - AoT compatible.",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/t-ho/ngx-ui-loader.git"

projects/ngx-ui-loader/src/lib/ngx-ui-loader-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface NgxUiLoaderConfig {
1111
fgsPosition?: string;
1212
fgsSize?: number;
1313
fgsType?: string;
14+
gap?: number;
1415
logoPosition?: string;
1516
logoSize?: number;
1617
logoUrl?: string;
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
1+
<!-- Progress bar {{{ -->
12
<div [ngClass]="'ngx-ui-loader-bar-' + pbDirection"
23
[style.height.px]="pbThickness"
34
[style.color]="pbColor"
45
[class.loading-foreground]="showForeground"
56
[class.foreground-closing]="foregroundClosing"></div>
7+
<!-- Progress bar }}} -->
68

9+
<!-- Foreground container {{{ -->
710
<div class="ngx-overlay"
811
[style.background-color]="overlayColor"
912
[class.loading-foreground]="showForeground"
1013
[class.foreground-closing]="foregroundClosing">
14+
15+
<!-- Logo {{{ -->
1116
<img *ngIf="logoUrl" class="ngx-loading-logo"
12-
[ngClass]="realLogoPosition" [src]="trustedLogoUrl"
13-
[style.width.px]="logoSize" [style.height.px]="logoSize">
17+
[ngClass]="logoPosition" [src]="trustedLogoUrl"
18+
[style.width.px]="logoSize" [style.height.px]="logoSize"
19+
[style.top]="logoTop">
20+
<!-- Logo }}} -->
21+
22+
<!-- Foreground spinner {{{ -->
1423
<div class="ngx-foreground-spinner"
1524
[ngClass]="fgsPosition" [style.color]="fgsColor"
16-
[style.width.px]="fgsSize" [style.height.px]="fgsSize">
25+
[style.width.px]="fgsSize" [style.height.px]="fgsSize"
26+
[style.top]="spinnerTop">
1727
<div [class]="fgSpinnerClass">
1828
<div *ngFor="let div of fgDivs"></div>
1929
</div>
2030
</div>
31+
<!-- Foreground spinner }}} -->
32+
33+
<!-- Loading text {{{ -->
2134
<div class="ngx-loading-text"
22-
[ngClass]="realTextPosition"
35+
[ngClass]="textPosition"
36+
[style.top]="textTop"
2337
[style.color]="textColor">{{text}}</div>
38+
<!-- Loading text }}} -->
39+
2440
</div>
41+
<!-- Foreground container }}} -->
2542

43+
<!-- Background spinner {{{ -->
2644
<div class="ngx-background-spinner"
2745
[ngClass]="bgsPosition"
2846
[class.loading-background]="showBackground"
@@ -32,4 +50,5 @@
3250
<div [class]="bgSpinnerClass">
3351
<div *ngFor="let div of bgDivs"></div>
3452
</div>
35-
</div>
53+
</div>
54+
<!-- Background spinner }}} -->

projects/ngx-ui-loader/src/lib/ngx-ui-loader.component.scss

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ $spinnerSize: 60px;
209209
}
210210

211211
.ngx-overlay > .ngx-foreground-spinner {
212-
position: absolute;
212+
position: fixed;
213213
width: $spinnerSize;
214214
height: $spinnerSize;
215215
margin: 0;
216216
color: $spinnerColor;
217217
}
218218

219219
.ngx-overlay > .ngx-loading-logo {
220-
position: absolute;
220+
position: fixed;
221221
margin: 0;
222222
width: $logoSize;
223223
height: $logoSize;
224224
}
225225

226226
.ngx-overlay > .ngx-loading-text {
227-
position: absolute;
227+
position: fixed;
228228
margin: 0;
229229
font-family: sans-serif;
230230
font-weight: $loadingTextFontWeight;
@@ -320,32 +320,6 @@ $spinnerSize: 60px;
320320
right: 30px;
321321
}
322322

323-
.ngx-loading-text-center-with-logo {
324-
position: fixed;
325-
top: calc(50% + 60px + 36px);
326-
left: 50%;
327-
-webkit-transform: translate(-50%, -50%);
328-
-ms-transform: translate(-50%, -50%);
329-
transform: translate(-50%, -50%);
330-
}
331-
332-
.ngx-loading-text-center-with-spinner {
333-
position: fixed;
334-
top: calc(50% + 30px + 36px);
335-
left: 50%;
336-
-webkit-transform: translate(-50%, -50%);
337-
-ms-transform: translate(-50%, -50%);
338-
transform: translate(-50%, -50%);
339-
}
340-
341-
.ngx-loading-logo-center-with-spinner {
342-
position: fixed;
343-
top: calc(50% - 30px - 84px);
344-
left: 50%;
345-
-webkit-transform: translate(-50%, -50%);
346-
-ms-transform: translate(-50%, -50%);
347-
transform: translate(-50%, -50%);
348-
}
349323
// Utility classes }}}
350324

351325
// sk-rotating-plane {{{

projects/ngx-ui-loader/src/lib/ngx-ui-loader.component.ts

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

projects/ngx-ui-loader/src/lib/ngx-ui-loader.contants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const DEFAULT_CONFIG: NgxUiLoaderConfig = {
108108
fgsPosition: NGX_POSITIONS.centerCenter,
109109
fgsSize: 60,
110110
fgsType: SPINNER_TYPES.rectangleBounce,
111+
gap: 24,
111112
logoPosition: NGX_POSITIONS.centerCenter,
112113
logoSize: 120,
113114
logoUrl: '',

src/app/app.component.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[bgsPosition]="config.bgsPosition"
99
[bgsSize]="config.bgsSize"
1010
[bgsType]="config.bgsType"
11+
[gap]="config.gap"
1112
[logoPosition]="config.logoPosition"
1213
[logoSize]="config.logoSize"
1314
[logoUrl]="config.logoUrl"
@@ -193,14 +194,15 @@ <h3>A fully customizable loader/spinner for angular 5+ and 6+</h3>
193194
<mat-icon matSuffix [style.color]="config.pbColor" fontIcon="mdi-palette" fontSet="mdi"></mat-icon>
194195
</mat-form-field>
195196

197+
<div>
198+
<span class="place-holder">Gap between logo, spinner and text (gap)</span>
199+
<mat-slider fxFlex="100" max="150" min="10" step="1" [thumbLabel]="true" [(ngModel)]="config.gap"></mat-slider>
200+
</div>
201+
196202
<div style="margin-top: 21px; margin-bottom: 20px">
197203
<mat-checkbox (change)="addLogo($event.checked)" [checked]="config.logoUrl">Add logo</mat-checkbox>
198204
</div>
199205

200-
<mat-form-field>
201-
<input matInput placeholder="Logo (logoUrl)" [(ngModel)]="config.logoUrl" autocomplete="off" disabled>
202-
</mat-form-field>
203-
204206
<mat-form-field>
205207
<mat-select placeholder="Logo Position (logoPosition)" [(value)]="config.logoPosition" [disabled]="!config.logoUrl">
206208
<mat-option *ngFor="let position of positions" [value]="position">

0 commit comments

Comments
 (0)