UNPKG

ng-zorro-antd

Version:

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

284 lines (277 loc) 10.4 kB
import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Input, Renderer2, TemplateRef, ViewChild, ViewEncapsulation, ContentChildren, NgModule } from '@angular/core'; import { toBoolean, NzAddOnModule } from 'ng-zorro-antd/core'; import { NzIconModule } from 'ng-zorro-antd/icon'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzStepComponent { /** * @param {?} cdr * @param {?} renderer * @param {?} elementRef */ constructor(cdr, renderer, elementRef) { this.cdr = cdr; this.isCustomStatus = false; this._status = 'wait'; this.oldAPIIcon = true; this.isIconString = true; // Set by parent. this.direction = 'horizontal'; this.index = 0; this.last = false; this.outStatus = 'process'; this.showProcessDot = false; this._currentIndex = 0; renderer.addClass(elementRef.nativeElement, 'ant-steps-item'); } /** * @return {?} */ get nzStatus() { return this._status; } /** * @param {?} status * @return {?} */ set nzStatus(status) { this._status = status; this.isCustomStatus = true; } /** * @return {?} */ get nzIcon() { return this._icon; } /** * @param {?} value * @return {?} */ set nzIcon(value) { if (!(value instanceof TemplateRef)) { this.isIconString = true; this.oldAPIIcon = typeof value === 'string' && value.indexOf('anticon') > -1; } else { this.isIconString = false; } this._icon = value; } /** * @return {?} */ get currentIndex() { return this._currentIndex; } /** * @param {?} current * @return {?} */ set currentIndex(current) { this._currentIndex = current; if (!this.isCustomStatus) { this._status = current > this.index ? 'finish' : current === this.index ? this.outStatus || '' : 'wait'; } } /** * @return {?} */ markForCheck() { this.cdr.markForCheck(); } } NzStepComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-step', exportAs: 'nzStep', preserveWhitespaces: false, template: "<div class=\"ant-steps-item-tail\" *ngIf=\"last !== true\"></div>\n<div class=\"ant-steps-item-icon\">\n <ng-template [ngIf]=\"!showProcessDot\">\n <span class=\"ant-steps-icon\" *ngIf=\"nzStatus === 'finish' && !nzIcon\"><i nz-icon type=\"check\"></i></span>\n <span class=\"ant-steps-icon\" *ngIf=\"nzStatus === 'error'\"><i nz-icon type=\"close\"></i></span>\n <span class=\"ant-steps-icon\" *ngIf=\"(nzStatus === 'process' || nzStatus === 'wait') && !nzIcon\">{{ index + 1 }}</span>\n <span class=\"ant-steps-icon\" *ngIf=\"nzIcon\">\n <ng-container *ngIf=\"isIconString; else iconTemplate\">\n <i nz-icon [type]=\"!oldAPIIcon && nzIcon\" [ngClass]=\"oldAPIIcon && nzIcon\"></i>\n </ng-container>\n <ng-template #iconTemplate>\n <ng-template [ngTemplateOutlet]=\"nzIcon\"></ng-template>\n </ng-template>\n </span>\n </ng-template>\n <ng-template [ngIf]=\"showProcessDot\">\n <span class=\"ant-steps-icon\">\n <ng-template #processDotTemplate>\n <span class=\"ant-steps-icon-dot\"></span>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"customProcessTemplate||processDotTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: processDotTemplate, status:nzStatus, index:index }\">\n </ng-template>\n </span>\n </ng-template>\n</div>\n<div class=\"ant-steps-item-content\">\n <div class=\"ant-steps-item-title\">\n <ng-container *nzStringTemplateOutlet=\"nzTitle\">{{ nzTitle }}</ng-container>\n </div>\n <div class=\"ant-steps-item-description\">\n <ng-container *nzStringTemplateOutlet=\"nzDescription\">{{ nzDescription }}</ng-container>\n </div>\n</div>\n", host: { '[class.ant-steps-item-wait]': 'nzStatus === "wait"', '[class.ant-steps-item-process]': 'nzStatus === "process"', '[class.ant-steps-item-finish]': 'nzStatus === "finish"', '[class.ant-steps-item-error]': 'nzStatus === "error"', '[class.ant-steps-custom]': '!!nzIcon', '[class.ant-steps-next-error]': '(outStatus === "error") && (currentIndex === index + 1)' } }] } ]; /** @nocollapse */ NzStepComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: Renderer2 }, { type: ElementRef } ]; NzStepComponent.propDecorators = { processDotTemplate: [{ type: ViewChild, args: ['processDotTemplate',] }], nzTitle: [{ type: Input }], nzDescription: [{ type: Input }], nzStatus: [{ type: Input }], nzIcon: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzStepsComponent { constructor() { this.nzCurrent = 0; this.nzDirection = 'horizontal'; this.nzLabelPlacement = 'horizontal'; this.nzSize = 'default'; this.nzStartIndex = 0; this.nzStatus = 'process'; this.showProcessDot = false; this.destroy$ = new Subject(); } /** * @param {?} value * @return {?} */ set nzProgressDot(value) { if (value instanceof TemplateRef) { this.showProcessDot = true; this.customProcessDotTemplate = value; } else { this.showProcessDot = toBoolean(value); } this.updateChildrenSteps(); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzStartIndex || changes.nzDirection || changes.nzStatus || changes.nzCurrent) { this.updateChildrenSteps(); } if (changes.nzDirection || changes.nzProgressDot || changes.nzLabelPlacement || changes.nzSize) { this.setClassMap(); } } /** * @return {?} */ ngOnInit() { this.setClassMap(); this.updateChildrenSteps(); } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } /** * @return {?} */ ngAfterContentInit() { this.updateChildrenSteps(); if (this.steps) { this.steps.changes.pipe(takeUntil(this.destroy$)).subscribe((/** * @return {?} */ () => { this.updateChildrenSteps(); })); } } /** * @private * @return {?} */ updateChildrenSteps() { if (this.steps) { /** @type {?} */ const length = this.steps.length; this.steps.toArray().forEach((/** * @param {?} step * @param {?} index * @return {?} */ (step, index) => { Promise.resolve().then((/** * @return {?} */ () => { step.outStatus = this.nzStatus; step.showProcessDot = this.showProcessDot; if (this.customProcessDotTemplate) { step.customProcessTemplate = this.customProcessDotTemplate; } step.direction = this.nzDirection; step.index = index + this.nzStartIndex; step.currentIndex = this.nzCurrent; step.last = length === index + 1; step.markForCheck(); })); })); } } /** * @private * @return {?} */ setClassMap() { this.classMap = { [`ant-steps-${this.nzDirection}`]: true, [`ant-steps-label-horizontal`]: this.nzDirection === 'horizontal', [`ant-steps-label-vertical`]: (this.showProcessDot || this.nzLabelPlacement === 'vertical') && this.nzDirection === 'horizontal', [`ant-steps-dot`]: this.showProcessDot, ['ant-steps-small']: this.nzSize === 'small' }; } } NzStepsComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false, selector: 'nz-steps', exportAs: 'nzSteps', template: "<div class=\"ant-steps\" [ngClass]=\"classMap\">\n <ng-content></ng-content>\n</div>" }] } ]; NzStepsComponent.propDecorators = { steps: [{ type: ContentChildren, args: [NzStepComponent,] }], nzCurrent: [{ type: Input }], nzDirection: [{ type: Input }], nzLabelPlacement: [{ type: Input }], nzSize: [{ type: Input }], nzStartIndex: [{ type: Input }], nzStatus: [{ type: Input }], nzProgressDot: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzStepsModule { } NzStepsModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, NzIconModule, NzAddOnModule], exports: [NzStepsComponent, NzStepComponent], declarations: [NzStepsComponent, NzStepComponent] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzStepsComponent, NzStepComponent, NzStepsModule }; //# sourceMappingURL=ng-zorro-antd-steps.js.map