ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
442 lines (435 loc) • 13.6 kB
JavaScript
import { Directive, ElementRef, Renderer2, NgZone, Input, Optional, Host, NgModule } from '@angular/core';
import { MediaMatcher, LayoutModule } from '@angular/cdk/layout';
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { responsiveMap, NzUpdateHostClassService, NzDomEventService, isNotNil } from 'ng-zorro-antd/core';
import { Subject } from 'rxjs';
import { takeUntil, finalize, startWith } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzRowDirective {
/**
* @param {?} elementRef
* @param {?} renderer
* @param {?} nzUpdateHostClassService
* @param {?} mediaMatcher
* @param {?} ngZone
* @param {?} platform
* @param {?} nzDomEventService
*/
constructor(elementRef, renderer, nzUpdateHostClassService, mediaMatcher, ngZone, platform, nzDomEventService) {
this.elementRef = elementRef;
this.renderer = renderer;
this.nzUpdateHostClassService = nzUpdateHostClassService;
this.mediaMatcher = mediaMatcher;
this.ngZone = ngZone;
this.platform = platform;
this.nzDomEventService = nzDomEventService;
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() {
Object.keys(responsiveMap).map((/**
* @param {?} screen
* @return {?}
*/
(screen) => {
/** @type {?} */
const castBP = (/** @type {?} */ (screen));
/** @type {?} */
const matchBelow = this.mediaMatcher.matchMedia(responsiveMap[castBP]).matches;
if (matchBelow) {
this.breakPoint = castBP;
}
}));
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.nzDomEventService
.registerResizeListener()
.pipe(takeUntil(this.destroy$), finalize((/**
* @return {?}
*/
() => this.nzDomEventService.unregisterResizeListener())))
.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 },
{ type: NzDomEventService }
];
NzRowDirective.propDecorators = {
nzType: [{ type: Input }],
nzAlign: [{ type: Input }],
nzJustify: [{ type: Input }],
nzGutter: [{ type: Input }]
};
if (false) {
/** @type {?} */
NzRowDirective.prototype.nzType;
/** @type {?} */
NzRowDirective.prototype.nzAlign;
/** @type {?} */
NzRowDirective.prototype.nzJustify;
/** @type {?} */
NzRowDirective.prototype.nzGutter;
/**
* @type {?}
* @private
*/
NzRowDirective.prototype.el;
/**
* @type {?}
* @private
*/
NzRowDirective.prototype.prefixCls;
/**
* @type {?}
* @private
*/
NzRowDirective.prototype.breakPoint;
/** @type {?} */
NzRowDirective.prototype.actualGutter;
/** @type {?} */
NzRowDirective.prototype.actualGutter$;
/** @type {?} */
NzRowDirective.prototype.destroy$;
/** @type {?} */
NzRowDirective.prototype.elementRef;
/** @type {?} */
NzRowDirective.prototype.renderer;
/** @type {?} */
NzRowDirective.prototype.nzUpdateHostClassService;
/** @type {?} */
NzRowDirective.prototype.mediaMatcher;
/** @type {?} */
NzRowDirective.prototype.ngZone;
/** @type {?} */
NzRowDirective.prototype.platform;
/**
* @type {?}
* @private
*/
NzRowDirective.prototype.nzDomEventService;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function EmbeddedProperty() { }
if (false) {
/** @type {?|undefined} */
EmbeddedProperty.prototype.span;
/** @type {?|undefined} */
EmbeddedProperty.prototype.pull;
/** @type {?|undefined} */
EmbeddedProperty.prototype.push;
/** @type {?|undefined} */
EmbeddedProperty.prototype.offset;
/** @type {?|undefined} */
EmbeddedProperty.prototype.order;
}
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();
}
/**
* 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 {
/** @type {?} */
const embedded = (/** @type {?} */ (this[name]));
/** @type {?} */
const prefixArray = ['span', 'pull', 'push', 'offset', 'order'];
prefixArray.forEach((/**
* @param {?} prefix
* @return {?}
*/
prefix => {
/** @type {?} */
const prefixClass = prefix === 'span' ? '-' : `-${prefix}-`;
listClassMap[`${this.prefixCls}-${sizeName}${prefixClass}${embedded[prefix]}`] =
embedded && isNotNil(embedded[prefix]);
}));
}
}
}));
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 }]
};
if (false) {
/**
* @type {?}
* @private
*/
NzColDirective.prototype.el;
/**
* @type {?}
* @private
*/
NzColDirective.prototype.prefixCls;
/**
* @type {?}
* @protected
*/
NzColDirective.prototype.destroy$;
/** @type {?} */
NzColDirective.prototype.nzSpan;
/** @type {?} */
NzColDirective.prototype.nzOrder;
/** @type {?} */
NzColDirective.prototype.nzOffset;
/** @type {?} */
NzColDirective.prototype.nzPush;
/** @type {?} */
NzColDirective.prototype.nzPull;
/** @type {?} */
NzColDirective.prototype.nzXs;
/** @type {?} */
NzColDirective.prototype.nzSm;
/** @type {?} */
NzColDirective.prototype.nzMd;
/** @type {?} */
NzColDirective.prototype.nzLg;
/** @type {?} */
NzColDirective.prototype.nzXl;
/** @type {?} */
NzColDirective.prototype.nzXXl;
/**
* @type {?}
* @private
*/
NzColDirective.prototype.nzUpdateHostClassService;
/**
* @type {?}
* @private
*/
NzColDirective.prototype.elementRef;
/** @type {?} */
NzColDirective.prototype.nzRowDirective;
/** @type {?} */
NzColDirective.prototype.renderer;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,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,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzColDirective, NzGridModule, NzRowDirective };
//# sourceMappingURL=ng-zorro-antd-grid.js.map