src/lib/markup-kit/utils/datepicker/datepicker/datepicker.component.ts
Datepicker Component for selecting dates.
This component allows users to pick a date from a calendar interface. It supports various configuration options such as language, date format, and date range.
<mefdev-datepicker
[labelContentText]="'Select your date'"
[lang]="'uk'"
[dateFormat]="'dd/MM/yyyy'"
[range]="{startYear: 1900, toYear: 300}"
[disabled]="false"
(dateChanged)="onDateChanged($event)"
[topOffset]="'20'"
[leftOffset]="'10'">
</mefdev-datepicker>
OnChanges
OnInit
selector | mefdev-datepicker |
styleUrls | ./datepicker.component.scss |
templateUrl | ./datepicker.component.html |
Properties |
Methods |
|
Inputs |
Outputs |
HostListeners |
constructor(datePipe: DatePipe, elementRef: ElementRef)
|
||||||||||||
Constructor for the DatepickerComponent class. It is used to access DOM elements.
Parameters :
|
dateFormat |
Type : string
|
Default value : 'EEE MMM dd yyyy'
|
The date format for displaying the selected date. Default value: 'EEE MMM dd yyyy'.
|
disabled |
Type : boolean
|
Default value : false
|
Whether the datepicker is disabled or not. Default value: false (enabled).
|
labelContentText |
Type : string
|
Label text for the datepicker. Default value: 'en' (English).
|
lang |
Type : string
|
Default value : 'en'
|
The language/locale for the datepicker. Default value: 'en' (English).
|
leftOffset |
Type : string
|
Default value : '10'
|
The left offset for positioning the datepicker. Default value: '10'.
|
topOffset |
Type : string
|
Default value : '20'
|
The top offset for positioning the datepicker. Default value: '20'.
|
onClick | ||||||||
onClick(event: MouseEvent)
|
||||||||
Decorators :
@HostListener('document:click', ['$event'])
|
||||||||
Host listener for document click events to handle calendar interaction. This function checks if a click event occurred within the calendar or input elements.
Parameters :
Returns :
void
|
Public onDateInput | ||||||||
onDateInput(event: any)
|
||||||||
Handle user input in the editable input field for date editing. This method captures the input value and stores it in the 'editedDate' variable. If the input matches the valid date format, it updates 'selectedDateMonth' and 'selectedDateYear' accordingly.
Parameters :
Returns :
void
|
selectDate | ||||||||
selectDate(date: Date)
|
||||||||
Select a date in the calendar interface and perform necessary updates. This method sets the selected date, formats it, closes the calendar, and emits a dateChanged event. It also updates the selected month and year dropdown values.
Parameters :
Returns :
void
|
toggleEdit |
toggleEdit()
|
Toggle the editing mode for the date input. When enabled, the user can edit the date directly in the input field.
Returns :
void
|
editedDate |
Type : string
|
Default value : ''
|
Track the edited date separately when in editing mode. Default value: An empty string. |
formattedDate |
Type : any
|
The formatted date for display in the input. Default value: Formatted representation of the selected date. |
isCalendarOpen |
Type : boolean
|
Default value : false
|
Flag to determine if the calendar is open or closed. Default value: false (closed). |
isMonthDropdownOpen |
Type : boolean
|
Default value : true
|
Flag to determine if the month dropdown is open or closed. Default value: true (open). |
isUserDateValid |
Type : boolean
|
Default value : true
|
A flag that checks whether a valid date has been entered and whether the entered date exists. If the two previous conditions are not true, the datepicker will be highlighted in red |
isYearDropdownOpen |
Type : boolean
|
Default value : true
|
Flag to determine if the year dropdown is open or closed. Default value: true (open). |
selectedDate |
Type : Date
|
Default value : new Date()
|
The currently selected date. Default value: Today's date. |
selectedDateMonth |
Type : number
|
Default value : this.selectedDate.getMonth()
|
The selected month (0-11). Default value: The month of the selected date. |
selectedDateYear |
Type : number
|
Default value : this.selectedDate.getFullYear()
|
The selected year. Default value: The year of the selected date. |
userInput |
Type : string
|
Default value : ''
|
The string entered by the user for date input. This variable stores the user's input as they type in the date field. |
years |
Type : number[]
|
An array of years for the year dropdown. Default value: An array of years within the specified range. |