ng-material-date-range-picker
Version:
This library provides the date range selection with two views.
116 lines (115 loc) • 4.35 kB
TypeScript
/**
* @(#)calendar.component.scss Sept 07, 2023
*
* Custom Calendar Component that manages two side-by-side
* month views with support for date range selection, hover
* highlighting, and navigation controls.
*
* @author Aakash Kumar
*/
import { AfterViewInit } from '@angular/core';
import { DateRange, MatCalendar } from '@angular/material/datepicker';
import * as i0 from "@angular/core";
export declare class CalendarComponent implements AfterViewInit {
firstViewStartDate: import("@angular/core").WritableSignal<Date>;
secondViewStartDate: import("@angular/core").WritableSignal<Date>;
secondViewMinDate: import("@angular/core").WritableSignal<Date>;
minDate: Date;
maxDate: Date;
firstCalendarView: MatCalendar<Date>;
secondCalendarView: MatCalendar<Date>;
private _selectedDates;
private isAllowHoverEvent;
private cdref;
private el;
private renderer;
/**
* Updates the selected date range and synchronizes both calendar views.
*/
set selectedDates(selectedDates: DateRange<Date> | null);
get selectedDates(): DateRange<Date> | null;
/**
* Lifecycle hook that is called after Angular has fully initialized
* the component's view (and child views).
*
* Used here to attach hover events and register active date change
* listeners once the calendar views are available in the DOM.
*/
ngAfterViewInit(): void;
/**
* Handles month selection in the first view.
*
* @param event - Selected month date
*/
monthSelected(viewName: string): void;
/**
* Updates the selected date range when a date is clicked.
*
* @param date - Date clicked by the user
*/
updateDateRangeSelection(date: Date | null): void;
/**
* Registers event handlers for active date changes on both calendar views.
*
* This method overrides the default `activeDate` property setter of each
* calendar view to ensure custom handlers are executed whenever the
* active date changes.
*/
private registerActiveDateChangeEvents;
/**
* Handles the event when the active date of the first calendar view changes.
*
* @param activeDate - Object containing `previous` and `current` date values.
*/
private onFirstViewActiveDateChange;
/**
* Handles the event when the active date of the second calendar view changes.
*
* @param activeDate - Object containing `previous` and `current` date values.
*/
private onSecondViewActiveDateChange;
/**
* Handles the "next" navigation event for the first calendar view.
*
* @param currDate - The currently active date in the first calendar view.
* @param force - Optional flag that can be used to enforce updates (not used in current logic).
*/
private handleFirstViewNextEvent;
/**
* Handles the "previous" navigation event for the first calendar view.
*
* @param activeDate - Object containing `previous` and `current` date values.
*/
private handleFirstViewPrevEvent;
/**
* Checks whether the previous date is greater than the current date.
*
* @param activeDate - Object containing `previous` and `current` date values.
* @returns `true` if the previous date is later than the current date, otherwise `false`.
*/
private isPrevious;
/**
* Attaches hover events to all date cells in the first view.
*/
private attachHoverEvent;
/**
* Removes active focus from the second view.
*
* @param classRef - Reference to this component
*/
private removeDefaultFocus;
/**
* Updates the selection range dynamically on hover.
*
* @param date - Hovered date
*/
private updateSelectionOnMouseHover;
/**
* Attaches hover events to given nodes to update range selection.
*
* @param nodes - Date cell nodes
*/
private addHoverEvents;
static ɵfac: i0.ɵɵFactoryDeclaration<CalendarComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<CalendarComponent, "lib-calendar", never, { "minDate": { "alias": "minDate"; "required": false; }; "maxDate": { "alias": "maxDate"; "required": false; }; "selectedDates": { "alias": "selectedDates"; "required": false; }; }, {}, never, never, false, never>;
}