ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
430 lines (421 loc) • 20.3 kB
JavaScript
import { __decorate } from 'tslib';
import { NgStyle } from '@angular/common';
import * as i0 from '@angular/core';
import { numberAttribute, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, inject, booleanAttribute, NgModule } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { zoomBadgeMotion } from 'ng-zorro-antd/core/animation';
import * as i1 from 'ng-zorro-antd/core/config';
import { WithConfig } from 'ng-zorro-antd/core/config';
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
import * as i3 from 'ng-zorro-antd/core/outlet';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import * as i2 from '@angular/cdk/bidi';
/**
* 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 NzBadgeSupComponent {
constructor() {
this.nzStyle = null;
this.nzDot = false;
this.nzOverflowCount = 99;
this.disableAnimation = false;
this.noAnimation = false;
this.nzSize = 'default';
this.maxNumberArray = [];
this.countArray = [];
this.count = 0;
this.countSingleArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
}
generateMaxNumberArray() {
this.maxNumberArray = this.nzOverflowCount.toString().split('');
}
ngOnInit() {
this.generateMaxNumberArray();
}
ngOnChanges(changes) {
const { nzOverflowCount, nzCount } = changes;
if (nzCount && typeof nzCount.currentValue === 'number') {
this.count = Math.max(0, nzCount.currentValue);
this.countArray = this.count
.toString()
.split('')
.map(item => +item);
}
if (nzOverflowCount) {
this.generateMaxNumberArray();
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeSupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.1.2", type: NzBadgeSupComponent, isStandalone: true, selector: "nz-badge-sup", inputs: { nzOffset: "nzOffset", nzTitle: "nzTitle", nzStyle: "nzStyle", nzDot: "nzDot", nzOverflowCount: ["nzOverflowCount", "nzOverflowCount", numberAttribute], disableAnimation: "disableAnimation", nzCount: "nzCount", noAnimation: "noAnimation", nzSize: "nzSize" }, host: { properties: { "@.disabled": "disableAnimation", "@zoomBadgeMotion": "", "attr.title": "nzTitle === null ? '' : nzTitle || nzCount", "style": "nzStyle", "style.right.px": "nzOffset && nzOffset[0] ? -nzOffset[0] : null", "style.margin-top.px": "nzOffset && nzOffset[1] ? nzOffset[1] : null", "class.ant-badge-count": "!nzDot", "class.ant-badge-count-sm": "nzSize === 'small'", "class.ant-badge-dot": "nzDot", "class.ant-badge-multiple-words": "countArray.length >= 2" }, classAttribute: "ant-scroll-number" }, exportAs: ["nzBadgeSup"], usesOnChanges: true, ngImport: i0, template: `
(count <= nzOverflowCount) {
(n of maxNumberArray; track n; let i = $index) {
<span
[nzNoAnimation]="noAnimation"
class="ant-scroll-number-only"
[style.transform]="'translateY(' + -countArray[i] * 100 + '%)'"
>
(!nzDot && countArray[i] !== undefined) {
(p of countSingleArray; track p) {
<p class="ant-scroll-number-only-unit" [class.current]="p === countArray[i]">
{{ p }}
</p>
}
}
</span>
}
} {
{{ nzOverflowCount }}+
}
`, isInline: true, dependencies: [{ kind: "directive", type: NzNoAnimationDirective, selector: "[nzNoAnimation]", inputs: ["nzNoAnimation"], exportAs: ["nzNoAnimation"] }], animations: [zoomBadgeMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeSupComponent, decorators: [{
type: Component,
args: [{
selector: 'nz-badge-sup',
exportAs: 'nzBadgeSup',
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [zoomBadgeMotion],
standalone: true,
imports: [NzNoAnimationDirective],
template: `
(count <= nzOverflowCount) {
(n of maxNumberArray; track n; let i = $index) {
<span
[nzNoAnimation]="noAnimation"
class="ant-scroll-number-only"
[style.transform]="'translateY(' + -countArray[i] * 100 + '%)'"
>
(!nzDot && countArray[i] !== undefined) {
(p of countSingleArray; track p) {
<p class="ant-scroll-number-only-unit" [class.current]="p === countArray[i]">
{{ p }}
</p>
}
}
</span>
}
} {
{{ nzOverflowCount }}+
}
`,
host: {
class: 'ant-scroll-number',
'[@.disabled]': `disableAnimation`,
'[@zoomBadgeMotion]': '',
'[attr.title]': `nzTitle === null ? '' : nzTitle || nzCount`,
'[style]': `nzStyle`,
'[style.right.px]': `nzOffset && nzOffset[0] ? -nzOffset[0] : null`,
'[style.margin-top.px]': `nzOffset && nzOffset[1] ? nzOffset[1] : null`,
'[class.ant-badge-count]': `!nzDot`,
'[class.ant-badge-count-sm]': `nzSize === 'small'`,
'[class.ant-badge-dot]': `nzDot`,
'[class.ant-badge-multiple-words]': `countArray.length >= 2`
}
}]
}], ctorParameters: () => [], propDecorators: { nzOffset: [{
type: Input
}], nzTitle: [{
type: Input
}], nzStyle: [{
type: Input
}], nzDot: [{
type: Input
}], nzOverflowCount: [{
type: Input,
args: [{ transform: numberAttribute }]
}], disableAnimation: [{
type: Input
}], nzCount: [{
type: Input
}], noAnimation: [{
type: Input
}], nzSize: [{
type: Input
}] } });
/**
* 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
*/
const badgePresetColors = [
'pink',
'red',
'yellow',
'orange',
'cyan',
'green',
'blue',
'purple',
'geekblue',
'magenta',
'volcano',
'gold',
'lime'
];
const NZ_CONFIG_MODULE_NAME = 'badge';
class NzBadgeComponent {
constructor(nzConfigService, renderer, cdr, elementRef, directionality) {
this.nzConfigService = nzConfigService;
this.renderer = renderer;
this.cdr = cdr;
this.elementRef = elementRef;
this.directionality = directionality;
this._nzModuleName = NZ_CONFIG_MODULE_NAME;
this.showSup = false;
this.presetColor = null;
this.dir = 'ltr';
this.destroy$ = new Subject();
this.nzShowZero = false;
this.nzShowDot = true;
this.nzStandalone = false;
this.nzDot = false;
this.nzOverflowCount = 99;
this.nzColor = undefined;
this.nzStyle = null;
this.nzText = null;
this.nzSize = 'default';
this.noAnimation = inject(NzNoAnimationDirective, { host: true, optional: true });
}
ngOnInit() {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
this.dir = direction;
this.prepareBadgeForRtl();
this.cdr.detectChanges();
});
this.dir = this.directionality.value;
this.prepareBadgeForRtl();
}
ngOnChanges(changes) {
const { nzColor, nzShowDot, nzDot, nzCount, nzShowZero } = changes;
if (nzColor) {
this.presetColor = this.nzColor && badgePresetColors.indexOf(this.nzColor) !== -1 ? this.nzColor : null;
}
if (nzShowDot || nzDot || nzCount || nzShowZero) {
this.showSup =
(this.nzShowDot && this.nzDot) ||
(typeof this.nzCount === 'number' && this.nzCount > 0) ||
(typeof this.nzCount === 'number' && this.nzCount <= 0 && this.nzShowZero);
}
}
prepareBadgeForRtl() {
if (this.isRtlLayout) {
this.renderer.addClass(this.elementRef.nativeElement, 'ant-badge-rtl');
}
else {
this.renderer.removeClass(this.elementRef.nativeElement, 'ant-badge-rtl');
}
}
get isRtlLayout() {
return this.dir === 'rtl';
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeComponent, deps: [{ token: i1.NzConfigService }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i2.Directionality }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.1.2", type: NzBadgeComponent, isStandalone: true, selector: "nz-badge", inputs: { nzShowZero: ["nzShowZero", "nzShowZero", booleanAttribute], nzShowDot: ["nzShowDot", "nzShowDot", booleanAttribute], nzStandalone: ["nzStandalone", "nzStandalone", booleanAttribute], nzDot: ["nzDot", "nzDot", booleanAttribute], nzOverflowCount: "nzOverflowCount", nzColor: "nzColor", nzStyle: "nzStyle", nzText: "nzText", nzTitle: "nzTitle", nzStatus: "nzStatus", nzCount: "nzCount", nzOffset: "nzOffset", nzSize: "nzSize" }, host: { properties: { "class.ant-badge-status": "nzStatus", "class.ant-badge-not-a-wrapper": "!!(nzStandalone || nzStatus || nzColor)" }, classAttribute: "ant-badge" }, exportAs: ["nzBadge"], usesOnChanges: true, ngImport: i0, template: `
(nzStatus || nzColor) {
<span
class="ant-badge-status-dot ant-badge-status-{{ nzStatus || presetColor }}"
[style.background]="!presetColor && nzColor"
[ngStyle]="nzStyle"
></span>
<span class="ant-badge-status-text">
<ng-container *nzStringTemplateOutlet="nzText">{{ nzText }}</ng-container>
</span>
}
<ng-content />
<ng-container *nzStringTemplateOutlet="nzCount">
(showSup) {
<nz-badge-sup
[nzOffset]="nzOffset"
[nzSize]="nzSize"
[nzTitle]="nzTitle"
[nzStyle]="nzStyle"
[nzDot]="nzDot"
[nzOverflowCount]="nzOverflowCount"
[disableAnimation]="!!(nzStandalone || nzStatus || nzColor || noAnimation?.nzNoAnimation)"
[nzCount]="nzCount"
[noAnimation]="!!noAnimation?.nzNoAnimation"
/>
}
</ng-container>
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: NzBadgeSupComponent, selector: "nz-badge-sup", inputs: ["nzOffset", "nzTitle", "nzStyle", "nzDot", "nzOverflowCount", "disableAnimation", "nzCount", "noAnimation", "nzSize"], exportAs: ["nzBadgeSup"] }, { kind: "ngmodule", type: NzOutletModule }, { kind: "directive", type: i3.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], animations: [zoomBadgeMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
__decorate([
WithConfig()
], NzBadgeComponent.prototype, "nzOverflowCount", void 0);
__decorate([
WithConfig()
], NzBadgeComponent.prototype, "nzColor", void 0);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeComponent, decorators: [{
type: Component,
args: [{
selector: 'nz-badge',
exportAs: 'nzBadge',
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [zoomBadgeMotion],
standalone: true,
imports: [NgStyle, NzBadgeSupComponent, NzOutletModule],
template: `
(nzStatus || nzColor) {
<span
class="ant-badge-status-dot ant-badge-status-{{ nzStatus || presetColor }}"
[style.background]="!presetColor && nzColor"
[ngStyle]="nzStyle"
></span>
<span class="ant-badge-status-text">
<ng-container *nzStringTemplateOutlet="nzText">{{ nzText }}</ng-container>
</span>
}
<ng-content />
<ng-container *nzStringTemplateOutlet="nzCount">
(showSup) {
<nz-badge-sup
[nzOffset]="nzOffset"
[nzSize]="nzSize"
[nzTitle]="nzTitle"
[nzStyle]="nzStyle"
[nzDot]="nzDot"
[nzOverflowCount]="nzOverflowCount"
[disableAnimation]="!!(nzStandalone || nzStatus || nzColor || noAnimation?.nzNoAnimation)"
[nzCount]="nzCount"
[noAnimation]="!!noAnimation?.nzNoAnimation"
/>
}
</ng-container>
`,
host: {
class: 'ant-badge',
'[class.ant-badge-status]': 'nzStatus',
'[class.ant-badge-not-a-wrapper]': '!!(nzStandalone || nzStatus || nzColor)'
}
}]
}], ctorParameters: () => [{ type: i1.NzConfigService }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i2.Directionality }], propDecorators: { nzShowZero: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], nzShowDot: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], nzStandalone: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], nzDot: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], nzOverflowCount: [{
type: Input
}], nzColor: [{
type: Input
}], nzStyle: [{
type: Input
}], nzText: [{
type: Input
}], nzTitle: [{
type: Input
}], nzStatus: [{
type: Input
}], nzCount: [{
type: Input
}], nzOffset: [{
type: Input
}], nzSize: [{
type: Input
}] } });
/**
* 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 NzRibbonComponent {
constructor() {
this.nzPlacement = 'end';
this.nzText = null;
this.presetColor = null;
}
ngOnChanges(changes) {
const { nzColor } = changes;
if (nzColor) {
this.presetColor = this.nzColor && badgePresetColors.indexOf(this.nzColor) !== -1 ? this.nzColor : null;
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzRibbonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.1.2", type: NzRibbonComponent, isStandalone: true, selector: "nz-ribbon", inputs: { nzColor: "nzColor", nzPlacement: "nzPlacement", nzText: "nzText" }, host: { classAttribute: "ant-ribbon-wrapper" }, exportAs: ["nzRibbon"], usesOnChanges: true, ngImport: i0, template: `
<ng-content></ng-content>
<div
class="ant-ribbon"
[class]="presetColor && 'ant-ribbon-color-' + presetColor"
[class.ant-ribbon-placement-end]="nzPlacement === 'end'"
[class.ant-ribbon-placement-start]="nzPlacement === 'start'"
[style.background-color]="!presetColor && nzColor"
>
<ng-container *nzStringTemplateOutlet="nzText">
<span class="ant-ribbon-text">{{ nzText }}</span>
</ng-container>
<div class="ant-ribbon-corner" [style.color]="!presetColor && nzColor"></div>
</div>
`, isInline: true, dependencies: [{ kind: "ngmodule", type: NzOutletModule }, { kind: "directive", type: i3.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzRibbonComponent, decorators: [{
type: Component,
args: [{
selector: 'nz-ribbon',
exportAs: 'nzRibbon',
preserveWhitespaces: false,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [NzOutletModule],
template: `
<ng-content></ng-content>
<div
class="ant-ribbon"
[class]="presetColor && 'ant-ribbon-color-' + presetColor"
[class.ant-ribbon-placement-end]="nzPlacement === 'end'"
[class.ant-ribbon-placement-start]="nzPlacement === 'start'"
[style.background-color]="!presetColor && nzColor"
>
<ng-container *nzStringTemplateOutlet="nzText">
<span class="ant-ribbon-text">{{ nzText }}</span>
</ng-container>
<div class="ant-ribbon-corner" [style.color]="!presetColor && nzColor"></div>
</div>
`,
host: { class: 'ant-ribbon-wrapper' }
}]
}], ctorParameters: () => [], propDecorators: { nzColor: [{
type: Input
}], nzPlacement: [{
type: Input
}], nzText: [{
type: Input
}] } });
/**
* 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 NzBadgeModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeModule, imports: [NzBadgeComponent, NzRibbonComponent], exports: [NzBadgeComponent, NzRibbonComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeModule, imports: [NzBadgeComponent, NzRibbonComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzBadgeModule, decorators: [{
type: NgModule,
args: [{
exports: [NzBadgeComponent, NzRibbonComponent],
imports: [NzBadgeComponent, NzRibbonComponent]
}]
}] });
/**
* 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 { NzBadgeComponent, NzBadgeModule, NzRibbonComponent };
//# sourceMappingURL=ng-zorro-antd-badge.mjs.map