Skip to content

Commit cf6fd70

Browse files
committed
Make the opacity configurable
1 parent 707cc55 commit cf6fd70

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22

33
## v5.1.0
4-
- This release introduces the **backdrop** option (`true` by default). If set to `false`, the spinner background elements will remain clickable, without any background color.
4+
- This release introduces 2 new options:
5+
- **backdrop** (`true` by default): If set to `false`, the spinner background elements will remain clickable, without any background color.
6+
- **opacity**: This option lets you override the spinner opacity (0.7 by default).
57

68
## v5.0.1
79
- The `rxjs` `peerDependency` has been relaxed from `~6.3.3` to `^6.3.3` so that no warning is thrown when the `rxjs` version has been bumped at application side.

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,28 @@ In your app.component.html, simply add:
8080

8181
## Customizing the spinner
8282

83-
You can customize the **background-color**, the **spinner type**, the spinner **backdrop** (visible by default), the **debounce delay** (ie. after how many milliseconds the spinner will be visible, if needed), the **minimum duration** (ie. how many milliseconds should the spinner be visible at least), the **extra duration** (ie. how many extra milliseconds should the spinner be visible):
83+
You can customize the following parameters:
84+
- The spinner **backdrop** (visible by default).
85+
- The **background-color** (ie. the color of the spinner itself).
86+
- The **debounce delay** (ie. after how many milliseconds the spinner will be visible, if needed).
87+
- The **extra duration** (ie. how many extra milliseconds should the spinner be visible).
88+
- The **minimum duration** (ie. how many milliseconds should the spinner be visible at least).
89+
- The spinner **opacity**.
90+
- The **spinner type**.
91+
8492
```xml
8593
<ng-http-loader
86-
[backgroundColor]="'#ff0000'"
87-
[spinner]="spinkit.skWave"
8894
[backdrop]="false"
95+
[backgroundColor]="'#ff0000'"
8996
[debounceDelay]="100"
97+
[extraDuration]="300"
9098
[minDuration]="300"
91-
[extraDuration]="300">
99+
[opacity]=".6"
100+
[spinner]="spinkit.skWave">
92101
</ng-http-loader>
93102
```
94103

95-
**_To use this syntax, you must reference the `Spinkit` const as a public property in your app.component.ts_**:
104+
**_To specify the spinner type this way, you must reference the `Spinkit` const as a public property in your app.component.ts_**:
96105

97106
```typescript
98107
import { Spinkit } from 'ng-http-loader'; // <============

src/lib/components/_variables.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ $spinkit-spinner-margin: auto !default;
22
$spinkit-size: 40px !default;
33
$spinkit-top: 50% !default;
44
$spinkit-position: relative !default;
5+
$spinkit-background-color: #333 !default;
56

6-
$spinner-background-color: #f1f1f1 !default;
7-
$spinner-opacity: .7 !default;
8-
$colored-background-color: #333 !default;
7+
$backdrop-background-color: #f1f1f1 !default;

src/lib/components/ng-http-loader.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div id="spinner" [class.backdrop]="backdrop" *ngIf="isVisible$ | async">
1+
<div id="spinner"
2+
*ngIf="isVisible$ | async"
3+
[class.backdrop]="backdrop"
4+
[style.opacity]="opacity">
25

36
<ng-container *ngComponentOutlet="entryComponent"></ng-container>
47

src/lib/components/ng-http-loader.component.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
transform: translate(-50%, -50%);
77
position: fixed;
88
z-index: 9999;
9-
opacity: $spinner-opacity;
109

1110
&.backdrop {
1211
top: 0;
1312
left: 0;
1413
height: 100%;
1514
width: 100%;
16-
background-color: $spinner-background-color;
15+
background-color: $backdrop-background-color;
1716
display: flex;
1817
align-items: center;
1918
justify-content: center;
@@ -22,5 +21,5 @@
2221
}
2322

2423
::ng-deep .colored-parent, ::ng-deep .colored > div {
25-
background-color: $colored-background-color;
24+
background-color: $spinkit-background-color;
2625
}

src/lib/components/ng-http-loader.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class NgHttpLoaderComponent implements OnDestroy, OnInit {
3434
@Input() public filteredMethods: string[] = [];
3535
@Input() public filteredUrlPatterns: string[] = [];
3636
@Input() public minDuration = 0;
37+
@Input() public opacity = '.7';
3738
@Input() public spinner = Spinkit.skWave;
3839

3940
constructor(private pendingRequestsInterceptor: PendingRequestsInterceptor, private spinnerVisibility: SpinnerVisibilityService) {

src/test/components/ng-http-loader.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,4 +878,31 @@ describe('NgHttpLoaderComponent', () => {
878878

879879
expect(element).toBeNull();
880880
});
881+
882+
it('should have a default opacity', () => {
883+
spyOnProperty(component, 'isVisible$')
884+
.and.returnValue(new BehaviorSubject(true).asObservable());
885+
fixture.detectChanges();
886+
887+
const element: HTMLElement = fixture
888+
.debugElement
889+
.query(By.css('#spinner'))
890+
.nativeElement;
891+
892+
expect(element.style.opacity).toBe('0.7');
893+
});
894+
895+
it('should be possible to override opacity', () => {
896+
spyOnProperty(component, 'isVisible$')
897+
.and.returnValue(new BehaviorSubject(true).asObservable());
898+
component.opacity = '.3';
899+
fixture.detectChanges();
900+
901+
const element: HTMLElement = fixture
902+
.debugElement
903+
.query(By.css('#spinner'))
904+
.nativeElement;
905+
906+
expect(element.style.opacity).toBe(`0${component.opacity}`);
907+
});
881908
});

0 commit comments

Comments
 (0)