Skip to content

Commit 18c5a61

Browse files
committed
refactor(calendar): refactor and clean #4282
1 parent b4d199f commit 18c5a61

File tree

6 files changed

+18
-32
lines changed

6 files changed

+18
-32
lines changed

projects/igniteui-angular/src/lib/calendar/calendar-base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class IgxCalendarBase implements ControlValueAccessor {
211211
}
212212

213213
/**
214-
* Sets/gets whether the inactive dates (dates that are out of the current month) will be hidden.
214+
* Sets/gets whether the outside dates (dates that are out of the current month) will be hidden.
215215
* Default value is `false`.
216216
* ```html
217217
* <igx-calendar [hideOutsideDays] = "true"></igx-calendar>

projects/igniteui-angular/src/lib/calendar/calendar.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ <h2 class="igx-calendar__header-date">
3333
<igx-icon fontSet="material">keyboard_arrow_left</igx-icon>
3434
</div>
3535
<div *ngFor="let view of dayViews; index as i;" [style.width.%]="100/monthsViewNumber">
36-
<ng-template *ngTemplateOutlet="subheaderTemplate ? subheaderTemplate : defaultMonth; context: getContext(i)">
37-
</ng-template>
36+
<ng-container *ngTemplateOutlet="subheaderTemplate ? subheaderTemplate : defaultMonth; context: getContext(i)">
37+
</ng-container>
3838
</div>
3939
<div tabindex="0" class="igx-calendar-picker__next" #nextMonthBtn
4040
igxCalendarScrollMonth [startScroll]="startNextMonthScroll" [stopScroll]="stopMonthScroll" [ngStyle]="{

projects/igniteui-angular/src/lib/calendar/calendar.component.ts

+12-21
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
201201
* @hidden
202202
*/
203203
@ViewChild('days', { read: IgxDaysViewComponent, static: false })
204-
public daysView = new IgxDaysViewComponent;
204+
public daysView: IgxDaysViewComponent;
205205

206206
/**
207207
* @hidden
@@ -346,15 +346,15 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
346346
/**
347347
*@hidden
348348
*/
349-
private defaultDayView: IMonthView = {
350-
value: this.value,
351-
viewDate: this.viewDate,
352-
};
349+
private _monthViewsChanges$: Subscription;
353350

354351
/**
355352
*@hidden
356353
*/
357-
private _monthViewsChanges$: Subscription;
354+
private defaultDayView: IMonthView = {
355+
value: this.value,
356+
viewDate: this.viewDate,
357+
};
358358

359359
/**
360360
*@hidden
@@ -431,6 +431,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
431431
public startPrevMonthScroll = (isKeydownTrigger = false) => {
432432
this.startMonthScroll$.next();
433433
this.daysView.monthScrollDirection = ScrollMonth.PREV;
434+
434435
this.previousMonth(isKeydownTrigger);
435436
}
436437

@@ -531,19 +532,11 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
531532
this.viewDate = this.calendarModel.timedelta(date, 'month', delta);
532533
}
533534

534-
/**
535-
* @hidden
536-
*/
537-
public daysViewInit(event: IgxDaysViewComponent) {
538-
// this.monthViews.
539-
}
540-
541535
/**
542536
* @hidden
543537
*/
544538
public changeMonth(event: Date) {
545539
this.viewDate = new Date(this.viewDate.getFullYear(), event.getMonth());
546-
547540
this.activeView = CalendarView.DEFAULT;
548541

549542
requestAnimationFrame(() => {
@@ -588,17 +581,15 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
588581
* @hidden
589582
*/
590583
public getViewDate(i: number): Date {
591-
const nextMonthDate = new Date(this.viewDate);
592-
nextMonthDate.setMonth(nextMonthDate.getMonth() + i);
593-
return nextMonthDate;
584+
const date = this.calendarModel.timedelta(this.viewDate, 'month', i);
585+
return date;
594586
}
595587

596588
/**
597589
* @hidden
598590
*/
599591
public getContext(i: number) {
600-
const date: Date = new Date(this.viewDate);
601-
date.setMonth(date.getMonth() + i);
592+
const date = this.calendarModel.timedelta(this.viewDate, 'month', i);
602593
return this.generateContext(date, i);
603594
}
604595

@@ -740,7 +731,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
740731
@HostListener('keydown.home', ['$event'])
741732
public onKeydownHome(event: KeyboardEvent) {
742733
if (this.daysView) {
743-
this.monthViews.first.onKeydownHome(event);
734+
this.daysView.onKeydownHome(event);
744735
}
745736
}
746737

@@ -750,7 +741,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
750741
@HostListener('keydown.end', ['$event'])
751742
public onKeydownEnd(event: KeyboardEvent) {
752743
if (this.daysView) {
753-
this.monthViews.last.onKeydownEnd(event);
744+
this.daysView.onKeydownEnd(event);
754745
}
755746
}
756747

projects/igniteui-angular/src/lib/calendar/days-view/day-item.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class IgxDayItemComponent {
161161

162162
@HostBinding('class.igx-calendar__date--disabled')
163163
public get isDisabledCSS(): boolean {
164-
return this.isDisabled || this.isOutOfRange || this.isHidden;
164+
return this.isDisabled || this.isOutOfRange || this.isHidden;
165165
}
166166

167167
@HostBinding('class.igx-calendar__date--range')

projects/igniteui-angular/src/lib/calendar/days-view/days-view.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
[outOfRangeDates]="outOfRangeDates"
1818
[hideOutsideDays]="hideOutsideDays"
1919
(onDateSelection)="selectDay($event)">
20-
{{ formattedDate(day.date) }}
20+
{{ formattedDate(day.date) }}
2121
</igx-day-item>
2222
</div>

projects/igniteui-angular/src/lib/calendar/month-picker-base.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { IgxCalendarBase } from './calendar-base';
22
import { ViewChild, ElementRef, HostBinding } from '@angular/core';
33
import { KEYS } from '../core/utils';
4-
import { IMonthView } from './calendar.component';
54

65
/**
76
* Sets the calender view - days, months or years.
@@ -63,12 +62,8 @@ export class IgxMonthPickerBase extends IgxCalendarBase {
6362
/**
6463
* @hidden
6564
*/
66-
public changeYear(event: Date, dayViews: IMonthView[]) {
65+
public changeYear(event: Date) {
6766
this.viewDate = new Date(event.getFullYear(), this.viewDate.getMonth());
68-
const yearsDiff = event.getFullYear() - dayViews[0].viewDate.getFullYear();
69-
dayViews.forEach((val, index) => {
70-
val.viewDate.setMonth(event.getMonth() + 12 * yearsDiff + index);
71-
});
7267
this._activeView = CalendarView.DEFAULT;
7368

7469
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)