UNPKG

ng-zorro-antd

Version:

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

342 lines (335 loc) 11.1 kB
import { fromEvent, Subject } from 'rxjs'; import { auditTime, takeUntil, startWith } from 'rxjs/operators'; import { NzUpdateHostClassService, isNotNil } from 'ng-zorro-antd/core'; import { MediaMatcher, LayoutModule } from '@angular/cdk/layout'; import { Platform, PlatformModule } from '@angular/cdk/platform'; import { CommonModule } from '@angular/common'; import { Directive, ElementRef, Input, NgZone, Renderer2, Host, Optional, NgModule } from '@angular/core'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const Breakpoint = { 'xxl': 0, 'xl': 1, 'lg': 2, 'md': 3, 'sm': 4, 'xs': 5, }; Breakpoint[Breakpoint['xxl']] = 'xxl'; Breakpoint[Breakpoint['xl']] = 'xl'; Breakpoint[Breakpoint['lg']] = 'lg'; Breakpoint[Breakpoint['md']] = 'md'; Breakpoint[Breakpoint['sm']] = 'sm'; Breakpoint[Breakpoint['xs']] = 'xs'; /** @type {?} */ const responsiveMap = { xs: '(max-width: 575px)', sm: '(min-width: 576px)', md: '(min-width: 768px)', lg: '(min-width: 992px)', xl: '(min-width: 1200px)', xxl: '(min-width: 1600px)' }; class NzRowDirective { /** * @param {?} elementRef * @param {?} renderer * @param {?} nzUpdateHostClassService * @param {?} mediaMatcher * @param {?} ngZone * @param {?} platform */ constructor(elementRef, renderer, nzUpdateHostClassService, mediaMatcher, ngZone, platform) { this.elementRef = elementRef; this.renderer = renderer; this.nzUpdateHostClassService = nzUpdateHostClassService; this.mediaMatcher = mediaMatcher; this.ngZone = ngZone; this.platform = platform; this.nzAlign = 'top'; this.nzJustify = 'start'; this.el = this.elementRef.nativeElement; this.prefixCls = 'ant-row'; this.actualGutter$ = new Subject(); this.destroy$ = new Subject(); } /** * @return {?} */ calculateGutter() { if (typeof this.nzGutter !== 'object') { return this.nzGutter; } else if (this.breakPoint && this.nzGutter[this.breakPoint]) { return this.nzGutter[this.breakPoint]; } else { return 0; } } /** * @return {?} */ updateGutter() { /** @type {?} */ const actualGutter = this.calculateGutter(); if (this.actualGutter !== actualGutter) { this.actualGutter = actualGutter; this.actualGutter$.next(this.actualGutter); this.renderer.setStyle(this.el, 'margin-left', `-${this.actualGutter / 2}px`); this.renderer.setStyle(this.el, 'margin-right', `-${this.actualGutter / 2}px`); } } /** * @return {?} */ watchMedia() { // @ts-ignore Object.keys(responsiveMap).map((/** * @param {?} screen * @return {?} */ (screen) => { /** @type {?} */ const matchBelow = this.mediaMatcher.matchMedia(responsiveMap[screen]).matches; if (matchBelow) { this.breakPoint = screen; } })); this.updateGutter(); } /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ setClassMap() { /** @type {?} */ const classMap = { [`${this.prefixCls}`]: !this.nzType, [`${this.prefixCls}-${this.nzType}`]: this.nzType, [`${this.prefixCls}-${this.nzType}-${this.nzAlign}`]: this.nzType && this.nzAlign, [`${this.prefixCls}-${this.nzType}-${this.nzJustify}`]: this.nzType && this.nzJustify }; this.nzUpdateHostClassService.updateHostClass(this.el, classMap); } /** * @return {?} */ ngOnInit() { this.setClassMap(); this.watchMedia(); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.nzType || changes.nzAlign || changes.nzJustify) { this.setClassMap(); } if (changes.nzGutter) { this.updateGutter(); } } /** * @return {?} */ ngAfterViewInit() { if (this.platform.isBrowser) { this.ngZone.runOutsideAngular((/** * @return {?} */ () => { fromEvent(window, 'resize') .pipe(auditTime(16), takeUntil(this.destroy$)) .subscribe((/** * @return {?} */ () => this.watchMedia())); })); } } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzRowDirective.decorators = [ { type: Directive, args: [{ selector: '[nz-row],nz-row', exportAs: 'nzRow', providers: [NzUpdateHostClassService] },] } ]; /** @nocollapse */ NzRowDirective.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 }, { type: NzUpdateHostClassService }, { type: MediaMatcher }, { type: NgZone }, { type: Platform } ]; NzRowDirective.propDecorators = { nzType: [{ type: Input }], nzAlign: [{ type: Input }], nzJustify: [{ type: Input }], nzGutter: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzColDirective { /** * @param {?} nzUpdateHostClassService * @param {?} elementRef * @param {?} nzRowDirective * @param {?} renderer */ constructor(nzUpdateHostClassService, elementRef, nzRowDirective, renderer) { this.nzUpdateHostClassService = nzUpdateHostClassService; this.elementRef = elementRef; this.nzRowDirective = nzRowDirective; this.renderer = renderer; this.el = this.elementRef.nativeElement; this.prefixCls = 'ant-col'; this.destroy$ = new Subject(); } // tslint:disable-line:no-any /** * temp solution since no method add classMap to host https://github.com/angular/angular/issues/7289 * @return {?} */ setClassMap() { /** @type {?} */ const classMap = Object.assign({ [`${this.prefixCls}-${this.nzSpan}`]: isNotNil(this.nzSpan), [`${this.prefixCls}-order-${this.nzOrder}`]: isNotNil(this.nzOrder), [`${this.prefixCls}-offset-${this.nzOffset}`]: isNotNil(this.nzOffset), [`${this.prefixCls}-pull-${this.nzPull}`]: isNotNil(this.nzPull), [`${this.prefixCls}-push-${this.nzPush}`]: isNotNil(this.nzPush) }, this.generateClass()); this.nzUpdateHostClassService.updateHostClass(this.el, classMap); } /** * @return {?} */ generateClass() { /** @type {?} */ const listOfSizeInputName = ['nzXs', 'nzSm', 'nzMd', 'nzLg', 'nzXl', 'nzXXl']; /** @type {?} */ const listClassMap = {}; listOfSizeInputName.forEach((/** * @param {?} name * @return {?} */ name => { /** @type {?} */ const sizeName = name.replace('nz', '').toLowerCase(); if (isNotNil(this[name])) { if (typeof this[name] === 'number' || typeof this[name] === 'string') { listClassMap[`${this.prefixCls}-${sizeName}-${this[name]}`] = true; } else { listClassMap[`${this.prefixCls}-${sizeName}-${this[name].span}`] = this[name] && isNotNil(this[name].span); listClassMap[`${this.prefixCls}-${sizeName}-pull-${this[name].pull}`] = this[name] && isNotNil(this[name].pull); listClassMap[`${this.prefixCls}-${sizeName}-push-${this[name].push}`] = this[name] && isNotNil(this[name].push); listClassMap[`${this.prefixCls}-${sizeName}-offset-${this[name].offset}`] = this[name] && isNotNil(this[name].offset); listClassMap[`${this.prefixCls}-${sizeName}-order-${this[name].order}`] = this[name] && isNotNil(this[name].order); } } })); return listClassMap; } /** * @return {?} */ ngOnChanges() { this.setClassMap(); } /** * @return {?} */ ngAfterViewInit() { if (this.nzRowDirective) { this.nzRowDirective.actualGutter$ .pipe(startWith(this.nzRowDirective.actualGutter), takeUntil(this.destroy$)) .subscribe((/** * @param {?} actualGutter * @return {?} */ actualGutter => { this.renderer.setStyle(this.el, 'padding-left', `${actualGutter / 2}px`); this.renderer.setStyle(this.el, 'padding-right', `${actualGutter / 2}px`); })); } } /** * @return {?} */ ngOnInit() { this.setClassMap(); } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzColDirective.decorators = [ { type: Directive, args: [{ selector: '[nz-col],nz-col', exportAs: 'nzCol', providers: [NzUpdateHostClassService] },] } ]; /** @nocollapse */ NzColDirective.ctorParameters = () => [ { type: NzUpdateHostClassService }, { type: ElementRef }, { type: NzRowDirective, decorators: [{ type: Optional }, { type: Host }] }, { type: Renderer2 } ]; NzColDirective.propDecorators = { nzSpan: [{ type: Input }], nzOrder: [{ type: Input }], nzOffset: [{ type: Input }], nzPush: [{ type: Input }], nzPull: [{ type: Input }], nzXs: [{ type: Input }], nzSm: [{ type: Input }], nzMd: [{ type: Input }], nzLg: [{ type: Input }], nzXl: [{ type: Input }], nzXXl: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzGridModule { } NzGridModule.decorators = [ { type: NgModule, args: [{ declarations: [NzColDirective, NzRowDirective], exports: [NzColDirective, NzRowDirective], imports: [CommonModule, LayoutModule, PlatformModule] },] } ]; /** * @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 { Breakpoint, NzRowDirective, NzColDirective, NzGridModule }; //# sourceMappingURL=ng-zorro-antd-grid.js.map