UNPKG

ng-material-date-range-picker

Version:
796 lines (784 loc) 50 kB
import * as i0 from '@angular/core'; import { Component, ChangeDetectionStrategy, Input, ViewChild, EventEmitter, Output, NgModule } from '@angular/core'; import * as i1$1 from '@angular/common'; import { DatePipe, CommonModule } from '@angular/common'; import * as i1 from '@angular/material/datepicker'; import { DateRange, MatDatepickerModule } from '@angular/material/datepicker'; import * as i2 from '@angular/material/input'; import { MatInputModule } from '@angular/material/input'; import * as i3 from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field'; import * as i4 from '@angular/cdk/overlay'; import { OverlayModule } from '@angular/cdk/overlay'; import * as i5 from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon'; import * as i6 from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button'; import * as i7 from '@angular/material/list'; import { MatListModule } from '@angular/material/list'; import * as i8 from '@angular/material/tooltip'; import { MatTooltipModule } from '@angular/material/tooltip'; import { FormsModule } from '@angular/forms'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { MatNativeDateModule } from '@angular/material/core'; /** * @(#)date-filter-enum.ts Sept 08, 2023 * * @author Aakash Kumar */ var DEFAULT_DATE_OPTION_ENUM; (function (DEFAULT_DATE_OPTION_ENUM) { DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["DATE_DIFF"] = 1] = "DATE_DIFF"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["LAST_MONTH"] = 2] = "LAST_MONTH"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["THIS_MONTH"] = 3] = "THIS_MONTH"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["YEAR_TO_DATE"] = 4] = "YEAR_TO_DATE"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["CUSTOM"] = 5] = "CUSTOM"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["MONTH_TO_DATE"] = 6] = "MONTH_TO_DATE"; DEFAULT_DATE_OPTION_ENUM[DEFAULT_DATE_OPTION_ENUM["WEEK_TO_DATE"] = 7] = "WEEK_TO_DATE"; })(DEFAULT_DATE_OPTION_ENUM || (DEFAULT_DATE_OPTION_ENUM = {})); /** * @(#)default-date-options.ts Sept 08, 2023 * * @author Aakash Kumar */ const DEFAULT_DATE_OPTIONS = [ { optionLabel: 'Today', optionKey: DEFAULT_DATE_OPTION_ENUM.DATE_DIFF, dateDiff: 0, isSelected: false, isVisible: true, }, { optionLabel: 'Yesterday', optionKey: DEFAULT_DATE_OPTION_ENUM.DATE_DIFF, dateDiff: -1, isSelected: false, isVisible: true, }, { optionLabel: 'Last 7 Days', optionKey: DEFAULT_DATE_OPTION_ENUM.DATE_DIFF, dateDiff: -7, isSelected: false, isVisible: true, }, { optionLabel: 'Last 30 Days', optionKey: DEFAULT_DATE_OPTION_ENUM.DATE_DIFF, dateDiff: -30, isSelected: false, isVisible: true, }, { optionLabel: 'Last Month', optionKey: DEFAULT_DATE_OPTION_ENUM.LAST_MONTH, dateDiff: 0, isSelected: false, isVisible: true, }, { optionLabel: 'This Month', optionKey: DEFAULT_DATE_OPTION_ENUM.THIS_MONTH, dateDiff: 0, isSelected: false, isVisible: true, }, { optionLabel: 'Month To Date', optionKey: DEFAULT_DATE_OPTION_ENUM.MONTH_TO_DATE, dateDiff: 0, isSelected: false, isVisible: true, }, { optionLabel: 'Week To Date', optionKey: DEFAULT_DATE_OPTION_ENUM.WEEK_TO_DATE, dateDiff: 0, isSelected: false, isVisible: false, }, { optionLabel: 'Year To Date', optionKey: DEFAULT_DATE_OPTION_ENUM.YEAR_TO_DATE, dateDiff: 0, isSelected: false, isVisible: true, }, { optionLabel: 'Custom Range', optionKey: DEFAULT_DATE_OPTION_ENUM.CUSTOM, dateDiff: 0, isSelected: false, isVisible: true, }, ]; class CalendarViewData { } /** * @(#)calendar.component.scss Sept 07, 2023 * @author Aakash Kumar */ class CalendarComponent { constructor(cdref, el, renderer) { this.cdref = cdref; this.el = el; this.renderer = renderer; this.isAllowHoverEvent = false; } ngOnInit() { this.initFirstCalendar(); this.initSecondCalendar(); } ngAfterViewInit() { this.addFirstCalendarButtonEvents(); this.attachHoverEventOnFirstViewDates(); this.attachHoverEventOnSecondViewDates(); this.addSecondCalendarButtonEvents(); } /** * This method gets all eligible cells on second view for hover event. */ attachHoverEventOnSecondViewDates() { const nodes = this.el.nativeElement.querySelectorAll('#secondCalendarView .mat-calendar-body-cell'); setTimeout(() => this.addHoverEvents(nodes), 200); } /** * This method handles second calendar view month selection. * * @param event Date */ secondViewMonthSelected(event) { this.removeDefaultFocus(this); setTimeout(() => { this.attachHoverEventOnSecondViewDates(); }, 300); } /** * This method handles first calendar view month selection. * * @param event Date */ monthSelected(event) { this.secondCalendarView._goToDateInView(event, 'year'); setTimeout(() => this.handleFirstCalendarNextEvent(this, true), 1); } /** * This method updates the date selection range. * * @param date Date */ updateDateRangeSelection(date) { const selectedDates = this.selectedDates; if (!selectedDates || (selectedDates.start && selectedDates.end) || (selectedDates.start && date && selectedDates.start > date)) { this.selectedDates = new DateRange(date, null); this.isAllowHoverEvent = true; } else { this.isAllowHoverEvent = false; this.selectedDates = new DateRange(selectedDates.start, date); } this.cdref.markForCheck(); } /** * This method handles First calendar prev button event. * @param classRef CalendarComponent */ handleFirstCalDatePrevEvent(classRef) { const leftDateCalender = classRef.firstCalendarView; if (leftDateCalender.currentView.toLocaleLowerCase() === 'month') { const date = new Date(leftDateCalender['_clampedActiveDate']); classRef.secondCalendarView.minDate = classRef.getFirstDateOfNextMonth(date); classRef.cdref.markForCheck(); } classRef.attachHoverEventOnFirstViewDates(); } /** * This method gets all eligible cells on first view for hover event. */ attachHoverEventOnFirstViewDates() { const nodes = this.el.nativeElement.querySelectorAll('#firstCalendarView .mat-calendar-body-cell'); setTimeout(() => this.addHoverEvents(nodes), 200); } /** * This method handle the next button event. * * @param classRef CalendarComponent * @param isForced boolean */ handleFirstCalendarNextEvent(classRef, isForced = false) { const firstCalendar = classRef.firstCalendarView; if (firstCalendar.currentView.toLocaleLowerCase() === 'month' || isForced) { const date = new Date(firstCalendar['_clampedActiveDate']); const nextMonthDate = classRef.getFirstDateOfNextMonth(date); classRef.secondCalendarView.minDate = nextMonthDate; classRef.secondCalendarView._goToDateInView(nextMonthDate, 'month'); classRef.removeDefaultFocus(classRef); classRef.cdref.markForCheck(); } setTimeout(() => { classRef.attachHoverEventOnFirstViewDates(); classRef.attachHoverEventOnSecondViewDates(); }, 300); } /** * This method remove active focus on second view. * * @param classRef CalendarComponent */ removeDefaultFocus(classRef) { setTimeout(() => { const btn = classRef.el.nativeElement.querySelectorAll('#secondCalendarView button.mat-calendar-body-active'); if (btn?.length) { btn[0].blur(); } }, 1); } /** * This method attaches next and prev events on buttons. * */ addFirstCalendarButtonEvents() { const monthPrevBtn = this.el.nativeElement.querySelectorAll('#firstCalendarView .mat-calendar-previous-button'); const monthNextBtn = this.el.nativeElement.querySelectorAll('#firstCalendarView .mat-calendar-next-button'); this.attachClickEvent(monthPrevBtn, this.handleFirstCalDatePrevEvent); this.attachClickEvent(monthNextBtn, this.handleFirstCalendarNextEvent); } /** * This method attaches next and prev events on buttons. * */ addSecondCalendarButtonEvents() { const monthPrevBtn = this.el.nativeElement.querySelectorAll('#secondCalendarView .mat-calendar-previous-button'); const monthNextBtn = this.el.nativeElement.querySelectorAll('#secondCalendarView .mat-calendar-next-button'); if (!monthPrevBtn || !monthNextBtn) { return; } this.attachSecondViewClickEvent(monthPrevBtn); this.attachSecondViewClickEvent(monthNextBtn); } /** * This method attach click event of next and prev button on second view. * */ attachSecondViewClickEvent(nodes) { Array.from(nodes).forEach((button) => { this.renderer.listen(button, 'click', () => { this.attachHoverEventOnSecondViewDates(); }); }); } /** * This method will update the range selection on mouse hover event. * * @param date Date */ updateSelectionOnMouseHover(date) { const selectedDates = this.selectedDates; if (selectedDates?.start && date && selectedDates.start < date) { const dateRange = new DateRange(selectedDates.start, date); this.firstCalendarView.selected = dateRange; this.secondCalendarView.selected = dateRange; this.firstCalendarView['_changeDetectorRef'].markForCheck(); this.secondCalendarView['_changeDetectorRef'].markForCheck(); this.isAllowHoverEvent = true; } } /** * This method attach hover event on specified nodes. * * @param nodes any */ addHoverEvents(nodes) { if (!nodes) { return; } Array.from(nodes).forEach((button) => { this.renderer.listen(button, 'mouseover', (event) => { if (this.isAllowHoverEvent) { const date = new Date(event.target['ariaLabel']); this.updateSelectionOnMouseHover(date); } }); }); } /** * This method attach the next and prev events on specified nodes. * * @param nodes any * @param handler Function */ attachClickEvent(nodes, handler) { if (!nodes) { return; } Array.from(nodes).forEach((button) => { this.renderer.listen(button, 'click', () => { handler(this); }); }); } /** * This method initialize data for first calendar view. */ initFirstCalendar() { this.firstCalendarViewData = new CalendarViewData(); this.firstCalendarViewData.startDate = new Date(); } /** * This method initialize data for second calendar view. */ initSecondCalendar() { const currDate = new Date(); this.secondCalendarViewData = new CalendarViewData(); this.secondCalendarViewData.minDate = this.getFirstDateOfNextMonth(currDate); currDate.setMonth(currDate.getMonth() + 1); this.secondCalendarViewData.startDate = this.selectedDates?.end ? this.selectedDates.end : currDate; } /** * This method returns the next months first date. * * @param currDate Date * @returns Date */ getFirstDateOfNextMonth(currDate) { return new Date(currDate.getFullYear(), currDate.getMonth() + 1, 1); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: CalendarComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.6", type: CalendarComponent, selector: "lib-calendar", inputs: { selectedDates: "selectedDates", minDate: "minDate", maxDate: "maxDate" }, viewQueries: [{ propertyName: "firstCalendarView", first: true, predicate: ["firstCalendarView"], descendants: true }, { propertyName: "secondCalendarView", first: true, predicate: ["secondCalendarView"], descendants: true }], ngImport: i0, template: "<!--**\r\n * @(#)calendar.component.html Sept 07, 2023\r\n\r\n * @author Aakash Kumar\r\n *-->\r\n<div class=\"calendar-container\">\r\n <div class=\"first-view\">\r\n <mat-calendar id=\"firstCalendarView\" #firstCalendarView [startAt]=\"firstCalendarViewData.startDate\"\r\n [selected]=\"selectedDates\" (selectedChange)=\"updateDateRangeSelection($event)\"\r\n (monthSelected)=\"monthSelected($event)\" [minDate]=\"minDate\" [maxDate]=\"maxDate\"></mat-calendar>\r\n </div>\r\n <div class=\"second-view\">\r\n <mat-calendar id=\"secondCalendarView\" #secondCalendarView [startAt]=\"secondCalendarViewData.startDate\"\r\n [minDate]=\"secondCalendarViewData.minDate\" [maxDate]=\"maxDate\" [selected]=\"selectedDates\"\r\n (selectedChange)=\"updateDateRangeSelection($event)\"\r\n (monthSelected)=\" secondViewMonthSelected($event)\"></mat-calendar>\r\n </div>\r\n</div>\r\n", styles: [".mat-calendar{min-width:250px}.calendar-container{width:100%;display:block;float:left}.first-view,.second-view{width:50%;display:block;float:left}.first-view,.second-view{margin-top:.5rem}@media (max-width: 490px){.first-view,.second-view{width:100%}}\n"], dependencies: [{ kind: "component", type: i1.MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: CalendarComponent, decorators: [{ type: Component, args: [{ selector: 'lib-calendar', changeDetection: ChangeDetectionStrategy.OnPush, template: "<!--**\r\n * @(#)calendar.component.html Sept 07, 2023\r\n\r\n * @author Aakash Kumar\r\n *-->\r\n<div class=\"calendar-container\">\r\n <div class=\"first-view\">\r\n <mat-calendar id=\"firstCalendarView\" #firstCalendarView [startAt]=\"firstCalendarViewData.startDate\"\r\n [selected]=\"selectedDates\" (selectedChange)=\"updateDateRangeSelection($event)\"\r\n (monthSelected)=\"monthSelected($event)\" [minDate]=\"minDate\" [maxDate]=\"maxDate\"></mat-calendar>\r\n </div>\r\n <div class=\"second-view\">\r\n <mat-calendar id=\"secondCalendarView\" #secondCalendarView [startAt]=\"secondCalendarViewData.startDate\"\r\n [minDate]=\"secondCalendarViewData.minDate\" [maxDate]=\"maxDate\" [selected]=\"selectedDates\"\r\n (selectedChange)=\"updateDateRangeSelection($event)\"\r\n (monthSelected)=\" secondViewMonthSelected($event)\"></mat-calendar>\r\n </div>\r\n</div>\r\n", styles: [".mat-calendar{min-width:250px}.calendar-container{width:100%;display:block;float:left}.first-view,.second-view{width:50%;display:block;float:left}.first-view,.second-view{margin-top:.5rem}@media (max-width: 490px){.first-view,.second-view{width:100%}}\n"] }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { selectedDates: [{ type: Input }], minDate: [{ type: Input }], maxDate: [{ type: Input }], firstCalendarView: [{ type: ViewChild, args: ['firstCalendarView'] }], secondCalendarView: [{ type: ViewChild, args: ['secondCalendarView'] }] } }); /** * @(#)ng-date-picker.component.ts Sept 05, 2023 * * @author Aakash Kumar */ class NgDatePickerComponent { constructor(cdref, el) { this.cdref = cdref; this.el = el; this.isDateOptionList = false; this.isCustomRange = false; this.inputLabel = 'Date Range'; this.staticOptionId = 'static-options'; this.dynamicOptionId = 'dynamic-options'; this.calendarId = 'custom-calendar'; this.enableDefaultOptions = true; this.dateFormat = 'dd/MM/yyyy'; this.isShowStaticDefaultOptions = false; this.hideDefaultOptions = false; this.cdkConnectedOverlayOffsetX = 0; this.cdkConnectedOverlayOffsetY = 0; this.listCdkConnectedOverlayOffsetY = 0; this.listCdkConnectedOverlayOffsetX = 0; this.selectedOptionIndex = 3; this.displaySelectedLabel = false; this.cdkConnectedOverlayPush = true; this.cdkConnectedOverlayPositions = []; // default min date is current date - 10 years. this.minDate = new Date(new Date().setFullYear(new Date().getFullYear() - 10)); // default max date is current date - 10 years. this.maxDate = new Date(new Date().setFullYear(new Date().getFullYear() + 10)); this._dateDropDownOptions = []; this.onDateSelectionChanged = new EventEmitter(); this.dateListOptions = new EventEmitter(); } set dateDropDownOptions(defaultDateList) { if (this.enableDefaultOptions) { this._dateDropDownOptions = this.getClone(DEFAULT_DATE_OPTIONS).concat(defaultDateList); } else { this._dateDropDownOptions = defaultDateList; } } get dateDropDownOptions() { return this._dateDropDownOptions ?? []; } ngOnInit() { if (!this._dateDropDownOptions.length && this.enableDefaultOptions) { this._dateDropDownOptions = this.getClone(DEFAULT_DATE_OPTIONS); this._dateDropDownOptions[this.selectedOptionIndex].isSelected = true; } this.dateListOptions.emit(this.dateDropDownOptions); } ngAfterViewInit() { this.updateDefaultDatesValues(); } /** * This method toggles the visibility of default date option's List. */ toggleDateOptionSelectionList(event) { if (event) { event.preventDefault(); event.stopImmediatePropagation(); } const selectedOption = this.dateDropDownOptions.filter((option) => option.isSelected); if (selectedOption.length && selectedOption[0].optionKey === DEFAULT_DATE_OPTION_ENUM.CUSTOM) { this.toggleCustomDateRangeView(); } else { this.isDateOptionList = !this.isDateOptionList; } } /** * This method updates the date range on button click. * * @param input HTMLInputElement * @param selectedDates DateRange<Date> */ updateCustomRange(input, selectedDates) { this.updateSelectedDates(input, selectedDates?.start ?? new Date(), selectedDates?.end ?? new Date(), null); if (this.isCustomRange) { this.resetOptionSelection(); this.selectCustomOption(); this.isCustomRange = false; } } /** * This method update the date on specified option. * * @param option ISelectDateOption * @param input HTMLInputElement */ updateSelection(option, input) { this.isDateOptionList = false; if (option.optionKey !== DEFAULT_DATE_OPTION_ENUM.CUSTOM) { this.isCustomRange = false; this.resetOptionSelection(option); this.updateDateOnOptionSelect(option, input); } else { this.isCustomRange = true; } this.cdref.markForCheck(); } // This method sets custom option as selected. selectCustomOption() { const customOption = this.dateDropDownOptions.filter((option) => option.optionKey === DEFAULT_DATE_OPTION_ENUM.CUSTOM); customOption[0].isSelected = true; } /** * This method toggles the custom date range selection view. */ toggleCustomDateRangeView() { this.isCustomRange = !this.isCustomRange; } /** * Clears the selected dates and resets date-related properties. * * @param event - The mouse event that triggered the clear action. */ clearSelection(event) { event.stopImmediatePropagation(); const currentDate = new Date(); const year = currentDate.getFullYear(); this.minDate = new Date(currentDate.setFullYear(year - 10)); this.maxDate = new Date(currentDate.setFullYear(year + 10)); this.selectedDates = null; this.resetOptionSelection(); const dateInputField = this.el.nativeElement.querySelector('#date-input-field'); if (dateInputField) { dateInputField.value = ''; } this.cdref.markForCheck(); const selectedDateEventData = { range: null, selectedOption: null, }; this.onDateSelectionChanged.emit(selectedDateEventData); } /** * This method sets clicked element as selected. * @param option ISelectDateOption */ resetOptionSelection(option) { this.dateDropDownOptions.forEach((option) => (option.isSelected = false)); if (option) { option.isSelected = true; } this.cdref.markForCheck(); } /** * Updates the selected dates based on the given option and input element. * * @param option - The date option selected by the user. * @param input - The HTML input element to update. */ updateDateOnOptionSelect(option, input) { const currDate = new Date(); let startDate = new Date(); let lastDate = new Date(); // If there is a callback function, use it to get the date range if (option.callBackFunction) { const dateRange = option.callBackFunction(); if (dateRange?.start && dateRange?.end) { this.updateSelectedDates(input, dateRange.start, dateRange.end, option); return; } } // Determine the date range based on the option key switch (option.optionKey) { case DEFAULT_DATE_OPTION_ENUM.DATE_DIFF: startDate.setDate(startDate.getDate() + option.dateDiff); break; case DEFAULT_DATE_OPTION_ENUM.LAST_MONTH: currDate.setMonth(currDate.getMonth() - 1); startDate = new Date(currDate.getFullYear(), currDate.getMonth(), 1); lastDate = new Date(currDate.getFullYear(), currDate.getMonth(), this.getDaysInMonth(currDate)); break; case DEFAULT_DATE_OPTION_ENUM.THIS_MONTH: startDate = new Date(currDate.getFullYear(), currDate.getMonth(), 1); lastDate = new Date(currDate.getFullYear(), currDate.getMonth(), this.getDaysInMonth(currDate)); break; case DEFAULT_DATE_OPTION_ENUM.YEAR_TO_DATE: startDate = new Date(currDate.getFullYear(), 0, 1); break; case DEFAULT_DATE_OPTION_ENUM.MONTH_TO_DATE: startDate = new Date(currDate.getFullYear(), currDate.getMonth(), 1); break; default: break; } // Update the selected dates this.updateSelectedDates(input, startDate, lastDate, option); } /** * This method updates dates on selection. * * @param input HTMLInputElement * @param startDate Date * @param endDate Date */ updateSelectedDates(input, startDate, endDate, option) { this.selectedDates = new DateRange(startDate, endDate); input.value = this.displaySelectedLabel && option ? option.optionLabel : this.getDateString(startDate) + ' - ' + this.getDateString(endDate); const selectedOption = this.dateDropDownOptions.filter((option) => option.isSelected)[0]; const selectedDateEventData = { range: new DateRange(new Date(startDate), new Date(endDate)), selectedOption: selectedOption, }; this.onDateSelectionChanged.emit(selectedDateEventData); this.cdref.markForCheck(); } /** * This method converts the given date into specified string format. * * @param date Date * @returns formatted date. */ getDateString(date) { const datePipe = new DatePipe('en'); return datePipe.transform(date, this.dateFormat) ?? ''; } /** * This method return the number of days in moth on specified date. * * @param date Date * @returns number */ getDaysInMonth(date) { return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); } /** * This method clone the data. * * @param data T * @returns T */ getClone(data) { return JSON.parse(JSON.stringify(data)); } /** * This method update the default date values on init. */ updateDefaultDatesValues() { const input = this.el.nativeElement.querySelector('#date-input-field'); if (this.selectedDates && this.selectedDates.start && this.selectedDates.end) { const customOption = this._dateDropDownOptions.filter((option) => option.optionKey === DEFAULT_DATE_OPTION_ENUM.CUSTOM); customOption[0].isSelected = true; input.value = this.getDateString(this.selectedDates.start) + ' - ' + this.getDateString(this.selectedDates.end); } else { const selectedOptions = this._dateDropDownOptions.filter((option) => option.isSelected); if (selectedOptions.length && selectedOptions[0].optionKey !== DEFAULT_DATE_OPTION_ENUM.CUSTOM) { this.updatedFromListValueSelection(selectedOptions[0], input); } } this.cdref.detectChanges(); } /** * This method updates the date values based on default option selection. * * @param selectedOption ISelectDateOption * @param input HTMLInputElement */ updatedFromListValueSelection(selectedOption, input) { // This will update value if option is selected from provided custom list. if (selectedOption['callBackFunction']) { const dateRange = selectedOption.callBackFunction(); if (dateRange?.start && dateRange?.end) { this.updateSelectedDates(input, dateRange.start, dateRange.end, selectedOption); } } else { // This will update value if option is selected from default list. this.updateDateOnOptionSelect(selectedOption, input); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.0.6", type: NgDatePickerComponent, selector: "ng-date-range-picker", inputs: { inputLabel: "inputLabel", staticOptionId: "staticOptionId", dynamicOptionId: "dynamicOptionId", calendarId: "calendarId", enableDefaultOptions: "enableDefaultOptions", selectedDates: "selectedDates", dateFormat: "dateFormat", isShowStaticDefaultOptions: "isShowStaticDefaultOptions", hideDefaultOptions: "hideDefaultOptions", cdkConnectedOverlayOffsetX: "cdkConnectedOverlayOffsetX", cdkConnectedOverlayOffsetY: "cdkConnectedOverlayOffsetY", listCdkConnectedOverlayOffsetY: "listCdkConnectedOverlayOffsetY", listCdkConnectedOverlayOffsetX: "listCdkConnectedOverlayOffsetX", selectedOptionIndex: "selectedOptionIndex", displaySelectedLabel: "displaySelectedLabel", cdkConnectedOverlayPush: "cdkConnectedOverlayPush", cdkConnectedOverlayPositions: "cdkConnectedOverlayPositions", minDate: "minDate", maxDate: "maxDate", dateDropDownOptions: "dateDropDownOptions" }, outputs: { onDateSelectionChanged: "onDateSelectionChanged", dateListOptions: "dateListOptions" }, ngImport: i0, template: "<!--**\r\n * @(#)ng-date-picker.component.html Sept 05, 2023\r\n\r\n * @author Aakash Kumar\r\n *-->\r\n<div class=\"date-picker-main\" cdkOverlayOrigin #trigger>\r\n <mat-form-field class=\"w-full\" [class]=\"{'display-hidden':isShowStaticDefaultOptions}\" (click)=\"toggleDateOptionSelectionList($event)\">\r\n <mat-label (click)=\"toggleDateOptionSelectionList($event)\">{{inputLabel}}</mat-label>\r\n <input matInput readonly=\"readonly\" #dateInput class=\"cursor-pointer\" id=\"date-input-field\">\r\n <button mat-icon-button matSuffix class=\"cursor-pointer pe-0 ps-0\" matTooltip=\"Clear\" *ngIf=\"!!dateInput.value\"\r\n (click)=\"clearSelection($event)\"><mat-icon>clear</mat-icon></button>\r\n <button mat-icon-button matSuffix class=\"cursor-pointer\"> <mat-icon>date_range</mat-icon></button>\r\n </mat-form-field>\r\n\r\n @if(dateDropDownOptions && dateDropDownOptions.length && isShowStaticDefaultOptions) {\r\n <mat-action-list class=\"w-full custom-ckd-container range-input\" [id]=\"staticOptionId\">\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if (option.isVisible) {\r\n <mat-list-item [activated]=\"option.isSelected\" (click)=\"updateSelection(option, dateInput)\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n }\r\n\r\n <ng-template cdkConnectedOverlay [cdkConnectedOverlayHasBackdrop]=\"false\" [cdkConnectedOverlayOrigin]=\"trigger\"\r\n [cdkConnectedOverlayOpen]=\"isDateOptionList\" [cdkConnectedOverlayPush]=\"cdkConnectedOverlayPush\"\r\n [cdkConnectedOverlayOffsetX]=\"listCdkConnectedOverlayOffsetX\" [cdkConnectedOverlayOffsetY]=\"listCdkConnectedOverlayOffsetY\"\r\n (overlayOutsideClick)=\"!isShowStaticDefaultOptions && toggleDateOptionSelectionList()\">\r\n\r\n @if(dateDropDownOptions && dateDropDownOptions.length && !isShowStaticDefaultOptions) {\r\n <mat-action-list [id]=\"dynamicOptionId\" class=\"w-full custom-ckd-container range-input\">\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if (option.isVisible) {\r\n <mat-list-item [activated]=\"option.isSelected\" (click)=\"updateSelection(option, dateInput)\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n }\r\n </ng-template>\r\n\r\n <ng-template cdkConnectedOverlay [cdkConnectedOverlayHasBackdrop]=\"false\" [cdkConnectedOverlayOrigin]=\"trigger\"\r\n [cdkConnectedOverlayOpen]=\"isCustomRange\" [cdkConnectedOverlayPush]=\"cdkConnectedOverlayPush\"\r\n [cdkConnectedOverlayPositions]=\"cdkConnectedOverlayPositions\" [cdkConnectedOverlayOffsetX]=\"cdkConnectedOverlayOffsetX\"\r\n [cdkConnectedOverlayOffsetY]=\"cdkConnectedOverlayOffsetY\" (overlayOutsideClick)=\"toggleCustomDateRangeView()\">\r\n <div class=\"custom-ckd-container custom-calendar-container\" [class]=\"{'without-default-opt':hideDefaultOptions}\">\r\n <div class=\"row-1\">\r\n <div class=\"pt-custom br-right column-1\" *ngIf=\"!hideDefaultOptions\">\r\n <mat-action-list>\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if(option.isVisible) {\r\n <mat-list-item (click)=\"updateSelection(option, dateInput)\"\r\n [activated]=\"option.isSelected\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n </div>\r\n <div class=\"mt-2 column-2\"><lib-calendar [selectedDates]=\"selectedDates\" #calendar [minDate]=\"minDate\"\r\n [maxDate]=\"maxDate\"></lib-calendar></div>\r\n </div>\r\n <div class=\"row-2 br-top\">\r\n <div class=\"text-end my-2 w-full\">\r\n <div class=\"footer-content\">\r\n <span id=\"range-label-text\">\r\n {{calendar?.selectedDates?.start | date: dateFormat}}\r\n @if (calendar?.selectedDates?.end) {\r\n <span> - {{calendar.selectedDates?.end | date:\r\n dateFormat}} </span>\r\n }\r\n </span>\r\n <div class=\"d-inline buttons\">\r\n <button mat-button mat-raised-button class=\"p-3 mx-2\" (click)=\"isCustomRange=false;\">Cancel</button>\r\n <button mat-button mat-raised-button color=\"primary\" class=\"ms-2 p-3\"\r\n [class.disabled]=\"!(calendar?.selectedDates?.start && calendar?.selectedDates?.end)\"\r\n (click)=\"updateCustomRange(dateInput,calendar.selectedDates);\">&nbsp;Apply&nbsp;</button>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-template>\r\n</div>\r\n", styles: ["::ng-deep .cdk-overlay-dark-backdrop{background:none}mat-list-item{height:35px}::ng-deep .cdk-overlay-pane:has(.custom-ckd-container){width:100%;background-color:var(--bg-color, white);max-height:100vh;overflow-y:auto;overflow-x:hidden;max-width:700px;margin-top:-22px;border:1px solid var(--border-color, #ddd)}::ng-deep .cdk-overlay-pane:has(.range-input){max-width:250px}.br-top{border-top:1px solid var(--border-color, #ddd)}.br-right{border-right:1px solid var(--border-color, #ddd)}.disabled{pointer-events:none;opacity:.5}.mat-button,.mdc-button{font-family:var(--mdc-list-list-item-label-text-font);line-height:var(--mdc-list-list-item-label-text-line-height);font-size:var(--mdc-list-list-item-label-text-size);font-weight:var(--mdc-list-list-item-label-text-weight);letter-spacing:var(--mdc-list-list-item-label-text-tracking)}.w-full{width:100%}.display-hidden{display:none}.custom-calendar-container,.row-1,.row-2{width:100%;display:block;float:left}.row-2{padding:.7rem}.footer-content{width:100%;align-items:center;display:flex;text-align:right;justify-content:end;gap:10px;margin-right:2rem;text-overflow:ellipsis}.buttons{margin-right:1.5rem;display:flex;gap:10px}.column-1{width:25%;display:block;float:left}.column-2{width:73%;display:block;float:left}@media (max-width: 400px){.footer-content{display:block}#range-label-text{margin-right:1.5rem}.buttons{float:right;margin-top:20px}}@media (max-width: 650px){.column-1,.column-2{width:100%}}@media (min-width: 650px){.column-1{width:25%}.column-2{width:74%}}.without-default-opt .column-1{display:none}.without-default-opt .column-2{width:100%;display:block;float:left}.pe-0{padding-right:0}.ps-0{padding-left:0}\n"], dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i3.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "directive", type: i4.CdkConnectedOverlay, selector: "[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]", inputs: ["cdkConnectedOverlayOrigin", "cdkConnectedOverlayPositions", "cdkConnectedOverlayPositionStrategy", "cdkConnectedOverlayOffsetX", "cdkConnectedOverlayOffsetY", "cdkConnectedOverlayWidth", "cdkConnectedOverlayHeight", "cdkConnectedOverlayMinWidth", "cdkConnectedOverlayMinHeight", "cdkConnectedOverlayBackdropClass", "cdkConnectedOverlayPanelClass", "cdkConnectedOverlayViewportMargin", "cdkConnectedOverlayScrollStrategy", "cdkConnectedOverlayOpen", "cdkConnectedOverlayDisableClose", "cdkConnectedOverlayTransformOriginOn", "cdkConnectedOverlayHasBackdrop", "cdkConnectedOverlayLockPosition", "cdkConnectedOverlayFlexibleDimensions", "cdkConnectedOverlayGrowAfterOpen", "cdkConnectedOverlayPush", "cdkConnectedOverlayDisposeOnNavigation"], outputs: ["backdropClick", "positionChange", "attach", "detach", "overlayKeydown", "overlayOutsideClick"], exportAs: ["cdkConnectedOverlay"] }, { kind: "directive", type: i4.CdkOverlayOrigin, selector: "[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]", exportAs: ["cdkOverlayOrigin"] }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i6.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }, { kind: "component", type: i6.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i7.MatActionList, selector: "mat-action-list", exportAs: ["matActionList"] }, { kind: "component", type: i7.MatListItem, selector: "mat-list-item, a[mat-list-item], button[mat-list-item]", inputs: ["activated"], exportAs: ["matListItem"] }, { kind: "directive", type: i8.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: CalendarComponent, selector: "lib-calendar", inputs: ["selectedDates", "minDate", "maxDate"] }, { kind: "pipe", type: i1$1.DatePipe, name: "date" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerComponent, decorators: [{ type: Component, args: [{ selector: 'ng-date-range-picker', changeDetection: ChangeDetectionStrategy.OnPush, template: "<!--**\r\n * @(#)ng-date-picker.component.html Sept 05, 2023\r\n\r\n * @author Aakash Kumar\r\n *-->\r\n<div class=\"date-picker-main\" cdkOverlayOrigin #trigger>\r\n <mat-form-field class=\"w-full\" [class]=\"{'display-hidden':isShowStaticDefaultOptions}\" (click)=\"toggleDateOptionSelectionList($event)\">\r\n <mat-label (click)=\"toggleDateOptionSelectionList($event)\">{{inputLabel}}</mat-label>\r\n <input matInput readonly=\"readonly\" #dateInput class=\"cursor-pointer\" id=\"date-input-field\">\r\n <button mat-icon-button matSuffix class=\"cursor-pointer pe-0 ps-0\" matTooltip=\"Clear\" *ngIf=\"!!dateInput.value\"\r\n (click)=\"clearSelection($event)\"><mat-icon>clear</mat-icon></button>\r\n <button mat-icon-button matSuffix class=\"cursor-pointer\"> <mat-icon>date_range</mat-icon></button>\r\n </mat-form-field>\r\n\r\n @if(dateDropDownOptions && dateDropDownOptions.length && isShowStaticDefaultOptions) {\r\n <mat-action-list class=\"w-full custom-ckd-container range-input\" [id]=\"staticOptionId\">\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if (option.isVisible) {\r\n <mat-list-item [activated]=\"option.isSelected\" (click)=\"updateSelection(option, dateInput)\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n }\r\n\r\n <ng-template cdkConnectedOverlay [cdkConnectedOverlayHasBackdrop]=\"false\" [cdkConnectedOverlayOrigin]=\"trigger\"\r\n [cdkConnectedOverlayOpen]=\"isDateOptionList\" [cdkConnectedOverlayPush]=\"cdkConnectedOverlayPush\"\r\n [cdkConnectedOverlayOffsetX]=\"listCdkConnectedOverlayOffsetX\" [cdkConnectedOverlayOffsetY]=\"listCdkConnectedOverlayOffsetY\"\r\n (overlayOutsideClick)=\"!isShowStaticDefaultOptions && toggleDateOptionSelectionList()\">\r\n\r\n @if(dateDropDownOptions && dateDropDownOptions.length && !isShowStaticDefaultOptions) {\r\n <mat-action-list [id]=\"dynamicOptionId\" class=\"w-full custom-ckd-container range-input\">\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if (option.isVisible) {\r\n <mat-list-item [activated]=\"option.isSelected\" (click)=\"updateSelection(option, dateInput)\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n }\r\n </ng-template>\r\n\r\n <ng-template cdkConnectedOverlay [cdkConnectedOverlayHasBackdrop]=\"false\" [cdkConnectedOverlayOrigin]=\"trigger\"\r\n [cdkConnectedOverlayOpen]=\"isCustomRange\" [cdkConnectedOverlayPush]=\"cdkConnectedOverlayPush\"\r\n [cdkConnectedOverlayPositions]=\"cdkConnectedOverlayPositions\" [cdkConnectedOverlayOffsetX]=\"cdkConnectedOverlayOffsetX\"\r\n [cdkConnectedOverlayOffsetY]=\"cdkConnectedOverlayOffsetY\" (overlayOutsideClick)=\"toggleCustomDateRangeView()\">\r\n <div class=\"custom-ckd-container custom-calendar-container\" [class]=\"{'without-default-opt':hideDefaultOptions}\">\r\n <div class=\"row-1\">\r\n <div class=\"pt-custom br-right column-1\" *ngIf=\"!hideDefaultOptions\">\r\n <mat-action-list>\r\n @for (option of dateDropDownOptions; track option.optionKey) {\r\n @if(option.isVisible) {\r\n <mat-list-item (click)=\"updateSelection(option, dateInput)\"\r\n [activated]=\"option.isSelected\">{{option.optionLabel}}</mat-list-item>\r\n }\r\n }\r\n </mat-action-list>\r\n </div>\r\n <div class=\"mt-2 column-2\"><lib-calendar [selectedDates]=\"selectedDates\" #calendar [minDate]=\"minDate\"\r\n [maxDate]=\"maxDate\"></lib-calendar></div>\r\n </div>\r\n <div class=\"row-2 br-top\">\r\n <div class=\"text-end my-2 w-full\">\r\n <div class=\"footer-content\">\r\n <span id=\"range-label-text\">\r\n {{calendar?.selectedDates?.start | date: dateFormat}}\r\n @if (calendar?.selectedDates?.end) {\r\n <span> - {{calendar.selectedDates?.end | date:\r\n dateFormat}} </span>\r\n }\r\n </span>\r\n <div class=\"d-inline buttons\">\r\n <button mat-button mat-raised-button class=\"p-3 mx-2\" (click)=\"isCustomRange=false;\">Cancel</button>\r\n <button mat-button mat-raised-button color=\"primary\" class=\"ms-2 p-3\"\r\n [class.disabled]=\"!(calendar?.selectedDates?.start && calendar?.selectedDates?.end)\"\r\n (click)=\"updateCustomRange(dateInput,calendar.selectedDates);\">&nbsp;Apply&nbsp;</button>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-template>\r\n</div>\r\n", styles: ["::ng-deep .cdk-overlay-dark-backdrop{background:none}mat-list-item{height:35px}::ng-deep .cdk-overlay-pane:has(.custom-ckd-container){width:100%;background-color:var(--bg-color, white);max-height:100vh;overflow-y:auto;overflow-x:hidden;max-width:700px;margin-top:-22px;border:1px solid var(--border-color, #ddd)}::ng-deep .cdk-overlay-pane:has(.range-input){max-width:250px}.br-top{border-top:1px solid var(--border-color, #ddd)}.br-right{border-right:1px solid var(--border-color, #ddd)}.disabled{pointer-events:none;opacity:.5}.mat-button,.mdc-button{font-family:var(--mdc-list-list-item-label-text-font);line-height:var(--mdc-list-list-item-label-text-line-height);font-size:var(--mdc-list-list-item-label-text-size);font-weight:var(--mdc-list-list-item-label-text-weight);letter-spacing:var(--mdc-list-list-item-label-text-tracking)}.w-full{width:100%}.display-hidden{display:none}.custom-calendar-container,.row-1,.row-2{width:100%;display:block;float:left}.row-2{padding:.7rem}.footer-content{width:100%;align-items:center;display:flex;text-align:right;justify-content:end;gap:10px;margin-right:2rem;text-overflow:ellipsis}.buttons{margin-right:1.5rem;display:flex;gap:10px}.column-1{width:25%;display:block;float:left}.column-2{width:73%;display:block;float:left}@media (max-width: 400px){.footer-content{display:block}#range-label-text{margin-right:1.5rem}.buttons{float:right;margin-top:20px}}@media (max-width: 650px){.column-1,.column-2{width:100%}}@media (min-width: 650px){.column-1{width:25%}.column-2{width:74%}}.without-default-opt .column-1{display:none}.without-default-opt .column-2{width:100%;display:block;float:left}.pe-0{padding-right:0}.ps-0{padding-left:0}\n"] }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }], propDecorators: { inputLabel: [{ type: Input }], staticOptionId: [{ type: Input }], dynamicOptionId: [{ type: Input }], calendarId: [{ type: Input }], enableDefaultOptions: [{ type: Input }], selectedDates: [{ type: Input }], dateFormat: [{ type: Input }], isShowStaticDefaultOptions: [{ type: Input }], hideDefaultOptions: [{ type: Input }], cdkConnectedOverlayOffsetX: [{ type: Input }], cdkConnectedOverlayOffsetY: [{ type: Input }], listCdkConnectedOverlayOffsetY: [{ type: Input }], listCdkConnectedOverlayOffsetX: [{ type: Input }], selectedOptionIndex: [{ type: Input }], displaySelectedLabel: [{ type: Input }], cdkConnectedOverlayPush: [{ type: Input }], cdkConnectedOverlayPositions: [{ type: Input }], minDate: [{ type: Input }], maxDate: [{ type: Input }], onDateSelectionChanged: [{ type: Output }], dateListOptions: [{ type: Output }], dateDropDownOptions: [{ type: Input }] } }); class SelectDateOption { constructor() { this.optionLabel = ''; this.optionKey = DEFAULT_DATE_OPTION_ENUM.DATE_DIFF; this.dateDiff = 0; this.isSelected = false; this.isVisible = false; } } /** * @(#)ng-date-picker.module.ts Sept 05, 2023 * * @author Aakash Kumar */ class NgDatePickerModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerModule, declarations: [NgDatePickerComponent, CalendarComponent], imports: [CommonModule, FormsModule, MatDatepickerModule, MatNativeDateModule, MatInputModule, MatAutocompleteModule, OverlayModule, MatIconModule, MatButtonModule, MatListModule, MatFormFieldModule, MatTooltipModule], exports: [NgDatePickerComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerModule, imports: [CommonModule, FormsModule, MatDatepickerModule, MatNativeDateModule, MatInputModule, MatAutocompleteModule, OverlayModule, MatIconModule, MatButtonModule, MatListModule, MatFormFieldModule, MatTooltipModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: NgDatePickerModule, decorators: [{ type: NgModule, args: [{ declarations: [NgDatePickerComponent, CalendarComponent], imports: [ CommonModule, FormsModule, MatDatepickerModule, MatNativeDateModule, MatInputModule, MatAutocompleteModule, OverlayModule, MatIconModule, MatButtonModule, MatListModule, MatFormFieldModule, MatTooltipModule, ], exports: [NgDatePickerComponent], }] }] }); /** * @(#)public-api.ts Sept 05, 2023 * * @author Aakash Kumar */ // Public API Surface of ng-date-picker /** * Generated bundle index. Do not edit. */ export { DEFAULT_DATE_OPTION_ENUM, NgDatePickerComponent, NgDatePickerModule, SelectDateOption }; //# sourceMappingURL=ng-material-date-range-picker.mjs.map