UNPKG

ng-zorro-antd

Version:

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

208 lines (201 loc) 10.4 kB
import { __decorate } from 'tslib'; import { PlatformModule } from '@angular/cdk/platform'; import * as i0 from '@angular/core'; import { EventEmitter, numberAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ViewChild, NgModule } from '@angular/core'; import * as i1 from 'ng-zorro-antd/core/config'; import { WithConfig } from 'ng-zorro-antd/core/config'; import * as i2 from 'ng-zorro-antd/icon'; import { NzIconModule } from 'ng-zorro-antd/icon'; const NZ_CONFIG_MODULE_NAME = 'avatar'; class NzAvatarComponent { constructor(nzConfigService, elementRef, cdr) { this.nzConfigService = nzConfigService; this.elementRef = elementRef; this.cdr = cdr; this._nzModuleName = NZ_CONFIG_MODULE_NAME; this.nzShape = 'circle'; this.nzSize = 'default'; this.nzGap = 4; this.nzError = new EventEmitter(); this.hasText = false; this.hasSrc = true; this.hasIcon = false; this.classMap = {}; this.customSize = null; this.el = this.elementRef.nativeElement; } imgError($event) { this.nzError.emit($event); if (!$event.defaultPrevented) { this.hasSrc = false; this.hasIcon = false; this.hasText = false; if (this.nzIcon) { this.hasIcon = true; } else if (this.nzText) { this.hasText = true; } this.cdr.detectChanges(); this.setSizeStyle(); this.calcStringSize(); } } ngOnChanges() { this.hasText = !this.nzSrc && !!this.nzText; this.hasIcon = !this.nzSrc && !!this.nzIcon; this.hasSrc = !!this.nzSrc; this.setSizeStyle(); this.calcStringSize(); } ngAfterViewInit() { this.calcStringSize(); } calcStringSize() { if (!this.hasText || !this.textEl) { return; } const textEl = this.textEl.nativeElement; const childrenWidth = textEl.offsetWidth; const avatarWidth = this.el.getBoundingClientRect?.().width ?? 0; const offset = this.nzGap * 2 < avatarWidth ? this.nzGap * 2 : 8; const scale = avatarWidth - offset < childrenWidth ? (avatarWidth - offset) / childrenWidth : 1; textEl.style.transform = `scale(${scale}) translateX(-50%)`; textEl.style.lineHeight = this.customSize || ''; } setSizeStyle() { if (typeof this.nzSize === 'number') { this.customSize = `${this.nzSize}px`; } else { this.customSize = null; } this.cdr.markForCheck(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarComponent, deps: [{ token: i1.NzConfigService }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.1.2", type: NzAvatarComponent, isStandalone: true, selector: "nz-avatar", inputs: { nzShape: "nzShape", nzSize: "nzSize", nzGap: ["nzGap", "nzGap", numberAttribute], nzText: "nzText", nzSrc: "nzSrc", nzSrcSet: "nzSrcSet", nzAlt: "nzAlt", nzIcon: "nzIcon" }, outputs: { nzError: "nzError" }, host: { properties: { "class.ant-avatar-lg": "nzSize === 'large'", "class.ant-avatar-sm": "nzSize === 'small'", "class.ant-avatar-square": "nzShape === 'square'", "class.ant-avatar-circle": "nzShape === 'circle'", "class.ant-avatar-icon": "nzIcon", "class.ant-avatar-image": "hasSrc ", "style.width": "customSize", "style.height": "customSize", "style.line-height": "customSize", "style.font-size.px": "(hasIcon && customSize) ? $any(nzSize) / 2 : null" }, classAttribute: "ant-avatar" }, viewQueries: [{ propertyName: "textEl", first: true, predicate: ["textEl"], descendants: true }], exportAs: ["nzAvatar"], usesOnChanges: true, ngImport: i0, template: ` @if (nzIcon && hasIcon) { <span nz-icon [nzType]="nzIcon"></span> } @if (nzSrc && hasSrc) { <img [src]="nzSrc" [attr.srcset]="nzSrcSet" [attr.alt]="nzAlt" (error)="imgError($event)" /> } @if (nzText && hasText) { <span class="ant-avatar-string" #textEl>{{ nzText }}</span> } `, isInline: true, dependencies: [{ kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i2.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: PlatformModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } } __decorate([ WithConfig() ], NzAvatarComponent.prototype, "nzShape", void 0); __decorate([ WithConfig() ], NzAvatarComponent.prototype, "nzSize", void 0); __decorate([ WithConfig() ], NzAvatarComponent.prototype, "nzGap", void 0); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarComponent, decorators: [{ type: Component, args: [{ selector: 'nz-avatar', exportAs: 'nzAvatar', standalone: true, imports: [NzIconModule, PlatformModule], template: ` @if (nzIcon && hasIcon) { <span nz-icon [nzType]="nzIcon"></span> } @if (nzSrc && hasSrc) { <img [src]="nzSrc" [attr.srcset]="nzSrcSet" [attr.alt]="nzAlt" (error)="imgError($event)" /> } @if (nzText && hasText) { <span class="ant-avatar-string" #textEl>{{ nzText }}</span> } `, host: { class: 'ant-avatar', '[class.ant-avatar-lg]': `nzSize === 'large'`, '[class.ant-avatar-sm]': `nzSize === 'small'`, '[class.ant-avatar-square]': `nzShape === 'square'`, '[class.ant-avatar-circle]': `nzShape === 'circle'`, '[class.ant-avatar-icon]': `nzIcon`, '[class.ant-avatar-image]': `hasSrc `, '[style.width]': 'customSize', '[style.height]': 'customSize', '[style.line-height]': 'customSize', // nzSize type is number when customSize is true '[style.font-size.px]': '(hasIcon && customSize) ? $any(nzSize) / 2 : null' }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] }], ctorParameters: () => [{ type: i1.NzConfigService }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }], propDecorators: { nzShape: [{ type: Input }], nzSize: [{ type: Input }], nzGap: [{ type: Input, args: [{ transform: numberAttribute }] }], nzText: [{ type: Input }], nzSrc: [{ type: Input }], nzSrcSet: [{ type: Input }], nzAlt: [{ type: Input }], nzIcon: [{ type: Input }], nzError: [{ type: Output }], textEl: [{ type: ViewChild, args: ['textEl', { static: false }] }] } }); /** * 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 NzAvatarGroupComponent { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.1.2", type: NzAvatarGroupComponent, isStandalone: true, selector: "nz-avatar-group", host: { classAttribute: "ant-avatar-group" }, exportAs: ["nzAvatarGroup"], ngImport: i0, template: ` <ng-content></ng-content> `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarGroupComponent, decorators: [{ type: Component, args: [{ selector: 'nz-avatar-group', exportAs: 'nzAvatarGroup', standalone: true, template: ` <ng-content></ng-content> `, changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'ant-avatar-group' } }] }] }); /** * 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 NzAvatarModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarModule, imports: [NzAvatarComponent, NzAvatarGroupComponent], exports: [NzAvatarComponent, NzAvatarGroupComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarModule, imports: [NzAvatarComponent] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: NzAvatarModule, decorators: [{ type: NgModule, args: [{ exports: [NzAvatarComponent, NzAvatarGroupComponent], imports: [NzAvatarComponent, NzAvatarGroupComponent] }] }] }); /** * 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 { NzAvatarComponent, NzAvatarGroupComponent, NzAvatarModule }; //# sourceMappingURL=ng-zorro-antd-avatar.mjs.map