ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
209 lines (208 loc) • 5.57 kB
JavaScript
import { Directionality } from "@angular/cdk/bidi";
import * as i0 from "@angular/core";
import { Component, ElementRef, EventEmitter, Input, NgModule, Output, Renderer2, ViewEncapsulation, booleanAttribute, inject } from "@angular/core";
import { isPresetColor, isStatusColor, presetColors, statusColors } from "ng-zorro-antd/core/color";
import * as i1 from "ng-zorro-antd/icon";
import { NzIconModule } from "ng-zorro-antd/icon";
var NzTagComponent = class NzTagComponent {
renderer = inject(Renderer2);
el = inject(ElementRef).nativeElement;
dir = inject(Directionality).valueSignal;
nzMode = "default";
nzColor;
nzChecked = false;
nzBordered = true;
nzOnClose = new EventEmitter();
nzCheckedChange = new EventEmitter();
isPresetColor = false;
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.el), this.el);
}
clearPresetColor() {
const regexp = new RegExp(`(ant-tag-(?:${[...presetColors, ...statusColors].join("|")}))`, "g");
const classname = this.el.classList.toString();
const matches = [];
let match = regexp.exec(classname);
while (match !== null) {
matches.push(match[1]);
match = regexp.exec(classname);
}
this.el.classList.remove(...matches);
}
setPresetColor() {
this.clearPresetColor();
if (!this.nzColor) this.isPresetColor = false;
else this.isPresetColor = isPresetColor(this.nzColor) || isStatusColor(this.nzColor);
if (this.isPresetColor) this.el.classList.add(`ant-tag-${this.nzColor}`);
}
ngOnChanges(changes) {
const { nzColor } = changes;
if (nzColor) this.setPresetColor();
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.2.2",
type: NzTagComponent,
isStandalone: true,
selector: "nz-tag",
inputs: {
nzMode: "nzMode",
nzColor: "nzColor",
nzChecked: [
"nzChecked",
"nzChecked",
booleanAttribute
],
nzBordered: [
"nzBordered",
"nzBordered",
booleanAttribute
]
},
outputs: {
nzOnClose: "nzOnClose",
nzCheckedChange: "nzCheckedChange"
},
host: {
listeners: { "click": "updateCheckedStatus()" },
properties: {
"style.background-color": "isPresetColor ? '' : 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'",
"class.ant-tag-borderless": "!nzBordered"
},
classAttribute: "ant-tag"
},
exportAs: ["nzTag"],
usesOnChanges: true,
ngImport: i0,
template: `
<ng-content />
(nzMode === 'closeable') {
<nz-icon nzType="close" class="ant-tag-close-icon" tabindex="-1" (click)="closeTag($event)" />
}
`,
isInline: true,
dependencies: [{
kind: "ngmodule",
type: NzIconModule
}, {
kind: "directive",
type: i1.NzIconDirective,
selector: "nz-icon,[nz-icon]",
inputs: [
"nzType",
"nzTheme",
"nzTwotoneColor",
"nzSpin",
"nzRotate",
"nzIconfont",
"aria-label"
],
exportAs: ["nzIcon"]
}],
encapsulation: i0.ViewEncapsulation.None
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-tag",
exportAs: "nzTag",
template: `
<ng-content />
(nzMode === 'closeable') {
<nz-icon nzType="close" class="ant-tag-close-icon" tabindex="-1" (click)="closeTag($event)" />
}
`,
encapsulation: ViewEncapsulation.None,
host: {
class: "ant-tag",
"[style.background-color]": `isPresetColor ? '' : 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'`,
"[class.ant-tag-borderless]": `!nzBordered`,
"(click)": "updateCheckedStatus()"
},
imports: [NzIconModule]
}]
}],
propDecorators: {
nzMode: [{ type: Input }],
nzColor: [{ type: Input }],
nzChecked: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzBordered: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzOnClose: [{ type: Output }],
nzCheckedChange: [{ type: Output }]
}
});
var NzTagModule = class NzTagModule {
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagModule,
deps: [],
target: i0.ɵɵFactoryTarget.NgModule
});
static ɵmod = i0.ɵɵngDeclareNgModule({
minVersion: "14.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagModule,
imports: [NzTagComponent],
exports: [NzTagComponent]
});
static ɵinj = i0.ɵɵngDeclareInjector({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagModule,
imports: [NzTagComponent]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzTagModule,
decorators: [{
type: NgModule,
args: [{
imports: [NzTagComponent],
exports: [NzTagComponent]
}]
}]
});
export { NzTagComponent, NzTagModule };
//# sourceMappingURL=ng-zorro-antd-tag.mjs.map