UNPKG

ng-zorro-antd

Version:

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

133 lines (127 loc) 4.94 kB
import { __decorate, __metadata } from 'tslib'; import { Directionality, BidiModule } from '@angular/cdk/bidi'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Renderer2, ElementRef, Optional, Input, Output, NgModule } from '@angular/core'; import { isPresetColor } from 'ng-zorro-antd/core/color'; import { InputBoolean } from 'ng-zorro-antd/core/util'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { NzIconModule } from 'ng-zorro-antd/icon'; /** * 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 NzTagComponent { constructor(cdr, renderer, elementRef, directionality) { this.cdr = cdr; this.renderer = renderer; this.elementRef = elementRef; this.directionality = directionality; this.isPresetColor = false; this.nzMode = 'default'; this.nzChecked = false; this.nzOnClose = new EventEmitter(); this.nzCheckedChange = new EventEmitter(); this.dir = 'ltr'; this.destroy$ = new Subject(); // TODO: move to host after View Engine deprecation this.elementRef.nativeElement.classList.add('ant-tag'); } updateCheckedStatus() { if (this.nzMode === 'checkable') { this.nzChecked = !this.nzChecked; this.nzCheckedChange.emit(this.nzChecked); } } closeTag(e) { this.nzOnClose.emit(e); if (!e.defaultPrevented) { this.renderer.removeChild(this.renderer.parentNode(this.elementRef.nativeElement), this.elementRef.nativeElement); } } ngOnInit() { var _a; (_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(takeUntil(this.destroy$)).subscribe((direction) => { this.dir = direction; this.cdr.detectChanges(); }); this.dir = this.directionality.value; } ngOnChanges(changes) { const { nzColor } = changes; if (nzColor) { if (!this.nzColor) { this.isPresetColor = false; } else { this.isPresetColor = isPresetColor(this.nzColor) || /^(success|processing|error|default|warning)$/.test(this.nzColor); } } } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzTagComponent.decorators = [ { type: Component, args: [{ selector: 'nz-tag', exportAs: 'nzTag', preserveWhitespaces: false, template: ` <ng-content></ng-content> <i nz-icon nzType="close" class="ant-tag-close-icon" *ngIf="nzMode === 'closeable'" tabindex="-1" (click)="closeTag($event)"></i> `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { '[style.background-color]': `isPresetColor ? '' : nzColor`, '[class]': `isPresetColor ? ('ant-tag-' + nzColor) : ''`, '[class.ant-tag-has-color]': `nzColor && !isPresetColor`, '[class.ant-tag-checkable]': `nzMode === 'checkable'`, '[class.ant-tag-checkable-checked]': `nzChecked`, '[class.ant-tag-rtl]': `dir === 'rtl'`, '(click)': 'updateCheckedStatus()' } },] } ]; NzTagComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: Renderer2 }, { type: ElementRef }, { type: Directionality, decorators: [{ type: Optional }] } ]; NzTagComponent.propDecorators = { nzMode: [{ type: Input }], nzColor: [{ type: Input }], nzChecked: [{ type: Input }], nzOnClose: [{ type: Output }], nzCheckedChange: [{ type: Output }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzTagComponent.prototype, "nzChecked", void 0); /** * 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 NzTagModule { } NzTagModule.decorators = [ { type: NgModule, args: [{ imports: [BidiModule, CommonModule, FormsModule, NzIconModule], declarations: [NzTagComponent], exports: [NzTagComponent] },] } ]; /** * 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 { NzTagComponent, NzTagModule }; //# sourceMappingURL=ng-zorro-antd-tag.js.map