ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
152 lines (144 loc) • 5.6 kB
JavaScript
import { BidiModule } from '@angular/cdk/bidi';
import { CommonModule } from '@angular/common';
import { Directive, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, ContentChildren, TemplateRef, NgModule } from '@angular/core';
import { __decorate } from 'tslib';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { InputBoolean } from 'ng-zorro-antd/core/util';
/**
* 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
*/
class NzSpaceItemDirective {
constructor() { }
}
NzSpaceItemDirective.decorators = [
{ type: Directive, args: [{
selector: '[nzSpaceItem]'
},] }
];
NzSpaceItemDirective.ctorParameters = () => [];
/**
* 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
*/
const NZ_CONFIG_MODULE_NAME = 'space';
const SPACE_SIZE = {
small: 8,
middle: 16,
large: 24
};
class NzSpaceComponent {
constructor(nzConfigService, cdr) {
this.nzConfigService = nzConfigService;
this.cdr = cdr;
this._nzModuleName = NZ_CONFIG_MODULE_NAME;
this.nzDirection = 'horizontal';
this.nzSplit = null;
this.nzWrap = false;
this.nzSize = 'small';
this.spaceSize = SPACE_SIZE.small;
this.destroy$ = new Subject();
}
updateSpaceItems() {
const numberSize = typeof this.nzSize === 'string' ? SPACE_SIZE[this.nzSize] : this.nzSize;
this.spaceSize = numberSize / (this.nzSplit ? 2 : 1);
this.cdr.markForCheck();
}
ngOnChanges() {
this.updateSpaceItems();
this.mergedAlign = this.nzAlign === undefined && this.nzDirection === 'horizontal' ? 'center' : this.nzAlign;
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
ngAfterContentInit() {
this.updateSpaceItems();
this.items.changes.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.cdr.markForCheck();
});
}
}
NzSpaceComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-space, [nz-space]',
exportAs: 'NzSpace',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-content></ng-content>
<ng-template ngFor let-item let-last="last" let-index="index" [ngForOf]="items">
<div
class="ant-space-item"
[style.margin-bottom.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
[style.margin-right.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
>
<ng-container [ngTemplateOutlet]="item"></ng-container>
</div>
<span
*ngIf="nzSplit && !last"
class="ant-space-split"
[style.margin-bottom.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
[style.margin-right.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
>
<ng-template [ngTemplateOutlet]="nzSplit" [ngTemplateOutletContext]="{ $implicit: index }"></ng-template>
</span>
</ng-template>
`,
host: {
class: 'ant-space',
'[class.ant-space-horizontal]': 'nzDirection === "horizontal"',
'[class.ant-space-vertical]': 'nzDirection === "vertical"',
'[class.ant-space-align-start]': 'mergedAlign === "start"',
'[class.ant-space-align-end]': 'mergedAlign === "end"',
'[class.ant-space-align-center]': 'mergedAlign === "center"',
'[class.ant-space-align-baseline]': 'mergedAlign === "baseline"',
'[style.flex-wrap]': 'nzWrap ? "wrap" : null'
}
},] }
];
NzSpaceComponent.ctorParameters = () => [
{ type: NzConfigService },
{ type: ChangeDetectorRef }
];
NzSpaceComponent.propDecorators = {
nzDirection: [{ type: Input }],
nzAlign: [{ type: Input }],
nzSplit: [{ type: Input }],
nzWrap: [{ type: Input }],
nzSize: [{ type: Input }],
items: [{ type: ContentChildren, args: [NzSpaceItemDirective, { read: TemplateRef },] }]
};
__decorate([
InputBoolean()
], NzSpaceComponent.prototype, "nzWrap", void 0);
__decorate([
WithConfig()
], NzSpaceComponent.prototype, "nzSize", void 0);
/**
* 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
*/
class NzSpaceModule {
}
NzSpaceModule.decorators = [
{ type: NgModule, args: [{
declarations: [NzSpaceComponent, NzSpaceItemDirective],
exports: [NzSpaceComponent, NzSpaceItemDirective],
imports: [BidiModule, CommonModule]
},] }
];
/**
* 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
*/
/**
* 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
*/
/**
* Generated bundle index. Do not edit.
*/
export { NzSpaceComponent, NzSpaceItemDirective, NzSpaceModule };
//# sourceMappingURL=ng-zorro-antd-space.js.map