yoyo-ng-modulewindy
Version:
服务于52ABP模板的前端开源的相关组件内容。整合了ng-alain和你NG ZORRO的内容
126 lines • 4.95 kB
JavaScript
import { Component, Input, TemplateRef, ElementRef, Renderer2, ContentChild, Host, Optional, ChangeDetectorRef, ChangeDetectionStrategy, } from '@angular/core';
import { NgModel } from '@angular/forms';
import { updateHostClass, toNumber } from 'yoyo-ng-module/util';
import { SHFWrapDirective } from './wrap.directive';
var SHFItemComponent = /** @class */ (function () {
function SHFItemComponent(wrap, el, ren, cd) {
this.wrap = wrap;
this.el = el;
this.ren = ren;
this.cd = cd;
this.invalid = false;
this._label = '';
this.controlClass = '';
}
Object.defineProperty(SHFItemComponent.prototype, "label", {
set: function (value) {
if (value instanceof TemplateRef) {
this._label = null;
this._labelTpl = value;
}
else {
this._label = value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(SHFItemComponent.prototype, "col", {
get: function () {
return this._span;
},
set: function (value) {
this._span = 24 / toNumber(value, 2);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SHFItemComponent.prototype, "labelWidth", {
get: function () {
return this._labelWidth;
},
set: function (value) {
this._labelWidth = toNumber(value, 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SHFItemComponent.prototype, "isHorizontal", {
// endregion
get: function () {
return !this.wrap || (this.wrap && this.wrap.nzLayout === 'horizontal');
},
enumerable: true,
configurable: true
});
SHFItemComponent.prototype.fixLabelWidth = function () {
var w = this.wrap;
if (typeof this.col === 'undefined') {
this.col = w ? w.col : 2;
}
if (typeof this.labelWidth === 'undefined') {
this.labelWidth = w ? w.labelWidth : 100;
}
if (!this.isHorizontal)
this._labelWidth = null;
return this;
};
SHFItemComponent.prototype.setClassMap = function () {
var classMap = (_a = {},
_a["ant-form-item"] = true,
_a["ant-col-" + this.col] = this.isHorizontal,
_a["ad-shf__item"] = true,
_a);
updateHostClass(this.el.nativeElement, this.ren, classMap);
this.cd.detectChanges();
var _a;
};
SHFItemComponent.prototype.ngOnChanges = function () {
this.fixLabelWidth().setClassMap();
};
SHFItemComponent.prototype.ngAfterViewInit = function () {
var _this = this;
this.fixLabelWidth().setClassMap();
if (this.ngModel) {
this.status$ = this.ngModel.statusChanges.subscribe(function (res) {
var status = res !== 'VALID';
if (_this.invalid === status)
return;
_this.invalid = status;
_this.cd.detectChanges();
});
}
};
SHFItemComponent.prototype.ngOnDestroy = function () {
if (this.status$) {
this.status$.unsubscribe();
}
};
SHFItemComponent.decorators = [
{ type: Component, args: [{
selector: 'shf-item',
template: "\n <div class=\"ant-form-item-label ad-shf__label\"\n [class.ad-shf__nolabel]=\"!_label && !_labelTpl\" [style.width.px]=\"labelWidth\">\n <ng-container *ngIf=\"_label; else _labelTpl\">{{_label}}</ng-container>\n</div>\n<div class=\"ant-form-item-control-wrapper ad-shf__control\">\n <div class=\"ant-form-item-control {{controlClass}}\" [class.has-error]=\"invalid\" [attr.title]=\"tip\">\n <ng-content></ng-content>\n </div>\n</div>\n ",
// templateUrl: './item.component.html',
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
},] },
];
/** @nocollapse */
SHFItemComponent.ctorParameters = function () { return [
{ type: SHFWrapDirective, decorators: [{ type: Optional }, { type: Host }] },
{ type: ElementRef },
{ type: Renderer2 },
{ type: ChangeDetectorRef }
]; };
SHFItemComponent.propDecorators = {
ngModel: [{ type: ContentChild, args: [NgModel,] }],
tip: [{ type: Input }],
label: [{ type: Input }],
col: [{ type: Input }],
labelWidth: [{ type: Input }],
controlClass: [{ type: Input }]
};
return SHFItemComponent;
}());
export { SHFItemComponent };
//# sourceMappingURL=item.component.js.map