2025-12-04 21:07:18 +03:30
|
|
|
import { Maybe } from '@/core';
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
ElementRef,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
Input,
|
|
|
|
|
OnInit,
|
|
|
|
|
Output,
|
|
|
|
|
ViewChild,
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
2025-12-15 18:00:45 +03:30
|
|
|
import dayjs from 'dayjs';
|
2025-12-04 21:07:18 +03:30
|
|
|
import flatpickr from 'flatpickr-wrap';
|
|
|
|
|
import { BaseOptions } from 'flatpickr-wrap/dist/types/options';
|
|
|
|
|
import { InputTextModule } from 'primeng/inputtext';
|
|
|
|
|
import { UikitFieldComponent } from '../uikit-field.component';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'uikit-datepicker',
|
|
|
|
|
standalone: true,
|
|
|
|
|
imports: [CommonModule, ReactiveFormsModule, InputTextModule, UikitFieldComponent],
|
|
|
|
|
templateUrl: './datepicker.component.html',
|
|
|
|
|
})
|
|
|
|
|
export class UikitFlatpickrJalaliComponent implements OnInit {
|
|
|
|
|
@Input() control?: FormControl<Maybe<string>>;
|
|
|
|
|
@Input() placeholder = 'انتخاب تاریخ';
|
|
|
|
|
@Input() label = 'تاریخ';
|
|
|
|
|
@Input() disabled = false;
|
|
|
|
|
@Input() name: string = 'datepicker';
|
|
|
|
|
@Input() options: Partial<BaseOptions> = {};
|
2025-12-10 16:54:25 +03:30
|
|
|
@Input() showLabel: boolean = true;
|
|
|
|
|
@Input() showErrors: boolean = true;
|
2025-12-04 21:07:18 +03:30
|
|
|
|
|
|
|
|
@Output() valueChange = new EventEmitter<string>();
|
|
|
|
|
|
|
|
|
|
@ViewChild('wrapper', { static: true }) wrapperRef!: ElementRef<HTMLElement>;
|
|
|
|
|
|
|
|
|
|
private fpInstance: any | null = null;
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.fpInstance = flatpickr(this.wrapperRef.nativeElement, {
|
|
|
|
|
...this.options,
|
2025-12-15 18:00:45 +03:30
|
|
|
now: dayjs().calendar('jalali').format('YYYY/MM/DD'),
|
2025-12-04 21:07:18 +03:30
|
|
|
altInputClass: 'p-inputtext w-full',
|
|
|
|
|
onChange: (selectedDates: Date[], dateStr: string) => {
|
|
|
|
|
this.valueChange.emit(dateStr);
|
|
|
|
|
if (this.control) this.control.setValue(dateStr);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|