ng-ytl-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
106 lines (90 loc) • 2.46 kB
text/typescript
import {
Component,
ElementRef,
HostBinding,
Input,
Renderer2,
ViewEncapsulation,
} from '@angular/core';
import { toBoolean } from '../util/convert';
import { AutoSizeType } from './nz-input.component';
export class NzInputDirectiveComponent {
private _disabled = false;
private _readonly = false;
size = 'default';
nativeElement: HTMLElement;
_autosize: boolean | AutoSizeType = false;
get nzSize(): string {
return this.size;
}
set nzSize(value: string) {
this.size = { large: 'lg', small: 'sm' }[ value ];
}
set nzDisabled(value: boolean) {
const disabled = toBoolean(value);
if (disabled) {
this._render.setAttribute(this.nativeElement, 'disabled', '');
} else {
this._render.removeAttribute(this.nativeElement, 'disabled');
}
this._disabled = disabled;
}
get nzDisabled(): boolean {
return this._disabled;
}
set nzReadonly(value: boolean) {
const readonly = toBoolean(value);
if (readonly) {
this._render.setAttribute(this.nativeElement, 'readonly', '');
} else {
this._render.removeAttribute(this.nativeElement, 'readonly');
}
this._readonly = readonly;
}
get nzReadonly(): boolean {
return this._readonly;
}
set nzAutosize(value: string | boolean | AutoSizeType) {
if (typeof value === 'string') {
this._autosize = true;
} else {
this._autosize = value;
}
if (this._autosize) {
this._render.setAttribute(this.nativeElement, 'autosize', '');
} else {
this._render.removeAttribute(this.nativeElement, 'autosize');
}
}
get nzAutosize(): string | boolean | AutoSizeType {
return this._autosize;
}
get setLgClass(): boolean {
return this.size === 'lg';
}
get setSmClass(): boolean {
return this.size === 'sm';
}
constructor(private _elementRef: ElementRef,
private _render: Renderer2) {
this.nativeElement = this._elementRef.nativeElement;
}
}