UNPKG

ng-zorro-antd

Version:

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

75 lines 9.48 kB
/** * 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 */ import { Directive, Inject, Input, Optional } from '@angular/core'; import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; import { reqAnimFrame } from 'ng-zorro-antd/core/polyfill'; import * as i0 from "@angular/core"; export class NzTabsInkBarDirective { get _animated() { return this.animationMode !== 'NoopAnimations' && this.animated; } constructor(elementRef, ngZone, animationMode) { this.elementRef = elementRef; this.ngZone = ngZone; this.animationMode = animationMode; this.position = 'horizontal'; this.animated = true; } alignToElement(element) { this.ngZone.runOutsideAngular(() => { reqAnimFrame(() => this.setStyles(element)); }); } setStyles(element) { const inkBar = this.elementRef.nativeElement; if (this.position === 'horizontal') { inkBar.style.top = ''; inkBar.style.height = ''; inkBar.style.left = this.getLeftPosition(element); inkBar.style.width = this.getElementWidth(element); } else { inkBar.style.left = ''; inkBar.style.width = ''; inkBar.style.top = this.getTopPosition(element); inkBar.style.height = this.getElementHeight(element); } } getLeftPosition(element) { return element ? `${element.offsetLeft || 0}px` : '0'; } getElementWidth(element) { return element ? `${element.offsetWidth || 0}px` : '0'; } getTopPosition(element) { return element ? `${element.offsetTop || 0}px` : '0'; } getElementHeight(element) { return element ? `${element.offsetHeight || 0}px` : '0'; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzTabsInkBarDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: ANIMATION_MODULE_TYPE, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.4", type: NzTabsInkBarDirective, isStandalone: true, selector: "nz-tabs-ink-bar, [nz-tabs-ink-bar]", inputs: { position: "position", animated: "animated" }, host: { properties: { "class.ant-tabs-ink-bar-animated": "_animated" }, classAttribute: "ant-tabs-ink-bar" }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzTabsInkBarDirective, decorators: [{ type: Directive, args: [{ selector: 'nz-tabs-ink-bar, [nz-tabs-ink-bar]', host: { class: 'ant-tabs-ink-bar', '[class.ant-tabs-ink-bar-animated]': '_animated' }, standalone: true }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE] }] }], propDecorators: { position: [{ type: Input }], animated: [{ type: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFicy1pbmstYmFyLmRpcmVjdGl2ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL2NvbXBvbmVudHMvdGFicy90YWJzLWluay1iYXIuZGlyZWN0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7R0FHRztBQUVILE9BQU8sRUFBRSxTQUFTLEVBQWMsTUFBTSxFQUFFLEtBQUssRUFBVSxRQUFRLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDdkYsT0FBTyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sc0NBQXNDLENBQUM7QUFFN0UsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDOztBQVkzRCxNQUFNLE9BQU8scUJBQXFCO0lBSWhDLElBQUksU0FBUztRQUNYLE9BQU8sSUFBSSxDQUFDLGFBQWEsS0FBSyxnQkFBZ0IsSUFBSSxJQUFJLENBQUMsUUFBUSxDQUFDO0lBQ2xFLENBQUM7SUFFRCxZQUNVLFVBQW1DLEVBQ25DLE1BQWMsRUFDNEIsYUFBc0I7UUFGaEUsZUFBVSxHQUFWLFVBQVUsQ0FBeUI7UUFDbkMsV0FBTSxHQ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