UNPKG

ng-zorro-antd-yj

Version:

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

163 lines 13.2 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import * as tslib_1 from "tslib"; import { ChangeDetectionStrategy, Component, ElementRef, Input, Renderer2, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core'; import { zoomBadgeMotion } from '../core/animation/zoom'; import { isEmpty } from '../core/util/check'; import { InputBoolean } from '../core/util/convert'; export 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.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 } = 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(); } } } NzBadgeComponent.decorators = [ { type: Component, args: [{ selector: 'nz-badge', 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}}\" *ngIf=\"nzStatus\" [ngStyle]=\"nzStyle\"></span>\n<span class=\"ant-badge-status-text\" *ngIf=\"nzStatus\">{{ 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 }], nzStyle: [{ type: Input }], nzStatus: [{ type: Input }], nzCount: [{ type: Input }] }; tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzShowZero", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzShowDot", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzBadgeComponent.prototype, "nzDot", void 0); if (false) { /** @type {?} */ NzBadgeComponent.prototype.maxNumberArray; /** @type {?} */ NzBadgeComponent.prototype.countArray; /** @type {?} */ NzBadgeComponent.prototype.countSingleArray; /** @type {?} */ NzBadgeComponent.prototype.count; /** @type {?} */ NzBadgeComponent.prototype.contentElement; /** @type {?} */ NzBadgeComponent.prototype.nzShowZero; /** @type {?} */ NzBadgeComponent.prototype.nzShowDot; /** @type {?} */ NzBadgeComponent.prototype.nzDot; /** @type {?} */ NzBadgeComponent.prototype.nzOverflowCount; /** @type {?} */ NzBadgeComponent.prototype.nzText; /** @type {?} */ NzBadgeComponent.prototype.nzStyle; /** @type {?} */ NzBadgeComponent.prototype.nzStatus; /** @type {?} */ NzBadgeComponent.prototype.nzCount; /** * @type {?} * @private */ NzBadgeComponent.prototype.renderer; /** * @type {?} * @private */ NzBadgeComponent.prototype.elementRef; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnotYmFkZ2UuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6Im5nOi8vbmctem9ycm8tYW50ZC15ai8iLCJzb3VyY2VzIjpbImJhZGdlL256LWJhZGdlLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLE9BQU8sRUFFTCx1QkFBdUIsRUFDdkIsU0FBUyxFQUNULFVBQVUsRUFDVixLQUFLLEVBR0wsU0FBUyxFQUVULFdBQVcsRUFDWCxTQUFTLEVBQ1QsaUJBQWlCLEVBQ2xCLE1BQU0sZUFBZSxDQUFDO0FBQ3ZCLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUN6RCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDN0MsT0FBTyxFQUFFLFlBQVks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