UNPKG

ng-zorro-antd

Version:

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

285 lines (280 loc) 10.9 kB
import { CommonModule } from '@angular/common'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, ViewChild, TemplateRef, Input, isDevMode, ChangeDetectorRef, NgZone, ContentChildren, NgModule } from '@angular/core'; import { InputNumber, warn, Breakpoint, responsiveMap, InputBoolean, NzAddOnModule } from 'ng-zorro-antd/core'; import { __decorate, __metadata } from 'tslib'; import { MediaMatcher } from '@angular/cdk/layout'; import { Platform } from '@angular/cdk/platform'; import { merge, fromEvent, Subject } from 'rxjs'; import { startWith, takeUntil, auditTime } from 'rxjs/operators'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzDescriptionsItemComponent = /** @class */ (function () { function NzDescriptionsItemComponent() { this.nzSpan = 1; this.nzTitle = ''; } NzDescriptionsItemComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-descriptions-item', template: "<!-- Use a template to wrap contents so contents wouldn't be displayed. -->\n<ng-template>\n <ng-content></ng-content>\n</ng-template>\n", 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); return NzDescriptionsItemComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var defaultColumnMap = { xxl: 3, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }; var NzDescriptionsComponent = /** @class */ (function () { function NzDescriptionsComponent(cdr, ngZone, mediaMatcher, platform) { this.cdr = cdr; this.ngZone = ngZone; this.mediaMatcher = mediaMatcher; this.platform = platform; this.nzBordered = false; this.nzColumn = defaultColumnMap; this.nzSize = 'default'; this.nzTitle = ''; this.itemMatrix = []; this.realColumn = 3; this.destroy$ = new Subject(); this.resize$ = new Subject(); } /** * @param {?} changes * @return {?} */ NzDescriptionsComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (changes.nzColumn) { this.resize$.next(); } }; /** * @return {?} */ NzDescriptionsComponent.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; merge(this.items.changes.pipe(startWith(this.items), takeUntil(this.destroy$)), this.resize$) .pipe(takeUntil(this.destroy$)) .subscribe((/** * @return {?} */ function () { _this.prepareMatrix(); _this.cdr.markForCheck(); })); if (this.platform.isBrowser) { this.ngZone.runOutsideAngular((/** * @return {?} */ function () { fromEvent(window, 'resize') .pipe(auditTime(16), takeUntil(_this.destroy$)) .subscribe((/** * @return {?} */ function () { _this.ngZone.run((/** * @return {?} */ function () { _this.resize$.next(); })); })); })); } }; /** * @return {?} */ NzDescriptionsComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroy$.next(); this.destroy$.complete(); this.resize$.complete(); }; /** * Prepare the render matrix according to description items' spans. */ /** * Prepare the render matrix according to description items' spans. * @private * @return {?} */ NzDescriptionsComponent.prototype.prepareMatrix = /** * Prepare the render matrix according to description items' spans. * @private * @return {?} */ function () { /** @type {?} */ var currentRow = []; /** @type {?} */ var width = 0; /** @type {?} */ var column = (this.realColumn = this.getColumn()); /** @type {?} */ var items = this.items.toArray(); /** @type {?} */ var matrix = []; /** @type {?} */ var flushRow = (/** * @return {?} */ function () { matrix.push(currentRow); currentRow = []; width = 0; }); items.forEach((/** * @param {?} item * @return {?} */ function (item) { var title = item.nzTitle, content = item.content, span = item.nzSpan; currentRow.push({ title: title, content: content, span: span }); 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 && isDevMode()) { warn("\"nzColumn\" is " + column + " but we have row length " + width); } flushRow(); } })); if (currentRow.length) { flushRow(); } this.itemMatrix = matrix; }; /** * @private * @return {?} */ NzDescriptionsComponent.prototype.matchMedia = /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var bp = Breakpoint.md; Object.keys(responsiveMap).map((/** * @param {?} breakpoint * @return {?} */ function (breakpoint) { /** @type {?} */ var castBP = (/** @type {?} */ (breakpoint)); /** @type {?} */ var matchBelow = _this.mediaMatcher.matchMedia(responsiveMap[castBP]).matches; if (matchBelow) { bp = castBP; } })); return bp; }; /** * @private * @return {?} */ NzDescriptionsComponent.prototype.getColumn = /** * @private * @return {?} */ function () { if (typeof this.nzColumn !== 'number') { return this.nzColumn[this.matchMedia()]; } return this.nzColumn; }; NzDescriptionsComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-descriptions', template: "<div *ngIf=\"nzTitle\"\n class=\"ant-descriptions-title\">\n <ng-container *nzStringTemplateOutlet=\"nzTitle\">{{ nzTitle }}</ng-container>\n</div>\n<div class=\"ant-descriptions-view\">\n <table>\n <tbody>\n <tr class=\"ant-descriptions-row\"\n *ngFor=\"let row of itemMatrix; let i = index\">\n <ng-container *ngFor=\"let item of row; let isLast = last\">\n <ng-container *ngIf=\"!nzBordered\">\n <td class=\"ant-descriptions-item\"\n [colSpan]=\"isLast ? (realColumn - (row.length - 1)) * 2 - 1 : item.span\">\n <span class=\"ant-descriptions-item-label\">{{ item.title }}</span>\n <span class=\"ant-descriptions-item-content\">\n <ng-template [ngTemplateOutlet]=\"item.content\"></ng-template>\n </span>\n </td>\n </ng-container>\n <ng-container *ngIf=\"nzBordered\">\n <td class=\"ant-descriptions-item-label\"\n *nzStringTemplateOutlet=\"item.title\">{{ item.title }}</td>\n <td class=\"ant-descriptions-item-content\"\n [colSpan]=\"isLast ? (realColumn - (row.length - 1)) * 2 - 1 : item.span\">\n <ng-template [ngTemplateOutlet]=\"item.content\"></ng-template>\n </td>\n </ng-container>\n </ng-container>\n </tr>\n </tbody>\n\n </table>\n</div>\n", exportAs: 'nzDescriptions', preserveWhitespaces: false, host: { class: 'ant-descriptions', '[class.bordered]': 'nzBordered', '[class.middle]': 'nzSize === "middle"', '[class.small]': 'nzSize === "small"' }, styles: ["\n nz-descriptions {\n display: block;\n }\n "] }] } ]; /** @nocollapse */ NzDescriptionsComponent.ctorParameters = function () { return [ { type: ChangeDetectorRef }, { type: NgZone }, { type: MediaMatcher }, { type: Platform } ]; }; NzDescriptionsComponent.propDecorators = { items: [{ type: ContentChildren, args: [NzDescriptionsItemComponent,] }], nzBordered: [{ type: Input }], nzColumn: [{ type: Input }], nzSize: [{ type: Input }], nzTitle: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzDescriptionsComponent.prototype, "nzBordered", void 0); return NzDescriptionsComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NzDescriptionsModule = /** @class */ (function () { function NzDescriptionsModule() { } NzDescriptionsModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, NzAddOnModule], declarations: [NzDescriptionsComponent, NzDescriptionsItemComponent], exports: [NzDescriptionsComponent, NzDescriptionsItemComponent] },] } ]; return NzDescriptionsModule; }()); export { NzDescriptionsComponent, NzDescriptionsItemComponent, NzDescriptionsModule }; //# sourceMappingURL=ng-zorro-antd-descriptions.js.map