Skip to content

Commit 7e39bf1

Browse files
committed
Add more spinners and background is showed after foreground is closed out
1 parent 00d658a commit 7e39bf1

15 files changed

+1035
-67
lines changed

README.md

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ An all-in-one and fully customizable loader/spinner for Angular 5+ (5+ and 6+ ar
1111

1212
Available spinners:
1313

14-
[![ngx-ui-loader-spinners](https://j.gifs.com/L8VWkp.gif)](https://ngx-ui-loader-demo.stackblitz.io/spinners)
14+
[![ngx-ui-loader-spinners](https://j.gifs.com/G5VxP7.gif)](https://ngx-ui-loader-demo.stackblitz.io/spinners)
1515

1616
### Features
1717

@@ -22,13 +22,30 @@ Available spinners:
2222
* Be able to change color and size of logo, spinners and progress bar
2323
* Be able to change the direction of progress bar
2424

25-
## Demo
25+
## Table Of Contents
26+
- [Demo](#demo)
27+
- [Installation](#installation)
28+
- [Getting Started](#getting_started)
29+
- [Usage](#usage)
30+
- [API - NgxUiLoaderService](#api_service)
31+
- [Custom Configuration](#configuration)
32+
- [Input options](#input_options)
33+
- [Automatically show loader for router events](#router_events)
34+
- [Changelog](#changelog)
35+
- [Credits](#credits)
36+
- [License](#license)
37+
38+
39+
<a name="demo"></a>
40+
41+
## Demo <a name="demo"></a>
2642

2743
Live demo [here](https://ngx-ui-loader-demo.stackblitz.io).
2844

2945
Play with **ngx-ui-loader** [here](https://stackblitz.com/edit/ngx-ui-loader-demo) on stackblitz.
3046

31-
## Installation
47+
48+
## Installation <a name="installation"></a>
3249

3350
Install `ngx-ui-loader` via NPM, using the command below.
3451

@@ -37,7 +54,11 @@ Install `ngx-ui-loader` via NPM, using the command below.
3754
```shell
3855
npm install --save ngx-ui-loader
3956
```
40-
## Getting started
57+
58+
59+
<a name="getting_started"></a>
60+
61+
## Getting started <a name="getting_started"></a>
4162

4263
Import the `NgxUiLoaderModule` in your root application module `AppModule`:
4364

@@ -66,7 +87,10 @@ export class AppModule { }
6687

6788
```
6889

69-
## Usage
90+
91+
<a name="usage"></a>
92+
93+
## Usage <a name="usage"></a>
7094

7195
After importing the `NgxUiLoaderModule`, use `ngx-ui-loader` component in your root app template:
7296

@@ -107,7 +131,9 @@ export class AppComponent implements OnInit {
107131

108132
```
109133

110-
## NgxUiLoaderService service
134+
<a name="api_service"></a>
135+
136+
## API - NgxUiLoaderService <a name="api_service"></a>
111137

112138
* `NgxUiLoaderService.start([id]='default')` Starts a foreground loader with progress bar. Users cannot interact with the page when the loader is showed.
113139
* `NgxUiLoaderService.stop([id]='default')` Stops a foreground loader with progress bar.
@@ -117,7 +143,10 @@ export class AppComponent implements OnInit {
117143
* `NgxUiLoaderService.getStatus()` Returns an object including `waitingForeground` and `waitingBackground` properties.
118144
* `NgxUiLoaderService.stopAll()` Stops all foreground and background loaders.
119145

120-
## Configuration
146+
147+
<a name="configuration"></a>
148+
149+
## Custom Configuration <a name="configuration"></a>
121150

122151
You can configure `ngx-ui-loader` in the template as below:
123152

@@ -162,7 +191,9 @@ export class AppModule { }
162191

163192
```
164193

165-
## Input Options
194+
<a name="input_options"></a>
195+
196+
## Input Options <a name="input_options"></a>
166197

167198
| Attribute | Type | Required | Default | Description |
168199
| ---------------- | --------- | -------- | ------------------ | ----------------------------------------------------------------------------------------------- |
@@ -193,7 +224,10 @@ export class AppModule { }
193224
| `overlayColor` | *string* | optional | `rgba(40,40,40,.8)`| Overlay background color |
194225
| `threshold` | *number* | optional | `500` | The time a loader must be showed at least before it can be stopped. It must be >= 1 millisecond. **NOTE: `threshold` is only configured via forRoot() method.**||
195226

196-
## Automatically show loader for router events
227+
228+
<a name="router_events"></a>
229+
230+
## Automatically show loader for router events <a name="router_events"></a>
197231

198232
If you want the loader to start automatically for navigating between your app routes:
199233

@@ -230,7 +264,14 @@ NOTE: And in you root app template, do not forget to include `ngx-ui-loader` com
230264
<ngx-ui-loader></ngx-ui-loader>
231265
```
232266

233-
## Changelog
267+
268+
<a name="changelog"></a>
269+
270+
## Changelog <a name="changelog"></a>
271+
272+
### v.1.1.2
273+
* Add more spinner types (total 22 spinners)
274+
* Bugs fixed: Background spinner (if active) should be showed after the foreground spinner is closed out.
234275

235276
### v.1.1.1
236277
* Bugs fixed
@@ -264,13 +305,19 @@ NOTE: And in you root app template, do not forget to include `ngx-ui-loader` com
264305
* Be able to change color and size of spinners and progress bar
265306
* Be able to change the direction of progress bar
266307

267-
## Credits
308+
309+
<a name="credits"></a>
310+
311+
## Credits <a name="credits"></a>
268312

269313
* Tobias Ahlin - [CSS spinkit](https://github.com/tobiasahlin/SpinKit)
270314
* Daniel Cardoso - [Load awesome](https://github.com/danielcardoso/load-awesome)
271315
* Matt Carter - AngularJS `angular-ui-loader`
272316

273-
## License
317+
318+
<a name="license"></a>
319+
320+
## License <a name="license"></a>
274321

275322
MIT &copy; [t-ho](mailto:toan.hmt@gmail.com)
276323

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.1.1",
3+
"version": "1.1.2",
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": "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.1",
4+
"version": "1.1.2",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/t-ho/ngx-ui-loader.git"

projects/ngx-ui-loader/src/lib/core/ngx-ui-loader-helper.service.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class NgxUiLoaderHelperService {
2727
foregroundClosing: Observable<boolean>;
2828
backgroundClosing: Observable<boolean>;
2929

30+
/**
31+
* Constructor
32+
* @param config
33+
*/
3034
constructor(@Optional() @Inject(NGX_UI_LOADER_CONFIG_TOKEN) private config: NgxUiLoaderConfig) {
3135

3236
this.validSpinnerTypes = Object.keys(SPINNER_TYPES).map(key => SPINNER_TYPES[key]);
@@ -78,15 +82,15 @@ export class NgxUiLoaderHelperService {
7882

7983
/**
8084
* Get default loader configuration
81-
* @return default configuration object
85+
* @returns default configuration object
8286
*/
8387
getDefaultConfig(): NgxUiLoaderConfig {
8488
return Object.assign({}, this.defaultConfig);
8589
}
8690

8791
/**
8892
* Get current status
89-
* @return An object with waiting foreground and background properties
93+
* @returns An object with waiting foreground and background properties
9094
*/
9195
getStatus() {
9296
return {
@@ -97,23 +101,23 @@ export class NgxUiLoaderHelperService {
97101

98102
/**
99103
* Determine whether the loader is active
100-
* @return true if the loader is active
104+
* @returns true if the loader is active
101105
*/
102106
private isActive() {
103107
return Object.keys(this.waitingForeground).length > 0 || Object.keys(this.waitingBackground).length > 0;
104108
}
105109

106110
/**
107111
* Check whether the queue has any waiting foreground loader
108-
* @return true if at least one waiting foreground loader exists
112+
* @returns true if at least one waiting foreground loader exists
109113
*/
110114
private hasForeground() {
111115
return Object.keys(this.waitingForeground).length > 0;
112116
}
113117

114118
/**
115119
* Check whether the queue has any waiting background loader
116-
* @return true if at least one waiting background loader exists
120+
* @returns true if at least one waiting background loader exists
117121
*/
118122
private hasBackground() {
119123
return Object.keys(this.waitingBackground).length > 0;
@@ -153,7 +157,7 @@ export class NgxUiLoaderHelperService {
153157
/**
154158
* Stop a foreground loading with specific id
155159
* @param id the optional id to stop. If not provided, 'default' is used.
156-
* @return
160+
* @returns Object
157161
*/
158162
stop(id?: string): Object {
159163
const now = Date.now();
@@ -180,15 +184,18 @@ export class NgxUiLoaderHelperService {
180184
if (!this.hasForeground()) {
181185
this.foregroundCloseout();
182186
this._showForeground.next(false);
183-
this._showBackground.next(true);
187+
// Show background spinner after the foreground is closed out
188+
setTimeout(() => {
189+
this._showBackground.next(true);
190+
}, 500);
184191
}
185192
return { id: id, isForeground: true, isSuccess: true, stopAll: false };
186193
}
187194

188195
/**
189196
* Stop a background loading with specific id
190197
* @param id the optional id to stop. If not provided, 'default' is used.
191-
* @return
198+
* @returns Object
192199
*/
193200
stopBackground(id?: string): Object {
194201
const now = Date.now();
@@ -220,7 +227,7 @@ export class NgxUiLoaderHelperService {
220227
* @param inputName The name of the input property
221228
* @param value The spinner type to verify
222229
* @param defaultValue The default spinner type
223-
* @return a valid spinner type
230+
* @returns a valid spinner type
224231
*/
225232
validateSpinnerType(inputName: string, value: string, defaultValue: string) {
226233
return this.validate(this.validSpinnerTypes, inputName, value, defaultValue);
@@ -231,7 +238,7 @@ export class NgxUiLoaderHelperService {
231238
* @param inputName The name of the input property
232239
* @param value The position value to verify
233240
* @param defaultValue the default position
234-
* @return a valid position
241+
* @returns a valid position
235242
*/
236243
validatePosition(inputName: string, value: string, defaultValue: string) {
237244
return this.validate(this.validPositions, inputName, value, defaultValue);
@@ -242,7 +249,7 @@ export class NgxUiLoaderHelperService {
242249
* @param inputName the name of the input property
243250
* @param value the direction to verify
244251
* @param defaultValue the default direction
245-
* @return a valid direction
252+
* @returns a valid direction
246253
*/
247254
validateDirection(inputName: string, value: string, defaultValue: string) {
248255
return this.validate(this.validDirections, inputName, value, defaultValue);

0 commit comments

Comments
 (0)