UNPKG

ng-zorro-antd

Version:

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

387 lines (376 loc) • 14.6 kB
import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Renderer2, EventEmitter, ChangeDetectorRef, ContentChild, Output, Input, Optional, ContentChildren, NgModule } from '@angular/core'; import { Directionality, BidiModule } from '@angular/cdk/bidi'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { __decorate, __metadata } from 'tslib'; import { Platform, PlatformModule } from '@angular/cdk/platform'; import { siderResponsiveMap, NzBreakpointService } from 'ng-zorro-antd/core/services'; import { toCssPixel, inNextTick, InputBoolean } from 'ng-zorro-antd/core/util'; import { NzMenuDirective } from 'ng-zorro-antd/menu'; import { LayoutModule } from '@angular/cdk/layout'; import { CommonModule } from '@angular/common'; import { NzIconModule } from 'ng-zorro-antd/icon'; /** * 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 NzContentComponent { constructor(elementRef, renderer) { this.elementRef = elementRef; this.renderer = renderer; this.renderer.addClass(this.elementRef.nativeElement, 'ant-layout-content'); } } NzContentComponent.decorators = [ { type: Component, args: [{ selector: 'nz-content', exportAs: 'nzContent', preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: ` <ng-content></ng-content> ` },] } ]; NzContentComponent.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 } ]; /** * 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 NzFooterComponent { constructor(elementRef, renderer) { this.elementRef = elementRef; this.renderer = renderer; this.renderer.addClass(this.elementRef.nativeElement, 'ant-layout-footer'); } } NzFooterComponent.decorators = [ { type: Component, args: [{ selector: 'nz-footer', exportAs: 'nzFooter', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: ` <ng-content></ng-content> ` },] } ]; NzFooterComponent.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 } ]; /** * 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 NzHeaderComponent { constructor(elementRef, renderer) { this.elementRef = elementRef; this.renderer = renderer; this.renderer.addClass(this.elementRef.nativeElement, 'ant-layout-header'); } } NzHeaderComponent.decorators = [ { type: Component, args: [{ selector: 'nz-header', exportAs: 'nzHeader', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false, template: ` <ng-content></ng-content> ` },] } ]; NzHeaderComponent.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 } ]; /** * 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 NzSiderComponent { constructor(platform, cdr, breakpointService, elementRef) { this.platform = platform; this.cdr = cdr; this.breakpointService = breakpointService; this.elementRef = elementRef; this.destroy$ = new Subject(); this.nzMenuDirective = null; this.nzCollapsedChange = new EventEmitter(); this.nzWidth = 200; this.nzTheme = 'dark'; this.nzCollapsedWidth = 80; this.nzBreakpoint = null; this.nzZeroTrigger = null; this.nzTrigger = undefined; this.nzReverseArrow = false; this.nzCollapsible = false; this.nzCollapsed = false; this.matchBreakPoint = false; this.flexSetting = null; this.widthSetting = null; // TODO: move to host after View Engine deprecation this.elementRef.nativeElement.classList.add('ant-layout-sider'); } updateStyleMap() { this.widthSetting = this.nzCollapsed ? `${this.nzCollapsedWidth}px` : toCssPixel(this.nzWidth); this.flexSetting = `0 0 ${this.widthSetting}`; this.cdr.markForCheck(); } updateMenuInlineCollapsed() { if (this.nzMenuDirective && this.nzMenuDirective.nzMode === 'inline' && this.nzCollapsedWidth !== 0) { this.nzMenuDirective.setInlineCollapsed(this.nzCollapsed); } } setCollapsed(collapsed) { if (collapsed !== this.nzCollapsed) { this.nzCollapsed = collapsed; this.nzCollapsedChange.emit(collapsed); this.updateMenuInlineCollapsed(); this.updateStyleMap(); this.cdr.markForCheck(); } } ngOnInit() { this.updateStyleMap(); if (this.platform.isBrowser) { this.breakpointService .subscribe(siderResponsiveMap, true) .pipe(takeUntil(this.destroy$)) .subscribe(map => { const breakpoint = this.nzBreakpoint; if (breakpoint) { inNextTick().subscribe(() => { this.matchBreakPoint = !map[breakpoint]; this.setCollapsed(this.matchBreakPoint); this.cdr.markForCheck(); }); } }); } } ngOnChanges(changes) { const { nzCollapsed, nzCollapsedWidth, nzWidth } = changes; if (nzCollapsed || nzCollapsedWidth || nzWidth) { this.updateStyleMap(); } if (nzCollapsed) { this.updateMenuInlineCollapsed(); } } ngAfterContentInit() { this.updateMenuInlineCollapsed(); } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzSiderComponent.decorators = [ { type: Component, args: [{ selector: 'nz-sider', exportAs: 'nzSider', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: ` <div class="ant-layout-sider-children"> <ng-content></ng-content> </div> <div *ngIf="nzCollapsible && nzTrigger !== null" nz-sider-trigger [matchBreakPoint]="matchBreakPoint" [nzCollapsedWidth]="nzCollapsedWidth" [nzCollapsed]="nzCollapsed" [nzBreakpoint]="nzBreakpoint" [nzReverseArrow]="nzReverseArrow" [nzTrigger]="nzTrigger" [nzZeroTrigger]="nzZeroTrigger" [siderWidth]="widthSetting" (click)="setCollapsed(!nzCollapsed)" ></div> `, host: { '[class.ant-layout-sider-zero-width]': `nzCollapsed && nzCollapsedWidth === 0`, '[class.ant-layout-sider-light]': `nzTheme === 'light'`, '[class.ant-layout-sider-dark]': `nzTheme === 'dark'`, '[class.ant-layout-sider-collapsed]': `nzCollapsed`, '[style.flex]': 'flexSetting', '[style.maxWidth]': 'widthSetting', '[style.minWidth]': 'widthSetting', '[style.width]': 'widthSetting' } },] } ]; NzSiderComponent.ctorParameters = () => [ { type: Platform }, { type: ChangeDetectorRef }, { type: NzBreakpointService }, { type: ElementRef } ]; NzSiderComponent.propDecorators = { nzMenuDirective: [{ type: ContentChild, args: [NzMenuDirective,] }], nzCollapsedChange: [{ type: Output }], nzWidth: [{ type: Input }], nzTheme: [{ type: Input }], nzCollapsedWidth: [{ type: Input }], nzBreakpoint: [{ type: Input }], nzZeroTrigger: [{ type: Input }], nzTrigger: [{ type: Input }], nzReverseArrow: [{ type: Input }], nzCollapsible: [{ type: Input }], nzCollapsed: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSiderComponent.prototype, "nzReverseArrow", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSiderComponent.prototype, "nzCollapsible", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzSiderComponent.prototype, "nzCollapsed", 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 NzLayoutComponent { constructor(elementRef, directionality) { this.elementRef = elementRef; this.directionality = directionality; this.dir = 'ltr'; this.destroy$ = new Subject(); // TODO: move to host after View Engine deprecation this.elementRef.nativeElement.classList.add('ant-layout'); } ngOnInit() { var _a; this.dir = this.directionality.value; (_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(takeUntil(this.destroy$)).subscribe((direction) => { this.dir = direction; }); } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzLayoutComponent.decorators = [ { type: Component, args: [{ selector: 'nz-layout', exportAs: 'nzLayout', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, template: ` <ng-content></ng-content> `, host: { '[class.ant-layout-rtl]': `dir === 'rtl'`, '[class.ant-layout-has-sider]': 'listOfNzSiderComponent.length > 0' } },] } ]; NzLayoutComponent.ctorParameters = () => [ { type: ElementRef }, { type: Directionality, decorators: [{ type: Optional }] } ]; NzLayoutComponent.propDecorators = { listOfNzSiderComponent: [{ type: ContentChildren, args: [NzSiderComponent,] }] }; /** * 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 NzSiderTriggerComponent { constructor() { this.nzCollapsed = false; this.nzReverseArrow = false; this.nzZeroTrigger = null; this.nzTrigger = undefined; this.matchBreakPoint = false; this.nzCollapsedWidth = null; this.siderWidth = null; this.nzBreakpoint = null; this.isZeroTrigger = false; this.isNormalTrigger = false; } updateTriggerType() { this.isZeroTrigger = this.nzCollapsedWidth === 0 && ((this.nzBreakpoint && this.matchBreakPoint) || !this.nzBreakpoint); this.isNormalTrigger = this.nzCollapsedWidth !== 0; } ngOnInit() { this.updateTriggerType(); } ngOnChanges() { this.updateTriggerType(); } } NzSiderTriggerComponent.decorators = [ { type: Component, args: [{ selector: '[nz-sider-trigger]', exportAs: 'nzSiderTrigger', preserveWhitespaces: false, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: ` <ng-container *ngIf="isZeroTrigger"> <ng-template [ngTemplateOutlet]="nzZeroTrigger || defaultZeroTrigger"></ng-template> </ng-container> <ng-container *ngIf="isNormalTrigger"> <ng-template [ngTemplateOutlet]="nzTrigger || defaultTrigger"></ng-template> </ng-container> <ng-template #defaultTrigger> <i nz-icon [nzType]="nzCollapsed ? 'right' : 'left'" *ngIf="!nzReverseArrow"></i> <i nz-icon [nzType]="nzCollapsed ? 'left' : 'right'" *ngIf="nzReverseArrow"></i> </ng-template> <ng-template #defaultZeroTrigger> <i nz-icon nzType="bars"></i> </ng-template> `, host: { '[class.ant-layout-sider-trigger]': 'isNormalTrigger', '[style.width]': 'isNormalTrigger ? siderWidth : null', '[class.ant-layout-sider-zero-width-trigger]': 'isZeroTrigger', '[class.ant-layout-sider-zero-width-trigger-right]': 'isZeroTrigger && nzReverseArrow', '[class.ant-layout-sider-zero-width-trigger-left]': 'isZeroTrigger && !nzReverseArrow' } },] } ]; NzSiderTriggerComponent.propDecorators = { nzCollapsed: [{ type: Input }], nzReverseArrow: [{ type: Input }], nzZeroTrigger: [{ type: Input }], nzTrigger: [{ type: Input }], matchBreakPoint: [{ type: Input }], nzCollapsedWidth: [{ type: Input }], siderWidth: [{ type: Input }], nzBreakpoint: [{ type: Input }] }; /** * 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 NzLayoutModule { } NzLayoutModule.decorators = [ { type: NgModule, args: [{ declarations: [NzLayoutComponent, NzHeaderComponent, NzContentComponent, NzFooterComponent, NzSiderComponent, NzSiderTriggerComponent], exports: [NzLayoutComponent, NzHeaderComponent, NzContentComponent, NzFooterComponent, NzSiderComponent], imports: [BidiModule, CommonModule, NzIconModule, LayoutModule, PlatformModule] },] } ]; /** * 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 { NzContentComponent, NzFooterComponent, NzHeaderComponent, NzLayoutComponent, NzLayoutModule, NzSiderComponent, NzSiderTriggerComponent as ɵNzSiderTriggerComponent }; //# sourceMappingURL=ng-zorro-antd-layout.js.map