Skip to content

Commit 32564d6

Browse files
authored
Merge pull request t-ho#4 from t-ho/dev
Added NgxUiLoaderBlurred directive
2 parents 9d0bebb + ed13036 commit 32564d6

18 files changed

+460
-204
lines changed

README.md

Lines changed: 173 additions & 59 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 37 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-ui-loader-app",
3-
"version": "1.1.9",
3+
"version": "1.2.0",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
@@ -12,14 +12,14 @@
1212
"private": true,
1313
"dependencies": {
1414
"@angular/animations": "^6.0.3",
15-
"@angular/cdk": "^6.2.0",
15+
"@angular/cdk": "^6.2.1",
1616
"@angular/common": "^6.0.3",
1717
"@angular/compiler": "^6.0.3",
1818
"@angular/core": "^6.0.3",
1919
"@angular/flex-layout": "^6.0.0-beta.15",
2020
"@angular/forms": "^6.0.3",
2121
"@angular/http": "^6.0.3",
22-
"@angular/material": "^6.2.0",
22+
"@angular/material": "^6.2.1",
2323
"@angular/platform-browser": "^6.0.3",
2424
"@angular/platform-browser-dynamic": "^6.0.3",
2525
"@angular/router": "^6.0.3",

projects/ngx-ui-loader/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ngx-ui-loader",
33
"description": "An all-in-one and fully customizable loader/spinner for Angular 5+ (5+ and 6+ are tested) applications. It supports foreground, background spinner/loader and indicative progress bar.",
4-
"version": "1.1.9",
4+
"version": "1.2.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/t-ho/ngx-ui-loader.git"
@@ -15,7 +15,6 @@
1515
"@angular/core": ">=4.4.0"
1616
},
1717
"keywords": [
18-
"ngx",
1918
"ngx-ui-loader",
2019
"ngx-loader",
2120
"loader",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Coerce a value (string) to a number
3+
* @param value
4+
* @param fallbackValue
5+
*/
6+
export function coerceNumber(value, fallbackValue): number {
7+
return !isNaN(parseFloat(value as any)) && !isNaN(Number(value)) ? Number(value) : fallbackValue;
8+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Directive, ElementRef, Input, OnDestroy, Renderer2 } from '@angular/core';
2+
import { Subscription } from 'rxjs';
3+
import { NgxUiLoaderService } from './ngx-ui-loader.service';
4+
import { coerceNumber } from './coercion';
5+
6+
const DELAY = 500;
7+
8+
@Directive({ selector: '[ngxUiLoaderBlurred]' })
9+
export class NgxUiLoaderBlurredDirective implements OnDestroy {
10+
11+
private _blur: number;
12+
private _filterValue: string;
13+
14+
@Input()
15+
get blur(): number {
16+
return this._blur;
17+
}
18+
19+
set blur(value: number) {
20+
this._blur = coerceNumber(value, this.ngxUiLoaderService.getDefaultConfig().blur);
21+
}
22+
23+
showForegroundWatcher: Subscription;
24+
25+
constructor(
26+
private elementRef: ElementRef,
27+
private renderer: Renderer2,
28+
private ngxUiLoaderService: NgxUiLoaderService
29+
) {
30+
this._blur = this.ngxUiLoaderService.getDefaultConfig().blur;
31+
32+
this.showForegroundWatcher = this.ngxUiLoaderService.showForeground
33+
.subscribe(showForeground => {
34+
if (showForeground) {
35+
const filterValue = `blur(${this._blur}px)`;
36+
this.renderer.setStyle(this.elementRef.nativeElement, '-webkit-filter', filterValue);
37+
this.renderer.setStyle(this.elementRef.nativeElement, 'filter', filterValue);
38+
} else {
39+
setTimeout(() => {
40+
this.renderer.setStyle(this.elementRef.nativeElement, '-webkit-filter', 'none');
41+
this.renderer.setStyle(this.elementRef.nativeElement, 'filter', 'none');
42+
}, DELAY);
43+
}
44+
});
45+
46+
}
47+
48+
/**
49+
* On destroy event
50+
*/
51+
ngOnDestroy() {
52+
if (this.showForegroundWatcher) {
53+
this.showForegroundWatcher.unsubscribe();
54+
}
55+
}
56+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface NgxUiLoaderConfig {
88
bgsOpacity?: number;
99
bgsPosition?: PositionType;
1010
bgsSize?: number;
11+
blur?: number;
1112
bgsType?: SpinnerType;
1213
fgsColor?: string;
1314
fgsPosition?: PositionType;

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { NgxUiLoaderService } from './ngx-ui-loader.service';
44
import { Observable, Subscription } from 'rxjs';
55
import { NgxUiLoaderConfig } from './ngx-ui-loader-config';
66
import { 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';
88
import { 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

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgxUiLoaderConfig } from './ngx-ui-loader-config';
2-
import { NGX_POSITIONS, PB_DIRECTIONS, SPINNER_TYPES } from './ngx-ui-loader.enums';
2+
import { POSITION, PB_DIRECTION, SPINNER } from './ngx-ui-loader.enums';
33

44
/**
55
* The configuration of spinners
@@ -101,33 +101,29 @@ export const SPINNER_CONFIG = {
101101
export const DEFAULT_CONFIG: NgxUiLoaderConfig = {
102102
bgsColor: '#00ACC1',
103103
bgsOpacity: 0.5,
104-
bgsPosition: NGX_POSITIONS.bottomRight,
104+
bgsPosition: POSITION.bottomRight,
105105
bgsSize: 60,
106-
bgsType: SPINNER_TYPES.rectangleBounce,
106+
bgsType: SPINNER.rectangleBounce,
107+
blur: 5,
107108
fgsColor: '#00ACC1',
108-
fgsPosition: NGX_POSITIONS.centerCenter,
109+
fgsPosition: POSITION.centerCenter,
109110
fgsSize: 60,
110-
fgsType: SPINNER_TYPES.rectangleBounce,
111+
fgsType: SPINNER.rectangleBounce,
111112
gap: 24,
112-
logoPosition: NGX_POSITIONS.centerCenter,
113+
logoPosition: POSITION.centerCenter,
113114
logoSize: 120,
114115
logoUrl: '',
115116
overlayColor: 'rgba(40, 40, 40, 0.8)',
116117
pbColor: '#00ACC1',
117-
pbDirection: PB_DIRECTIONS.leftToRight,
118+
pbDirection: PB_DIRECTION.leftToRight,
118119
pbThickness: 5,
119120
text: '',
120121
textColor: '#FFFFFF',
121-
textPosition: NGX_POSITIONS.centerCenter,
122+
textPosition: POSITION.centerCenter,
122123
threshold: 500
123124
};
124125

125126
/**
126127
* The default id of the loading
127128
*/
128129
export const DEFAULT_ID = 'default';
129-
130-
/**
131-
* The time close out a loading
132-
*/
133-
export const INTERVAL = 1100;

0 commit comments

Comments
 (0)