UNPKG

ng-zorro-antd

Version:

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

440 lines (431 loc) 15.4 kB
import { PlatformModule } from '@angular/cdk/platform'; import { CommonModule } from '@angular/common'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, ViewChild, TemplateRef, Input, ChangeDetectorRef, ContentChildren, NgModule } from '@angular/core'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; import { __decorate, __metadata } from 'tslib'; import { InputNumber, InputBoolean } from 'ng-zorro-antd/core/util'; import { Subject, merge } from 'rxjs'; import { NzConfigService, WithConfig } from 'ng-zorro-antd/core/config'; import { warn } from 'ng-zorro-antd/core/logger'; import { NzBreakpointEnum, gridResponsiveMap, NzBreakpointService } from 'ng-zorro-antd/core/services'; import { startWith, takeUntil, switchMap, auditTime, tap } from 'rxjs/operators'; /** * @fileoverview added by tsickle * Generated from: descriptions-item.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzDescriptionsItemComponent { constructor() { this.nzSpan = 1; this.nzTitle = ''; this.inputChange$ = new Subject(); } /** * @return {?} */ ngOnChanges() { this.inputChange$.next(); } /** * @return {?} */ ngOnDestroy() { this.inputChange$.complete(); } } NzDescriptionsItemComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-descriptions-item', template: ` <ng-template> <ng-content></ng-content> </ng-template> `, exportAs: 'nzDescriptionsItem', preserveWhitespaces: false }] } ]; NzDescriptionsItemComponent.propDecorators = { content: [{ type: ViewChild, args: [TemplateRef, { static: true },] }], nzSpan: [{ type: Input }], nzTitle: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Object) ], NzDescriptionsItemComponent.prototype, "nzSpan", void 0); if (false) { /** @type {?} */ NzDescriptionsItemComponent.ngAcceptInputType_nzSpan; /** @type {?} */ NzDescriptionsItemComponent.prototype.content; /** @type {?} */ NzDescriptionsItemComponent.prototype.nzSpan; /** @type {?} */ NzDescriptionsItemComponent.prototype.nzTitle; /** @type {?} */ NzDescriptionsItemComponent.prototype.inputChange$; } /** * @fileoverview added by tsickle * Generated from: descriptions.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const NZ_CONFIG_COMPONENT_NAME = 'descriptions'; /** @type {?} */ const defaultColumnMap = { xxl: 3, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }; class NzDescriptionsComponent { /** * @param {?} nzConfigService * @param {?} cdr * @param {?} breakpointService */ constructor(nzConfigService, cdr, breakpointService) { this.nzConfigService = nzConfigService; this.cdr = cdr; this.breakpointService = breakpointService; this.nzLayout = 'horizontal'; this.nzTitle = ''; this.itemMatrix = []; this.realColumn = 3; this.breakpoint = NzBreakpointEnum.md; this.destroy$ = new Subject(); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzColumn) { this.prepareMatrix(); } } /** * @return {?} */ ngAfterContentInit() { /** @type {?} */ const contentChange$ = this.items.changes.pipe(startWith(this.items), takeUntil(this.destroy$)); merge(contentChange$, contentChange$.pipe(switchMap((/** * @return {?} */ () => merge(...this.items.map((/** * @param {?} i * @return {?} */ i => i.inputChange$))).pipe(auditTime(16))))), this.breakpointService.subscribe(gridResponsiveMap).pipe(tap((/** * @param {?} bp * @return {?} */ bp => (this.breakpoint = bp))))) .pipe(takeUntil(this.destroy$)) .subscribe((/** * @return {?} */ () => { this.prepareMatrix(); this.cdr.markForCheck(); })); } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } /** * Prepare the render matrix according to description items' spans. * @private * @return {?} */ prepareMatrix() { if (!this.items) { return; } /** @type {?} */ let currentRow = []; /** @type {?} */ let width = 0; /** @type {?} */ const column = (this.realColumn = this.getColumn()); /** @type {?} */ const items = this.items.toArray(); /** @type {?} */ const length = items.length; /** @type {?} */ const matrix = []; /** @type {?} */ const flushRow = (/** * @return {?} */ () => { matrix.push(currentRow); currentRow = []; width = 0; }); for (let i = 0; i < length; i++) { /** @type {?} */ const item = items[i]; const { nzTitle: title, content, nzSpan: span } = item; width += span; // If the last item make the row's length exceeds `nzColumn`, the last // item should take all the space left. This logic is implemented in the template. // Warn user about that. if (width >= column) { if (width > column) { warn(`"nzColumn" is ${column} but we have row length ${width}`); } currentRow.push({ title, content, span: column - (width - span) }); flushRow(); } else if (i === length - 1) { currentRow.push({ title, content, span: column - (width - span) }); flushRow(); } else { currentRow.push({ title, content, span }); } } this.itemMatrix = matrix; } /** * @private * @return {?} */ getColumn() { if (typeof this.nzColumn !== 'number') { return this.nzColumn[this.breakpoint]; } return this.nzColumn; } } NzDescriptionsComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-descriptions', exportAs: 'nzDescriptions', preserveWhitespaces: false, template: ` <div *ngIf="nzTitle" class="ant-descriptions-title"> <ng-container *nzStringTemplateOutlet="nzTitle">{{ nzTitle }}</ng-container> </div> <div class="ant-descriptions-view"> <table> <tbody> <ng-container *ngIf="nzLayout === 'horizontal'"> <tr class="ant-descriptions-row" *ngFor="let row of itemMatrix; let i = index"> <ng-container *ngFor="let item of row; let isLast = last"> <!-- Horizontal & NOT Bordered --> <ng-container *ngIf="!nzBordered"> <td class="ant-descriptions-item" [colSpan]="item.span"> <span class="ant-descriptions-item-label" [class.ant-descriptions-item-colon]="nzColon">{{ item.title }}</span> <span class="ant-descriptions-item-content"> <ng-template [ngTemplateOutlet]="item.content"></ng-template> </span> </td> </ng-container> <!-- Horizontal & Bordered --> <ng-container *ngIf="nzBordered"> <td class="ant-descriptions-item-label" *nzStringTemplateOutlet="item.title"> {{ item.title }} </td> <td class="ant-descriptions-item-content" [colSpan]="item.span * 2 - 1"> <ng-template [ngTemplateOutlet]="item.content"></ng-template> </td> </ng-container> </ng-container> </tr> </ng-container> <ng-container *ngIf="nzLayout === 'vertical'"> <!-- Vertical & NOT Bordered --> <ng-container *ngIf="!nzBordered"> <ng-container *ngFor="let row of itemMatrix; let i = index"> <tr class="ant-descriptions-row"> <ng-container *ngFor="let item of row; let isLast = last"> <td class="ant-descriptions-item" [colSpan]="item.span"> <span class="ant-descriptions-item-label" [class.ant-descriptions-item-colon]="nzColon">{{ item.title }}</span> </td> </ng-container> </tr> <tr class="ant-descriptions-row"> <ng-container *ngFor="let item of row; let isLast = last"> <td class="ant-descriptions-item" [colSpan]="item.span"> <span class="ant-descriptions-item-content"> <ng-template [ngTemplateOutlet]="item.content"></ng-template> </span> </td> </ng-container> </tr> </ng-container> </ng-container> <!-- Vertical & Bordered --> <ng-container *ngIf="nzBordered"> <ng-container *ngFor="let row of itemMatrix; let i = index"> <tr class="ant-descriptions-row"> <ng-container *ngFor="let item of row; let isLast = last"> <td class="ant-descriptions-item-label" [colSpan]="item.span"> {{ item.title }} </td> </ng-container> </tr> <tr class="ant-descriptions-row"> <ng-container *ngFor="let item of row; let isLast = last"> <td class="ant-descriptions-item-content" [colSpan]="item.span"> <ng-template [ngTemplateOutlet]="item.content"></ng-template> </td> </ng-container> </tr> </ng-container> </ng-container> </ng-container> </tbody> </table> </div> `, host: { class: 'ant-descriptions', '[class.ant-descriptions-bordered]': 'nzBordered', '[class.ant-descriptions-middle]': 'nzSize === "middle"', '[class.ant-descriptions-small]': 'nzSize === "small"' } }] } ]; /** @nocollapse */ NzDescriptionsComponent.ctorParameters = () => [ { type: NzConfigService }, { type: ChangeDetectorRef }, { type: NzBreakpointService } ]; NzDescriptionsComponent.propDecorators = { items: [{ type: ContentChildren, args: [NzDescriptionsItemComponent,] }], nzBordered: [{ type: Input }], nzLayout: [{ type: Input }], nzColumn: [{ type: Input }], nzSize: [{ type: Input }], nzTitle: [{ type: Input }], nzColon: [{ type: Input }] }; __decorate([ InputBoolean(), WithConfig(NZ_CONFIG_COMPONENT_NAME, false), __metadata("design:type", Boolean) ], NzDescriptionsComponent.prototype, "nzBordered", void 0); __decorate([ WithConfig(NZ_CONFIG_COMPONENT_NAME, defaultColumnMap), __metadata("design:type", Object) ], NzDescriptionsComponent.prototype, "nzColumn", void 0); __decorate([ WithConfig(NZ_CONFIG_COMPONENT_NAME, 'default'), __metadata("design:type", String) ], NzDescriptionsComponent.prototype, "nzSize", void 0); __decorate([ WithConfig(NZ_CONFIG_COMPONENT_NAME, true), InputBoolean(), __metadata("design:type", Boolean) ], NzDescriptionsComponent.prototype, "nzColon", void 0); if (false) { /** @type {?} */ NzDescriptionsComponent.ngAcceptInputType_nzBordered; /** @type {?} */ NzDescriptionsComponent.ngAcceptInputType_nzColon; /** @type {?} */ NzDescriptionsComponent.prototype.items; /** @type {?} */ NzDescriptionsComponent.prototype.nzBordered; /** @type {?} */ NzDescriptionsComponent.prototype.nzLayout; /** @type {?} */ NzDescriptionsComponent.prototype.nzColumn; /** @type {?} */ NzDescriptionsComponent.prototype.nzSize; /** @type {?} */ NzDescriptionsComponent.prototype.nzTitle; /** @type {?} */ NzDescriptionsComponent.prototype.nzColon; /** @type {?} */ NzDescriptionsComponent.prototype.itemMatrix; /** @type {?} */ NzDescriptionsComponent.prototype.realColumn; /** * @type {?} * @private */ NzDescriptionsComponent.prototype.breakpoint; /** * @type {?} * @private */ NzDescriptionsComponent.prototype.destroy$; /** @type {?} */ NzDescriptionsComponent.prototype.nzConfigService; /** * @type {?} * @private */ NzDescriptionsComponent.prototype.cdr; /** * @type {?} * @private */ NzDescriptionsComponent.prototype.breakpointService; } /** * @fileoverview added by tsickle * Generated from: descriptions.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzDescriptionsModule { } NzDescriptionsModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, NzOutletModule, PlatformModule], declarations: [NzDescriptionsComponent, NzDescriptionsItemComponent], exports: [NzDescriptionsComponent, NzDescriptionsItemComponent] },] } ]; /** * @fileoverview added by tsickle * Generated from: typings.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * 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 */ /** * @record */ function NzDescriptionsItemRenderProps() { } if (false) { /** @type {?} */ NzDescriptionsItemRenderProps.prototype.title; /** @type {?} */ NzDescriptionsItemRenderProps.prototype.span; /** @type {?} */ NzDescriptionsItemRenderProps.prototype.content; } /** * @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-descriptions.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzDescriptionsComponent, NzDescriptionsItemComponent, NzDescriptionsModule }; //# sourceMappingURL=ng-zorro-antd-descriptions.js.map