UNPKG

ng-zorro-antd

Version:

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

208 lines (204 loc) 7.89 kB
import { __decorate, __metadata } from 'tslib'; import { ContentObserver, ObserversModule } from '@angular/cdk/observers'; import { TemplateRef, Component, ViewEncapsulation, ChangeDetectionStrategy, Renderer2, ElementRef, ViewChild, Input, NgModule } from '@angular/core'; import { isEmpty, zoomBadgeMotion, InputBoolean, NzAddOnModule } from 'ng-zorro-antd/core'; import { Subject } from 'rxjs'; import { startWith, takeUntil } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzBadgeComponent = /** @class */ (function () { function NzBadgeComponent(renderer, elementRef, contentObserver) { this.renderer = renderer; this.elementRef = elementRef; this.contentObserver = contentObserver; this.destroy$ = new Subject(); this.maxNumberArray = []; this.countArray = []; this.countSingleArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; this.colorArray = [ 'pink', 'red', 'yellow', 'orange', 'cyan', 'green', 'blue', 'purple', 'geekblue', 'magenta', 'volcano', 'gold', 'lime' ]; this.presetColor = null; this.nzShowZero = false; this.nzShowDot = true; this.nzDot = false; this.nzOverflowCount = 99; renderer.addClass(elementRef.nativeElement, 'ant-badge'); } /** * @return {?} */ NzBadgeComponent.prototype.checkContent = /** * @return {?} */ function () { if (isEmpty(this.contentElement.nativeElement)) { this.renderer.addClass(this.elementRef.nativeElement, 'ant-badge-not-a-wrapper'); } else { this.renderer.removeClass(this.elementRef.nativeElement, 'ant-badge-not-a-wrapper'); } }; Object.defineProperty(NzBadgeComponent.prototype, "showSup", { get: /** * @return {?} */ function () { return (this.nzShowDot && this.nzDot) || this.count > 0 || (this.count === 0 && this.nzShowZero); }, enumerable: true, configurable: true }); /** * @return {?} */ NzBadgeComponent.prototype.generateMaxNumberArray = /** * @return {?} */ function () { this.maxNumberArray = this.nzOverflowCount.toString().split(''); }; /** * @return {?} */ NzBadgeComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.generateMaxNumberArray(); }; /** * @return {?} */ NzBadgeComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; this.contentObserver .observe(this.contentElement) .pipe(startWith(true), takeUntil(this.destroy$)) .subscribe((/** * @return {?} */ function () { _this.checkContent(); })); }; /** * @param {?} changes * @return {?} */ NzBadgeComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { var nzOverflowCount = changes.nzOverflowCount, nzCount = changes.nzCount, nzColor = changes.nzColor; if (nzCount && !(nzCount.currentValue instanceof TemplateRef)) { this.count = Math.max(0, nzCount.currentValue); this.countArray = this.count .toString() .split('') .map((/** * @param {?} item * @return {?} */ function (item) { return +item; })); } if (nzOverflowCount) { this.generateMaxNumberArray(); } if (nzColor) { this.presetColor = this.colorArray.indexOf(this.nzColor) !== -1 ? this.nzColor : null; } }; /** * @return {?} */ NzBadgeComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroy$.next(); this.destroy$.complete(); }; NzBadgeComponent.decorators = [ { type: Component, args: [{ selector: 'nz-badge', exportAs: 'nzBadge', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, animations: [zoomBadgeMotion], template: "<span #contentElement><ng-content></ng-content></span>\n<span class=\"ant-badge-status-dot ant-badge-status-{{nzStatus || presetColor}}\"\n [style.background]=\"!presetColor && nzColor\"\n *ngIf=\"nzStatus || nzColor\"\n [ngStyle]=\"nzStyle\"></span>\n<span class=\"ant-badge-status-text\" *ngIf=\"nzStatus || nzColor\">{{ nzText }}</span>\n<ng-container *nzStringTemplateOutlet=\"nzCount\">\n <sup class=\"ant-scroll-number\"\n *ngIf=\"showSup\"\n @zoomBadgeMotion\n [ngStyle]=\"nzStyle\"\n [class.ant-badge-count]=\"!nzDot\"\n [class.ant-badge-dot]=\"nzDot\"\n [class.ant-badge-multiple-words]=\"countArray.length>=2\">\n <ng-container *ngFor=\"let n of maxNumberArray;let i = index;\">\n <span class=\"ant-scroll-number-only\"\n *ngIf=\"count <= nzOverflowCount\"\n [style.transform]=\"'translateY(' + (-countArray[i] * 100) + '%)'\">\n <ng-container *ngIf=\"!nzDot && countArray[i] !== undefined\">\n <p *ngFor=\"let p of countSingleArray\" [class.current]=\"p === countArray[i]\">{{ p }}</p>\n </ng-container>\n </span>\n </ng-container>\n <ng-container *ngIf=\"count > nzOverflowCount\">{{ nzOverflowCount }}+</ng-container>\n </sup>\n</ng-container>", host: { '[class.ant-badge-status]': 'nzStatus' } }] } ]; /** @nocollapse */ NzBadgeComponent.ctorParameters = function () { return [ { type: Renderer2 }, { type: ElementRef }, { type: ContentObserver } ]; }; NzBadgeComponent.propDecorators = { contentElement: [{ type: ViewChild, args: ['contentElement', { static: false },] }], nzShowZero: [{ type: Input }], nzShowDot: [{ type: Input }], nzDot: [{ type: Input }], nzOverflowCount: [{ type: Input }], nzText: [{ type: Input }], nzColor: [{ type: Input }], nzStyle: [{ type: Input }], nzStatus: [{ type: Input }], nzCount: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzShowZero", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzShowDot", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzDot", void 0); return NzBadgeComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzBadgeModule = /** @class */ (function () { function NzBadgeModule() { } NzBadgeModule.decorators = [ { type: NgModule, args: [{ declarations: [NzBadgeComponent], exports: [NzBadgeComponent], imports: [CommonModule, ObserversModule, NzAddOnModule] },] } ]; return NzBadgeModule; }()); export { NzBadgeComponent, NzBadgeModule }; //# sourceMappingURL=ng-zorro-antd-badge.js.map