2025-12-04 21:07:18 +03:30
|
|
|
import { Maybe } from '@/core';
|
|
|
|
|
import { UikitFieldComponent } from '@/uikit/uikit-field.component';
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
|
|
|
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
|
2025-12-27 20:35:02 +03:30
|
|
|
import { InputGroupModule } from 'primeng/inputgroup';
|
|
|
|
|
import { InputGroupAddon } from 'primeng/inputgroupaddon';
|
|
|
|
|
import { InputNumberModule } from 'primeng/inputnumber';
|
2025-12-04 21:07:18 +03:30
|
|
|
import { InputTextModule } from 'primeng/inputtext';
|
2025-12-04 23:34:00 +03:30
|
|
|
import { ToggleSwitch } from 'primeng/toggleswitch';
|
2025-12-04 21:07:18 +03:30
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-input',
|
|
|
|
|
standalone: true,
|
2025-12-27 20:35:02 +03:30
|
|
|
imports: [
|
|
|
|
|
CommonModule,
|
|
|
|
|
ReactiveFormsModule,
|
|
|
|
|
InputTextModule,
|
|
|
|
|
InputGroupModule,
|
|
|
|
|
UikitFieldComponent,
|
|
|
|
|
ToggleSwitch,
|
|
|
|
|
InputGroupAddon,
|
|
|
|
|
InputNumberModule,
|
|
|
|
|
],
|
2025-12-04 21:07:18 +03:30
|
|
|
templateUrl: './input.component.html',
|
|
|
|
|
})
|
|
|
|
|
export class InputComponent {
|
2025-12-27 20:35:02 +03:30
|
|
|
@Input() type:
|
|
|
|
|
| 'simple'
|
|
|
|
|
| 'postalCode'
|
|
|
|
|
| 'mobile'
|
|
|
|
|
| 'phone'
|
|
|
|
|
| 'email'
|
|
|
|
|
| 'checkbox'
|
|
|
|
|
| 'switch'
|
|
|
|
|
| 'price' = 'simple';
|
2025-12-04 21:07:18 +03:30
|
|
|
@Input() control!: FormControl<Maybe<any>>;
|
|
|
|
|
@Input() name!: string;
|
|
|
|
|
@Input() label: string = '';
|
|
|
|
|
@Input() customPlaceholder?: string;
|
|
|
|
|
@Input() required = false;
|
|
|
|
|
@Input() disabled = false;
|
|
|
|
|
@Input() size?: 'small' | 'large';
|
|
|
|
|
@Input() autocomplete?: string = 'off';
|
2025-12-09 20:17:00 +03:30
|
|
|
@Input() showErrors = false;
|
2025-12-27 20:35:02 +03:30
|
|
|
@Input() hint?: string;
|
|
|
|
|
@Output() valueChange = new EventEmitter<string | number>();
|
2025-12-04 21:07:18 +03:30
|
|
|
|
|
|
|
|
onInput(ev: Event) {
|
|
|
|
|
const v = (ev.target as HTMLInputElement).value;
|
2025-12-27 20:35:02 +03:30
|
|
|
this.valueChange.emit(this.type === 'price' ? parseFloat(v) : v);
|
2025-12-04 21:07:18 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get placeholder(): string | null {
|
|
|
|
|
if (this.customPlaceholder) return this.customPlaceholder;
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case 'mobile':
|
|
|
|
|
return '09xxxxxxxx';
|
|
|
|
|
case 'postalCode':
|
|
|
|
|
return 'کد پستی (۱۰ رقم)';
|
|
|
|
|
case 'phone':
|
|
|
|
|
return 'شماره تلفن';
|
|
|
|
|
case 'email':
|
|
|
|
|
return 'آدرس ایمیل خود را وارد کنید';
|
2025-12-27 20:35:02 +03:30
|
|
|
case 'price':
|
|
|
|
|
return 'مبلغ';
|
2025-12-04 21:07:18 +03:30
|
|
|
default:
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get inputMode(): string | null {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case 'mobile':
|
|
|
|
|
case 'phone':
|
|
|
|
|
case 'postalCode':
|
2025-12-27 20:35:02 +03:30
|
|
|
case 'price':
|
2025-12-04 21:07:18 +03:30
|
|
|
return 'numeric';
|
|
|
|
|
default:
|
|
|
|
|
return 'text';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get maxLength(): number | null {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case 'mobile':
|
|
|
|
|
return 11;
|
|
|
|
|
case 'postalCode':
|
|
|
|
|
return 10;
|
|
|
|
|
case 'phone':
|
|
|
|
|
return 11;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get inputClass(): string {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case 'mobile':
|
|
|
|
|
case 'phone':
|
2025-12-27 20:35:02 +03:30
|
|
|
case 'price':
|
2025-12-04 21:07:18 +03:30
|
|
|
return 'ltrInput';
|
|
|
|
|
case 'email':
|
|
|
|
|
case 'postalCode':
|
|
|
|
|
return 'ltrInput rtlPlaceholder';
|
|
|
|
|
default:
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get htmlType(): string {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case 'email':
|
|
|
|
|
return 'email';
|
|
|
|
|
default:
|
|
|
|
|
return 'text';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get isRequired(): boolean {
|
|
|
|
|
return this.required || this.control.hasValidator(Validators.required);
|
|
|
|
|
}
|
|
|
|
|
}
|