Skip to content

Commit 72de46f

Browse files
committed
feat(calendar): calendar multi view #4282
1 parent fe5631b commit 72de46f

File tree

4 files changed

+117
-27
lines changed

4 files changed

+117
-27
lines changed

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

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
<span>{{ getFormattedDate().monthday }}</span>
44
</ng-template>
55

6-
<ng-template let-result #defaultMonth>
7-
<span tabindex="0" #monthsBtn (keydown)="activeViewYearKB($event)" (click)="activeViewYear()"
8-
class="igx-calendar-picker__date">
9-
{{ formattedMonth(viewDate) }}
10-
</span>
11-
<span tabindex="0" #yearsBtn (keydown)="activeViewDecadeKB($event)" (click)="activeViewDecade()"
12-
class="igx-calendar-picker__date">
13-
{{ formattedYear(viewDate) }}
14-
</span>
6+
<ng-template let-result #defaultMonth >
7+
<ng-container *ngFor="let view of dayViews; let i of index;">
8+
<div>
9+
<span tabindex="0" #monthsBtn (keydown)="activeViewYearKB($event)" (click)="activeViewYear()"
10+
class="igx-calendar-picker__date">
11+
{{ formattedMonth(view.viewDate) }}
12+
</span>
13+
<span tabindex="0" #yearsBtn (keydown)="activeViewDecadeKB($event)" (click)="activeViewDecade()"
14+
class="igx-calendar-picker__date">
15+
{{ formattedYear(view.viewDate) }}
16+
</span>
17+
</div>
18+
</ng-container>
1519
</ng-template>
1620

1721
<div *ngIf="selection === 'single' && hasHeader" class="igx-calendar__header">
@@ -29,7 +33,7 @@ <h2 class="igx-calendar__header-date">
2933
(click)="previousMonth()">
3034
<igx-icon fontSet="material">keyboard_arrow_left</igx-icon>
3135
</div>
32-
<div>
36+
<div style="display: contents">
3337
<ng-container *ngTemplateOutlet="subheaderTemplate ? subheaderTemplate : defaultMonth; context: context">
3438
</ng-container>
3539
</div>
@@ -38,20 +42,22 @@ <h2 class="igx-calendar__header-date">
3842
</div>
3943
</div>
4044

41-
<igx-days-view [changeDaysView]="true" #days
42-
[animationAction]="monthAction"
43-
[locale]="locale"
44-
[value]="value"
45-
[viewDate]="viewDate"
46-
[weekStart]="weekStart"
47-
[formatOptions]="formatOptions"
48-
[formatViews]="formatViews"
49-
[selection]="selection"
50-
[disabledDates]="disabledDates"
51-
[specialDates]="specialDates"
52-
(onViewChanged)="viewChanged($event)"
53-
(onDateSelection)="childClicked($event)">
54-
</igx-days-view>
45+
<div style="display: flex">
46+
<igx-days-view *ngFor="let view of dayViews; let i of index;" [changeDaysView]="true" #days
47+
[animationAction]="view.monthAction"
48+
[locale]="view.locale"
49+
[value]="view.value"
50+
[viewDate]="view.viewDate"
51+
[weekStart]="view.weekStart"
52+
[formatOptions]="view.formatOptions"
53+
[formatViews]="view.formatViews"
54+
[selection]="view.selection"
55+
[disabledDates]="view.disabledDates"
56+
[specialDates]="view.specialDates"
57+
(onViewChanged)="viewChanged($event)"
58+
(onDateSelection)="childClicked($event)">
59+
</igx-days-view>
60+
</div>
5561
</div>
5662

5763
<igx-months-view *ngIf="isYearView" [@animateView]="activeView" #months
@@ -67,5 +73,5 @@ <h2 class="igx-calendar__header-date">
6773
[locale]="locale"
6874
[formatView]="formatViews.year"
6975
[yearFormat]="formatOptions.year"
70-
(onSelection)="changeYear($event)">
76+
(onSelection)="changeYear($event, dayViews)">
7177
</igx-years-view>

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ import { CalendarView, IgxMonthPickerBase } from './month-picker-base';
2121
import { IgxMonthsViewComponent } from './months-view/months-view.component';
2222
import { IgxYearsViewComponent } from './years-view/years-view.component';
2323
import { IgxDaysViewComponent } from './days-view/days-view.component';
24+
import { DateRangeDescriptor } from '../core/dates';
2425

2526
let NEXT_ID = 0;
2627

28+
export interface IDayView {
29+
changeDaysView: boolean;
30+
animationAction: string;
31+
locale: string;
32+
value: Date | Date[];
33+
viewDate: Date;
34+
weekStart: number;
35+
formatOptions: object;
36+
formatViews: object;
37+
selection: string;
38+
disabledDates: DateRangeDescriptor[];
39+
specialDates: DateRangeDescriptor[];
40+
}
41+
2742
/**
2843
* **Ignite UI for Angular Calendar** -
2944
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/calendar.html)
@@ -90,6 +105,34 @@ export class IgxCalendarComponent extends IgxMonthPickerBase {
90105
@Input()
91106
public vertical = false;
92107

108+
/**
109+
* Sets/gets the number of dayViews duisplayed.
110+
* Default value is `1`.
111+
* ```html
112+
* <igx-calendar [vertical] = "true" [daysViewNumber]="2"></igx-calendar>
113+
* ```
114+
* ```typescript
115+
* let daysViewsDisplayed = this.calendar.daysViewNumber;
116+
* ```
117+
*/
118+
@Input()
119+
get daysViewNumber() {
120+
return this._daysViewNumber;
121+
}
122+
123+
set daysViewNumber(val: number) {
124+
this._daysViewNumber = val;
125+
126+
for (let i = 1; i < val; i++) {
127+
const dayView = Object.assign({}, this.defaultDayView);
128+
dayView.value = null;
129+
const nextMonthDate = new Date(dayView.viewDate);
130+
nextMonthDate.setMonth(nextMonthDate.getMonth() + i);
131+
dayView.viewDate = nextMonthDate;
132+
this.dayViews.push(dayView);
133+
}
134+
}
135+
93136
/**
94137
* The default `tabindex` attribute for the component.
95138
*
@@ -273,6 +316,33 @@ export class IgxCalendarComponent extends IgxMonthPickerBase {
273316
*/
274317
private _monthAction = '';
275318

319+
/**
320+
*@hidden
321+
*/
322+
private _daysViewNumber = 1;
323+
324+
/**
325+
*@hidden
326+
*/
327+
private defaultDayView: IDayView = {
328+
changeDaysView: true,
329+
animationAction: this._monthAction,
330+
locale: this.locale,
331+
value: this.value,
332+
viewDate: this.viewDate,
333+
weekStart: this.weekStart,
334+
formatOptions: this.formatOptions,
335+
formatViews: this.formatViews,
336+
selection: this.selection,
337+
disabledDates: this.disabledDates,
338+
specialDates: this.specialDates
339+
};
340+
341+
/**
342+
*@hidden
343+
*/
344+
private dayViews: Array<IDayView> = [this.defaultDayView];
345+
276346
/**
277347
* Returns the locale representation of the month in the month view if enabled,
278348
* otherwise returns the default `Date.getMonth()` value.
@@ -291,6 +361,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase {
291361
*/
292362
public previousMonth(isKeydownTrigger: boolean = false) {
293363
this.viewDate = this.calendarModel.timedelta(this.viewDate, 'month', -1);
364+
this.dayViews.forEach((val, index) => {
365+
val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', -1);
366+
});
294367
this._monthAction = 'prev';
295368

296369
if (this.daysView) {
@@ -315,6 +388,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase {
315388
*/
316389
public nextMonth(isKeydownTrigger: boolean = false) {
317390
this.viewDate = this.calendarModel.timedelta(this.viewDate, 'month', 1);
391+
this.dayViews.forEach((val, index) => {
392+
val.viewDate = this.calendarModel.timedelta(val.viewDate, 'month', 1);
393+
});
318394
this._monthAction = 'next';
319395

320396
if (this.daysView) {
@@ -401,6 +477,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase {
401477
*/
402478
public changeMonth(event: Date) {
403479
this.viewDate = new Date(this.viewDate.getFullYear(), event.getMonth());
480+
this.dayViews.forEach((val, index) => {
481+
val.viewDate.setMonth(event.getMonth() + index);
482+
});
404483
this.activeView = CalendarView.DEFAULT;
405484

406485
requestAnimationFrame(() => {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IgxCalendarBase } from './calendar-base';
22
import { ViewChild, ElementRef, HostBinding } from '@angular/core';
33
import { KEYS } from '../core/utils';
4+
import { IDayView } from './calendar.component';
45

56
/**
67
* Sets the calender view - days, months or years.
@@ -62,8 +63,12 @@ export class IgxMonthPickerBase extends IgxCalendarBase {
6263
/**
6364
* @hidden
6465
*/
65-
public changeYear(event: Date) {
66+
public changeYear(event: Date, dayViews: IDayView[]) {
6667
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+
});
6772
this._activeView = CalendarView.DEFAULT;
6873

6974
requestAnimationFrame(() => {

src/app/calendar/calendar.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h4 class="sample-title">Default Calendar</h4>
1111
<button igxButton="flat" igxRipple (click)="deselect()">Deselect</button>
1212
</div>
1313
<igx-card>
14-
<igx-calendar #calendar1 weekStart="1" selection="range"></igx-calendar>
14+
<igx-calendar #calendar1 weekStart="1" selection="multi" [daysViewNumber]="3"></igx-calendar>
1515
</igx-card>
1616
</div>
1717

0 commit comments

Comments
 (0)