UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

190 lines (184 loc) 8.4 kB
import { __decorate } from 'tslib'; import * as i0 from '@angular/core'; import { Component, ViewEncapsulation, Optional, Input, NgModule } from '@angular/core'; import { Subject, BehaviorSubject, ReplaySubject, timer } from 'rxjs'; import { startWith, distinctUntilChanged, switchMap, debounce, takeUntil } from 'rxjs/operators'; import * as i1 from 'ng-zorro-antd/core/config'; import { WithConfig } from 'ng-zorro-antd/core/config'; import { InputNumber, InputBoolean } from 'ng-zorro-antd/core/util'; import * as i2 from '@angular/cdk/bidi'; import { BidiModule } from '@angular/cdk/bidi'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import { ObserversModule } from '@angular/cdk/observers'; const NZ_CONFIG_MODULE_NAME = 'spin'; class NzSpinComponent { constructor(nzConfigService, cdr, directionality) { this.nzConfigService = nzConfigService; this.cdr = cdr; this.directionality = directionality; this._nzModuleName = NZ_CONFIG_MODULE_NAME; this.nzIndicator = null; this.nzSize = 'default'; this.nzTip = null; this.nzDelay = 0; this.nzSimple = false; this.nzSpinning = true; this.destroy$ = new Subject(); this.spinning$ = new BehaviorSubject(this.nzSpinning); this.delay$ = new ReplaySubject(1); this.isLoading = false; this.dir = 'ltr'; } ngOnInit() { const loading$ = this.delay$.pipe(startWith(this.nzDelay), distinctUntilChanged(), switchMap(delay => { if (delay === 0) { return this.spinning$; } return this.spinning$.pipe(debounce(spinning => timer(spinning ? delay : 0))); }), takeUntil(this.destroy$)); loading$.subscribe(loading => { this.isLoading = loading; this.cdr.markForCheck(); }); this.nzConfigService .getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME) .pipe(takeUntil(this.destroy$)) .subscribe(() => this.cdr.markForCheck()); this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => { this.dir = direction; this.cdr.detectChanges(); }); this.dir = this.directionality.value; } ngOnChanges(changes) { const { nzSpinning, nzDelay } = changes; if (nzSpinning) { this.spinning$.next(this.nzSpinning); } if (nzDelay) { this.delay$.next(this.nzDelay); } } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzSpinComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinComponent, deps: [{ token: i1.NzConfigService }, { token: i0.ChangeDetectorRef }, { token: i2.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Component }); NzSpinComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzSpinComponent, selector: "nz-spin", inputs: { nzIndicator: "nzIndicator", nzSize: "nzSize", nzTip: "nzTip", nzDelay: "nzDelay", nzSimple: "nzSimple", nzSpinning: "nzSpinning" }, host: { properties: { "class.ant-spin-nested-loading": "!nzSimple" } }, exportAs: ["nzSpin"], usesOnChanges: true, ngImport: i0, template: ` <ng-template #defaultTemplate> <span class="ant-spin-dot ant-spin-dot-spin"> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> </span> </ng-template> <div *ngIf="isLoading"> <div class="ant-spin" [class.ant-spin-rtl]="dir === 'rtl'" [class.ant-spin-spinning]="isLoading" [class.ant-spin-lg]="nzSize === 'large'" [class.ant-spin-sm]="nzSize === 'small'" [class.ant-spin-show-text]="nzTip" > <ng-template [ngTemplateOutlet]="nzIndicator || defaultTemplate"></ng-template> <div class="ant-spin-text" *ngIf="nzTip">{{ nzTip }}</div> </div> </div> <div *ngIf="!nzSimple" class="ant-spin-container" [class.ant-spin-blur]="isLoading"> <ng-content></ng-content> </div> `, isInline: true, directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], encapsulation: i0.ViewEncapsulation.None }); __decorate([ WithConfig() ], NzSpinComponent.prototype, "nzIndicator", void 0); __decorate([ InputNumber() ], NzSpinComponent.prototype, "nzDelay", void 0); __decorate([ InputBoolean() ], NzSpinComponent.prototype, "nzSimple", void 0); __decorate([ InputBoolean() ], NzSpinComponent.prototype, "nzSpinning", void 0); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinComponent, decorators: [{ type: Component, args: [{ selector: 'nz-spin', exportAs: 'nzSpin', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, template: ` <ng-template #defaultTemplate> <span class="ant-spin-dot ant-spin-dot-spin"> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> <i class="ant-spin-dot-item"></i> </span> </ng-template> <div *ngIf="isLoading"> <div class="ant-spin" [class.ant-spin-rtl]="dir === 'rtl'" [class.ant-spin-spinning]="isLoading" [class.ant-spin-lg]="nzSize === 'large'" [class.ant-spin-sm]="nzSize === 'small'" [class.ant-spin-show-text]="nzTip" > <ng-template [ngTemplateOutlet]="nzIndicator || defaultTemplate"></ng-template> <div class="ant-spin-text" *ngIf="nzTip">{{ nzTip }}</div> </div> </div> <div *ngIf="!nzSimple" class="ant-spin-container" [class.ant-spin-blur]="isLoading"> <ng-content></ng-content> </div> `, host: { '[class.ant-spin-nested-loading]': '!nzSimple' } }] }], ctorParameters: function () { return [{ type: i1.NzConfigService }, { type: i0.ChangeDetectorRef }, { type: i2.Directionality, decorators: [{ type: Optional }] }]; }, propDecorators: { nzIndicator: [{ type: Input }], nzSize: [{ type: Input }], nzTip: [{ type: Input }], nzDelay: [{ type: Input }], nzSimple: [{ type: Input }], nzSpinning: [{ type: Input }] } }); /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ class NzSpinModule { } NzSpinModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); NzSpinModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinModule, declarations: [NzSpinComponent], imports: [BidiModule, CommonModule, ObserversModule], exports: [NzSpinComponent] }); NzSpinModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinModule, imports: [[BidiModule, CommonModule, ObserversModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzSpinModule, decorators: [{ type: NgModule, args: [{ exports: [NzSpinComponent], declarations: [NzSpinComponent], imports: [BidiModule, CommonModule, ObserversModule] }] }] }); /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ /** * Generated bundle index. Do not edit. */ export { NzSpinComponent, NzSpinModule }; //# sourceMappingURL=ng-zorro-antd-spin.mjs.map