flexacore-ui-dev
Version:
Universal UI Framework for CDN, React, Angular, Vue, Svelte with TypeScript support
76 lines (66 loc) • 1.81 kB
text/typescript
import { Component, Input, Output, EventEmitter, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
export class FCInputComponent implements ControlValueAccessor {
type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' = 'text';
placeholder: string = '';
disabled: boolean = false;
readonly: boolean = false;
size: 'sm' | 'md' | 'lg' = 'md';
valueChange = new EventEmitter<string>();
value: string = '';
private onChange = (value: string) => {};
private onTouched = () => {};
get classes() {
return [
'fc-input',
`fc-input-${this.size}`
];
}
onInput(event: Event) {
const target = event.target as HTMLInputElement;
this.value = target.value;
this.onChange(this.value);
this.valueChange.emit(this.value);
}
onBlur() {
this.onTouched();
}
onFocus() {
// Focus event handling if needed
}
writeValue(value: string): void {
this.value = value || '';
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}
}