@nbxx/nb-input
Version:
Angular - nbinput
84 lines • 2.8 kB
JavaScript
import { Component, EventEmitter, forwardRef, Input, Output } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { NbFieldType } from "./nbinput.entity";
export class NbinputTextComponent {
constructor() {
this.FieldType = NbFieldType;
this.onTouchedCallback = () => { };
this.onChangeCallback = (_) => { };
this.disabled = false;
this.readonly = false;
this.fixed = false;
this.type = NbFieldType.Text;
this.placeholder = '';
this.onChange = new EventEmitter();
}
registerOnChange(fn) { if (fn)
this.onChangeCallback = fn; }
registerOnTouched(fn) { if (fn)
this.onTouchedCallback = fn; }
setDisabledState(isDisabled) { this.disabled = isDisabled; }
writeValue(obj) {
this.data = obj;
}
onBlur() { this.onTouchedCallback(); }
get value() {
return this.data;
}
;
set value(v) {
if (v !== this.data) {
this.data = v;
this.onChangeCallback(v);
}
}
changed(event) {
this.onChange.emit(this.data);
this.onChangeCallback(this.data);
}
}
NbinputTextComponent.decorators = [
{ type: Component, args: [{
selector: 'nbinput-text',
template: `
<ng-container *ngIf="readonly;else ELSEBLOCK">
<span>{{data&&data!=''?data:'-'}}</span>
</ng-container>
<ng-template #ELSEBLOCK>
<textarea *ngIf="type==FieldType.Area"
class="form-control"
[ngClass]="{'fixed':fixed}"
[placeholder]="placeholder"
[(ngModel)]="data"
[attr.disabled]="disabled?true:null"
(change)="changed($event)"
rows="3"></textarea>
<input *ngIf="type==FieldType.Text"
(change)="changed($event)"
class="form-control"
[placeholder]="placeholder"
[attr.disabled]="disabled?true:null"
[(ngModel)]="data" />
</ng-template>
`,
styles: [`
textarea{min-height:35px;min-width:80px}.fixed{height:215px}input{min-width:80px}
`],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NbinputTextComponent),
multi: true
}
]
},] },
];
NbinputTextComponent.propDecorators = {
readonly: [{ type: Input }],
data: [{ type: Input }],
fixed: [{ type: Input }],
type: [{ type: Input }],
placeholder: [{ type: Input }],
onChange: [{ type: Output }]
};
//# sourceMappingURL=nbinput-text.component.js.map