UNPKG

@neocomplexx/ngx-neo-loader

Version:
123 lines (116 loc) 6.44 kB
import { ɵɵdefineInjectable, ɵsetClassMetadata, Injectable, ɵɵelementStart, ɵɵnamespaceSVG, ɵɵelement, ɵɵelementEnd, ɵɵdirectiveInject, ɵɵdefineComponent, ɵɵtemplate, ɵɵproperty, Component, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core'; import { Subject, timer } from 'rxjs'; import { NgIf, CommonModule } from '@angular/common'; class NgxNeoLoaderService { constructor() { this.DELAY_TIME = 500; this.loaderSubject = new Subject(); this.loaderState = this.loaderSubject.asObservable(); } show() { const timerObs = timer(this.DELAY_TIME); // subscribing to a observable returns a subscription object const sub = timerObs.subscribe(t => this.loaderSubject.next({ showLoading: true })); this.sub = sub; return sub; // this.loaderSubject.next(<LoaderState>{showLoading: true}); } hide(sub = null) { if (!sub && this.sub) { this.sub.unsubscribe(); } else if (sub) { sub.unsubscribe(); } this.loaderSubject.next({ showLoading: false }); } } /** @nocollapse */ NgxNeoLoaderService.ɵfac = function NgxNeoLoaderService_Factory(t) { return new (t || NgxNeoLoaderService)(); }; /** @nocollapse */ NgxNeoLoaderService.ɵprov = ɵɵdefineInjectable({ token: NgxNeoLoaderService, factory: NgxNeoLoaderService.ɵfac }); /*@__PURE__*/ (function () { ɵsetClassMetadata(NgxNeoLoaderService, [{ type: Injectable }], function () { return []; }, null); })(); function LoaderComponent_div_0_Template(rf, ctx) { if (rf & 1) { ɵɵelementStart(0, "div"); ɵɵelementStart(1, "div", 1); ɵɵelementStart(2, "div"); ɵɵelementStart(3, "div", 2); ɵɵnamespaceSVG(); ɵɵelementStart(4, "svg", 3); ɵɵelement(5, "circle", 4); ɵɵelementEnd(); ɵɵelementEnd(); ɵɵelementEnd(); ɵɵelementEnd(); ɵɵelementEnd(); } } class LoaderComponent { constructor(loaderService) { this.loaderService = loaderService; this.show_loading = false; } ngOnInit() { this.subscription = this.loaderService.loaderState .subscribe((state) => { this.show_loading = state.showLoading; // if (state.showLoading == true){ // this.startLoading(); // } // if (state.showLoading == false){ // this.stopLoading(); // } }); } ngOnDestroy() { this.subscription.unsubscribe(); } } /** @nocollapse */ LoaderComponent.ɵfac = function LoaderComponent_Factory(t) { return new (t || LoaderComponent)(ɵɵdirectiveInject(NgxNeoLoaderService)); }; /** @nocollapse */ LoaderComponent.ɵcmp = ɵɵdefineComponent({ type: LoaderComponent, selectors: [["neo-app-loader"]], decls: 1, vars: 1, consts: [[4, "ngIf"], [1, "loader-container"], [1, "loader"], ["viewBox", "25 25 50 50", 1, "circular"], ["cx", "50", "cy", "50", "r", "20", "fill", "none", "stroke-width", "2", "stroke-miterlimit", "10", 1, "path"]], template: function LoaderComponent_Template(rf, ctx) { if (rf & 1) { ɵɵtemplate(0, LoaderComponent_div_0_Template, 6, 0, "div", 0); } if (rf & 2) { ɵɵproperty("ngIf", ctx.show_loading); } }, directives: [NgIf], styles: [".loader-container[_ngcontent-%COMP%]{width:100vw!important;height:100vh!important;position:fixed!important;overflow:hidden!important;display:flex!important;z-index:10000!important}.loader-container[_ngcontent-%COMP%] > div[_ngcontent-%COMP%]{margin:auto}.loader[_ngcontent-%COMP%]{position:relative;width:7rem;margin:0 auto .5rem}.loader[_ngcontent-%COMP%]:before{content:\"\";display:block;padding-top:100%}.circular[_ngcontent-%COMP%]{-webkit-animation:2s linear infinite rotate;animation:2s linear infinite rotate;height:100%;transform-origin:center center;width:100%;position:absolute;top:0;bottom:0;left:0;right:0;margin:auto}.path[_ngcontent-%COMP%]{stroke-dasharray:1,200;stroke-dashoffset:0;stroke:rgba(0,0,0,.35)!important;-webkit-animation:1.5s ease-in-out infinite dash;animation:1.5s ease-in-out infinite dash;stroke-linecap:round}@-webkit-keyframes rotate{100%{transform:rotate(360deg)}}@keyframes rotate{100%{transform:rotate(360deg)}}@-webkit-keyframes dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}@keyframes dash{0%{stroke-dasharray:1,200;stroke-dashoffset:0}50%{stroke-dasharray:89,200;stroke-dashoffset:-35px}100%{stroke-dasharray:89,200;stroke-dashoffset:-124px}}"] }); /*@__PURE__*/ (function () { ɵsetClassMetadata(LoaderComponent, [{ type: Component, args: [{ selector: 'neo-app-loader', templateUrl: 'ngx-neo-loader.component.html', styleUrls: ['ngx-neo-loader.component.scss'] }] }], function () { return [{ type: NgxNeoLoaderService }]; }, null); })(); class NgxNeoLoaderModule { static forRoot() { return { ngModule: NgxNeoLoaderModule, providers: [NgxNeoLoaderService] }; } } /** @nocollapse */ NgxNeoLoaderModule.ɵmod = ɵɵdefineNgModule({ type: NgxNeoLoaderModule }); /** @nocollapse */ NgxNeoLoaderModule.ɵinj = ɵɵdefineInjector({ factory: function NgxNeoLoaderModule_Factory(t) { return new (t || NgxNeoLoaderModule)(); }, imports: [[ CommonModule ]] }); (function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(NgxNeoLoaderModule, { declarations: [LoaderComponent], imports: [CommonModule], exports: [LoaderComponent] }); })(); /*@__PURE__*/ (function () { ɵsetClassMetadata(NgxNeoLoaderModule, [{ type: NgModule, args: [{ declarations: [ LoaderComponent ], imports: [ CommonModule ], exports: [ LoaderComponent ] }] }], null, null); })(); /* * Public API Surface of ngx-neo-loader */ /** * Generated bundle index. Do not edit. */ export { LoaderComponent, NgxNeoLoaderModule, NgxNeoLoaderService }; //# sourceMappingURL=neocomplexx-ngx-neo-loader.js.map