UNPKG

ng-zorro-antd

Version:

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

174 lines (168 loc) 6.53 kB
import { __decorate, __metadata } from 'tslib'; import { ObserversModule } from '@angular/cdk/observers'; import { CommonModule } from '@angular/common'; import { ChangeDetectionStrategy, Component, ElementRef, Input, Renderer2, TemplateRef, ViewChild, ViewEncapsulation, NgModule } from '@angular/core'; import { isEmpty, zoomBadgeMotion, InputBoolean, NzAddOnModule } from 'ng-zorro-antd/core'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzBadgeComponent { /** * @param {?} renderer * @param {?} elementRef */ constructor(renderer, elementRef) { this.renderer = renderer; this.elementRef = elementRef; 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 {?} */ checkContent() { 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'); } } /** * @return {?} */ get showSup() { return (this.nzShowDot && this.nzDot) || this.count > 0 || (this.count === 0 && this.nzShowZero); } /** * @return {?} */ generateMaxNumberArray() { this.maxNumberArray = this.nzOverflowCount.toString().split(''); } /** * @return {?} */ ngOnInit() { this.generateMaxNumberArray(); } /** * @return {?} */ ngAfterViewInit() { this.checkContent(); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { const { nzOverflowCount, nzCount, nzColor } = changes; if (nzCount && !(nzCount.currentValue instanceof TemplateRef)) { this.count = Math.max(0, nzCount.currentValue); this.countArray = this.count .toString() .split('') .map((/** * @param {?} item * @return {?} */ item => +item)); } if (nzOverflowCount) { this.generateMaxNumberArray(); } if (nzColor) { this.presetColor = this.colorArray.indexOf(this.nzColor) !== -1 ? this.nzColor : null; } } } NzBadgeComponent.decorators = [ { type: Component, args: [{ selector: 'nz-badge', exportAs: 'nzBadge', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, animations: [zoomBadgeMotion], template: "<span (cdkObserveContent)=\"checkContent()\" #contentElement><ng-content></ng-content></span>\n<span class=\"ant-badge-status-dot ant-badge-status-{{nzStatus || presetColor}}\" [style.background]=\"!presetColor && nzColor\" *ngIf=\"nzStatus || nzColor\" [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]!=null)\">\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 = () => [ { type: Renderer2 }, { type: ElementRef } ]; NzBadgeComponent.propDecorators = { contentElement: [{ type: ViewChild, args: ['contentElement',] }], 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); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzBadgeModule { } NzBadgeModule.decorators = [ { type: NgModule, args: [{ declarations: [NzBadgeComponent], exports: [NzBadgeComponent], imports: [CommonModule, ObserversModule, NzAddOnModule] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzBadgeComponent, NzBadgeModule }; //# sourceMappingURL=ng-zorro-antd-badge.js.map