Skip to content

Commit 1e8a872

Browse files
committed
feat: enhance ngx-spinner component and add print options for improved functionality and usability
1 parent b717d1d commit 1e8a872

File tree

9 files changed

+171
-27
lines changed

9 files changed

+171
-27
lines changed

angular.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"ng-kit": {
7+
"projectType": "library",
8+
"root": "projects/ng-kit",
9+
"sourceRoot": "projects/ng-kit/src",
10+
"prefix": "lib",
11+
"architect": {
12+
"build": {
13+
"builder": "@angular-devkit/build-angular:ng-packagr",
14+
"options": {
15+
"project": "projects/ng-kit/ng-package.json"
16+
},
17+
"configurations": {
18+
"production": {
19+
"tsConfig": "projects/ng-kit/tsconfig.lib.prod.json"
20+
},
21+
"development": {
22+
"tsConfig": "projects/ng-kit/tsconfig.lib.json"
23+
}
24+
},
25+
"defaultConfiguration": "production"
26+
},
27+
"lint": {
28+
"builder": "@angular-eslint/builder:lint",
29+
"options": {
30+
"lintFilePatterns": [
31+
"src/**/*.ts",
32+
"src/**/*.html"
33+
]
34+
}
35+
},
36+
"test": {
37+
"builder": "@angular-devkit/build-angular:jest",
38+
"options": {
39+
"tsConfig": "projects/ng-kit/tsconfig.spec.json",
40+
"polyfills": [
41+
"zone.js",
42+
"zone.js/testing"
43+
]
44+
}
45+
}
46+
}
47+
},
48+
"ng-kit-demo": {
49+
"projectType": "application",
50+
"schematics": {
51+
"@schematics/angular:component": {
52+
"style": "scss"
53+
}
54+
},
55+
"root": "projects/ng-kit-demo",
56+
"sourceRoot": "projects/ng-kit-demo/src",
57+
"prefix": "app",
58+
"architect": {
59+
"build": {
60+
"builder": "@angular-devkit/build-angular:application",
61+
"options": {
62+
"outputPath": "dist/ng-kit-demo",
63+
"index": "projects/ng-kit-demo/src/index.html",
64+
"browser": "projects/ng-kit-demo/src/main.ts",
65+
"polyfills": [
66+
"zone.js"
67+
],
68+
"tsConfig": "projects/ng-kit-demo/tsconfig.app.json",
69+
"inlineStyleLanguage": "scss",
70+
"assets": [
71+
"projects/ng-kit-demo/src/favicon.ico",
72+
"projects/ng-kit-demo/src/assets"
73+
],
74+
"styles": [
75+
"projects/ng-kit-demo/src/styles.scss"
76+
],
77+
"scripts": []
78+
},
79+
"configurations": {
80+
"production": {
81+
"budgets": [
82+
{
83+
"type": "initial",
84+
"maximumWarning": "1mb",
85+
"maximumError": "2mb"
86+
},
87+
{
88+
"type": "anyComponentStyle",
89+
"maximumWarning": "5kb",
90+
"maximumError": "10kb"
91+
}
92+
],
93+
"outputHashing": "all"
94+
},
95+
"development": {
96+
"optimization": false,
97+
"extractLicenses": false,
98+
"sourceMap": true
99+
}
100+
},
101+
"defaultConfiguration": "production"
102+
},
103+
"serve": {
104+
"builder": "@angular-devkit/build-angular:dev-server",
105+
"configurations": {
106+
"production": {
107+
"buildTarget": "ng-kit-demo:build:production"
108+
},
109+
"development": {
110+
"buildTarget": "ng-kit-demo:build:development"
111+
}
112+
},
113+
"defaultConfiguration": "development"
114+
},
115+
"extract-i18n": {
116+
"builder": "@angular-devkit/build-angular:extract-i18n",
117+
"options": {
118+
"buildTarget": "ng-kit-demo:build"
119+
}
120+
}
121+
}
122+
}
123+
},
124+
"cli": {
125+
"analytics": "09d8c19e-c136-407c-a909-b3593d1ceda7"
126+
}
127+
}

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = tseslint.config(
99
extends: [eslint.configs.recommended, ...tseslint.configs.recommended, ...tseslint.configs.stylistic, ...angular.configs.tsRecommended],
1010
processor: angular.processInlineTemplates,
1111
rules: {
12-
'prefer-inject-function': 'warn',
1312
'id-blacklist': ['off'],
1413
'@typescript-eslint/ban-ts-comment': ['off'],
1514
'@typescript-eslint/no-explicit-any': ['off'],

projects/ng-kit/src/lib/components/ngx-spinner/ngx-spinner.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if (spinner.show) {
22
<div
33
#overlay
4-
[@.disabled]="disableAnimation"
4+
[@.disabled]="disableAnimation()"
55
[@fadeIn]="'in'"
66
[style.background-color]="spinner.bdColor"
77
[style.position]="spinner.fullScreen ? 'fixed' : 'absolute'"
@@ -14,8 +14,8 @@
1414
}
1515
</div>
1616
}
17-
@if (template) {
18-
<div [innerHTML]="template | safeHtml"></div>
17+
@if (template()) {
18+
<div [innerHTML]="template() | safeHtml"></div>
1919
}
2020
<div [style.z-index]="spinner.zIndex" class="loading-text">
2121
<ng-content></ng-content>

projects/ng-kit/src/lib/components/ngx-spinner/ngx-spinner.component.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
5959
/**
6060
* Custom template for spinner/loader
6161
*/
62-
template = input<string | undefined>(undefined);
62+
template = input<string>('');
6363

6464
/**
6565
* Show/Hide the spinner
66-
* @type {boolean}
6766
*/
6867
showSpinner = input<boolean>(false);
6968

@@ -107,13 +106,13 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
107106
* Creates an instance of NgxSpinnerComponent.
108107
*/
109108
constructor(
110-
private spinnerService: NgxSpinnerService,
111-
private changeDetector: ChangeDetectorRef,
109+
private readonly spinnerService: NgxSpinnerService,
110+
private readonly changeDetector: ChangeDetectorRef,
112111
) {}
113112

114113
@HostListener('document:keydown', ['$event'])
115-
handleKeyboardEvent(event: KeyboardEvent) {
116-
if (this.spinnerDOM && this.spinnerDOM.nativeElement) {
114+
handleKeyboardEvent(event: KeyboardEvent): void {
115+
if (this.spinnerDOM?.nativeElement) {
117116
event.returnValue = false;
118117
event.preventDefault();
119118
}
@@ -122,7 +121,7 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
122121
/**
123122
* Initialization method
124123
*/
125-
ngOnInit() {
124+
ngOnInit(): void {
126125
this.setDefaultOptions();
127126
this.spinnerService
128127
.getSpinner(this.name())
@@ -140,7 +139,7 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
140139
/**
141140
* To set default ngx-spinner options
142141
*/
143-
setDefaultOptions = () => {
142+
setDefaultOptions = (): void => {
144143
this.spinner = new NgxSpinner({
145144
name: this.name(),
146145
bdColor: this.bdColor(),
@@ -165,7 +164,7 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
165164
this.spinner.divCount = LOADERS[type];
166165
this.spinner.divArray = Array(this.spinner.divCount)
167166
.fill(0)
168-
.map((x, i) => i);
167+
.map((_x, i) => i);
169168
let sizeClass = '';
170169
switch (size.toLowerCase()) {
171170
case 'small':
@@ -186,14 +185,14 @@ export class NgxSpinnerComponent implements OnDestroy, OnInit {
186185
/**
187186
* Check if input variables have changed
188187
*/
189-
onInputChange() {
188+
onInputChange(): void {
190189
this.spinner.class = this.getClass(this.spinner.type ?? DEFAULTS.SPINNER_TYPE, this.spinner.size ?? 'default');
191190
}
192191

193192
/**
194193
* Component destroy event
195194
*/
196-
ngOnDestroy() {
195+
ngOnDestroy(): void {
197196
this.ngUnsubscribe.next();
198197
this.ngUnsubscribe.complete();
199198
}

projects/ng-kit/src/lib/directives/ngx-print.directive.ts renamed to projects/ng-kit/src/lib/directives/ngx-print/ngx-print.directive.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Directive, HostListener, Input } from '@angular/core';
22
import { MatTableDataSource } from '@angular/material/table';
33
import { MatPaginator } from '@angular/material/paginator';
4+
import { PrintOptions } from './print-options';
45

56
/**
67
* Reusable Angular directory that prints given contents of HTML element
@@ -20,80 +21,73 @@ export class NgxPrintDirective {
2021
* @author Pavan Kumar Jadda
2122
*/
2223
@Input() printSectionId: string | undefined;
23-
2424
/**
2525
* Title of the HTML element those contents need to be printed
2626
*
2727
* @since 12.0.0
2828
* @author Pavan Kumar Jadda
2929
*/
3030
@Input() printTitle: string | undefined;
31-
3231
/**
3332
* If `true`, uses CSS of HTMl element, otherwise no CSS applied
3433
*
3534
* @since 12.0.0
3635
* @author Pavan Kumar Jadda
3736
*/
3837
@Input() useExistingCss = false;
39-
4038
/**
4139
* A delay in milliseconds to force the print dialog to wait before opened. Default: 0
4240
*
4341
* @since 12.0.0
4442
* @author Pavan Kumar Jadda
4543
*/
4644
@Input() printDelay = 0;
47-
4845
/**
4946
* Instance of the Mat Table Data Source
5047
*
5148
* @since 12.0.0
5249
* @author Pavan Kumar Jadda
5350
*/
5451
@Input() matTableDataSource!: MatTableDataSource<any>;
55-
5652
/**
5753
* Instance of the Mat Paginator
5854
*
5955
* @since 12.0.0
6056
* @author Pavan Kumar Jadda
6157
*/
6258
@Input() paginator!: MatPaginator;
63-
6459
/**
6560
* ID of the Mat Paginator
6661
*
6762
* @since 12.0.0
6863
* @author Pavan Kumar Jadda
6964
*/
7065
@Input() paginatorId = '';
71-
7266
/**
7367
* HTML tag ID of the Mat-Table Input Filter
7468
*
7569
* @since 12.0.0
7670
* @author Pavan Kumar Jadda
7771
*/
7872
@Input() inputFilterId = '';
79-
8073
/**
8174
* If `true`, referenced table is Mat-Table
8275
*
8376
* @since 12.0.0
8477
* @author Pavan Kumar Jadda
8578
*/
8679
@Input() isMatTable = false;
87-
8880
/**
8981
* If `true` Mat-Table paginator will be hidden
9082
*
9183
* @since 12.0.0
9284
* @author Pavan Kumar Jadda
9385
*/
9486
@Input() hideMatTablePaginator = false;
95-
87+
9688
public printStyleArray = [];
89+
printOptions = new PrintOptions();
90+
9791
/**
9892
* List of Style sheet files
9993
*
@@ -102,6 +96,15 @@ export class NgxPrintDirective {
10296
*/
10397
private styleSheetFileArray = '';
10498

99+
/**
100+
* Prevents the print dialog from opening on the window
101+
*
102+
* @memberof NgxPrintDirective
103+
*/
104+
@Input() set previewOnly(value: boolean) {
105+
this.printOptions = { ...this.printOptions, previewOnly: value };
106+
}
107+
105108
/**
106109
* List of CSS properties that needs to be applied while printing the document
107110
*
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class PrintOptions {
2+
printSectionId = '';
3+
printTitle = '';
4+
useExistingCss = false;
5+
bodyClass = '';
6+
openNewTab = false;
7+
previewOnly = false;
8+
closeWindow = true;
9+
printDelay = 0;
10+
11+
constructor(options?: Partial<PrintOptions>) {
12+
if (options) {
13+
Object.assign(this, options);
14+
}
15+
}
16+
}

projects/ng-kit/src/public-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export * from './lib/components/ngx-spinner/ngx-spinner.component';
99
export * from './lib/components/autocomplete/autocomplete.component';
1010

1111
// Export directives
12-
export * from './lib/directives/ngx-print.directive';
13-
export * from './lib/directives/prevent-multiple-clicks.directive';
12+
export * from './lib/directives/ngx-print/ngx-print.directive';
13+
export * from './lib/directives/prevent-multiple-clicks/prevent-multiple-clicks.directive';
1414

1515
// Export buttons
1616
export * from './lib/components/buttons/bs-link-button/bs-link-button.component';

0 commit comments

Comments
 (0)