ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
214 lines (208 loc) • 6.85 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Renderer2, ElementRef, Input, Output, NgModule } from '@angular/core';
import { fadeMotion } from 'ng-zorro-antd/core/animation';
import { warnDeprecation } from 'ng-zorro-antd/core/logger';
import { InputBoolean } from 'ng-zorro-antd/core/util';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NzIconModule } from 'ng-zorro-antd/icon';
/**
* @fileoverview added by tsickle
* Generated from: tag.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzTagComponent {
/**
* @param {?} renderer
* @param {?} elementRef
*/
constructor(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.presetColor = false;
this.cacheClassName = null;
this.nzMode = 'default';
this.nzChecked = false;
this.nzNoAnimation = false;
this.nzAfterClose = new EventEmitter();
this.nzOnClose = new EventEmitter();
this.nzCheckedChange = new EventEmitter();
}
/**
* @private
* @param {?=} color
* @return {?}
*/
isPresetColor(color) {
if (!color) {
return false;
}
return (/^(pink|red|yellow|orange|cyan|green|blue|purple|geekblue|magenta|volcano|gold|lime)(-inverse)?$/.test(color) ||
/^(success|processing|error|default|warning)$/.test(color));
}
/**
* @private
* @return {?}
*/
updateClassMap() {
this.presetColor = this.isPresetColor(this.nzColor);
if (this.cacheClassName) {
this.renderer.removeClass(this.elementRef.nativeElement, this.cacheClassName);
}
if (this.presetColor) {
this.cacheClassName = `ant-tag-${this.nzColor}`;
this.renderer.addClass(this.elementRef.nativeElement, this.cacheClassName);
}
}
/**
* @return {?}
*/
updateCheckedStatus() {
if (this.nzMode === 'checkable') {
this.nzChecked = !this.nzChecked;
this.nzCheckedChange.emit(this.nzChecked);
this.updateClassMap();
}
}
/**
* @param {?} e
* @return {?}
*/
closeTag(e) {
this.nzOnClose.emit(e);
if (!e.defaultPrevented) {
this.renderer.removeChild(this.renderer.parentNode(this.elementRef.nativeElement), this.elementRef.nativeElement);
}
}
/**
* @param {?} e
* @return {?}
*/
afterAnimation(e) {
if (e.toState === 'void') {
this.nzAfterClose.emit();
if (this.nzAfterClose.observers.length) {
warnDeprecation(`'(nzAfterClose)' Output is going to be removed in 9.0.0. Please use '(nzOnClose)' instead.`);
}
}
}
/**
* @return {?}
*/
ngOnInit() {
this.updateClassMap();
}
/**
* @return {?}
*/
ngOnChanges() {
this.updateClassMap();
}
}
NzTagComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-tag',
exportAs: 'nzTag',
preserveWhitespaces: false,
animations: [fadeMotion],
template: `
<ng-content></ng-content>
<i nz-icon nzType="close" *ngIf="nzMode === 'closeable'" tabindex="-1" (click)="closeTag($event)"></i>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[@fadeMotion]': '',
'[@.disabled]': 'nzNoAnimation',
'[style.background-color]': 'presetColor ? null : nzColor',
'[class.ant-tag]': `true`,
'[class.ant-tag-has-color]': `nzColor && !presetColor`,
'[class.ant-tag-checkable]': `nzMode === 'checkable'`,
'[class.ant-tag-checkable-checked]': `nzChecked`,
'(click)': 'updateCheckedStatus()',
'(@fadeMotion.done)': 'afterAnimation($event)'
}
}] }
];
/** @nocollapse */
NzTagComponent.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
NzTagComponent.propDecorators = {
nzMode: [{ type: Input }],
nzColor: [{ type: Input }],
nzChecked: [{ type: Input }],
nzNoAnimation: [{ type: Input }],
nzAfterClose: [{ type: Output }],
nzOnClose: [{ type: Output }],
nzCheckedChange: [{ type: Output }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzTagComponent.prototype, "nzChecked", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzTagComponent.prototype, "nzNoAnimation", void 0);
if (false) {
/** @type {?} */
NzTagComponent.ngAcceptInputType_nzChecked;
/** @type {?} */
NzTagComponent.ngAcceptInputType_nzNoAnimation;
/** @type {?} */
NzTagComponent.prototype.presetColor;
/** @type {?} */
NzTagComponent.prototype.cacheClassName;
/** @type {?} */
NzTagComponent.prototype.nzMode;
/** @type {?} */
NzTagComponent.prototype.nzColor;
/** @type {?} */
NzTagComponent.prototype.nzChecked;
/** @type {?} */
NzTagComponent.prototype.nzNoAnimation;
/** @type {?} */
NzTagComponent.prototype.nzAfterClose;
/** @type {?} */
NzTagComponent.prototype.nzOnClose;
/** @type {?} */
NzTagComponent.prototype.nzCheckedChange;
/**
* @type {?}
* @private
*/
NzTagComponent.prototype.renderer;
/**
* @type {?}
* @private
*/
NzTagComponent.prototype.elementRef;
}
/**
* @fileoverview added by tsickle
* Generated from: tag.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzTagModule {
}
NzTagModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, FormsModule, NzIconModule],
declarations: [NzTagComponent],
exports: [NzTagComponent]
},] }
];
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-tag.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzTagComponent, NzTagModule };
//# sourceMappingURL=ng-zorro-antd-tag.js.map