ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
60 lines • 6.4 kB
JavaScript
/**
* 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, ElementRef, Input, Renderer2 } from '@angular/core';
import { isNil } from 'ng-zorro-antd/core/util';
import { Subject } from 'rxjs';
export class NzThMeasureDirective {
constructor(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.changes$ = new Subject();
this.nzWidth = null;
this.colspan = null;
this.colSpan = null;
this.rowspan = null;
this.rowSpan = null;
}
ngOnChanges(changes) {
const { nzWidth, colspan, rowspan, colSpan, rowSpan } = changes;
if (colspan || colSpan) {
const col = this.colspan || this.colSpan;
if (!isNil(col)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'colspan', `${col}`);
}
else {
this.renderer.removeAttribute(this.elementRef.nativeElement, 'colspan');
}
}
if (rowspan || rowSpan) {
const row = this.rowspan || this.rowSpan;
if (!isNil(row)) {
this.renderer.setAttribute(this.elementRef.nativeElement, 'rowspan', `${row}`);
}
else {
this.renderer.removeAttribute(this.elementRef.nativeElement, 'rowspan');
}
}
if (nzWidth || colspan) {
this.changes$.next();
}
}
}
NzThMeasureDirective.decorators = [
{ type: Directive, args: [{
selector: 'th'
},] }
];
NzThMeasureDirective.ctorParameters = () => [
{ type: Renderer2 },
{ type: ElementRef }
];
NzThMeasureDirective.propDecorators = {
nzWidth: [{ type: Input }],
colspan: [{ type: Input }],
colSpan: [{ type: Input }],
rowspan: [{ type: Input }],
rowSpan: [{ type: Input }]
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGgtbWVhc3VyZS5kaXJlY3RpdmUuanMiLCJzb3VyY2VSb290IjoiL2hvbWUvdnN0cy93b3JrLzEvcy9jb21wb25lbnRzL3RhYmxlLyIsInNvdXJjZXMiOlsic3JjL2NlbGwvdGgtbWVhc3VyZS5kaXJl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