Skip to content

Commit 96bd878

Browse files
authored
Merge branch 'master' into astaev/5671-master
2 parents 3a207da + 884c982 commit 96bd878

File tree

11 files changed

+269
-74
lines changed

11 files changed

+269
-74
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export function isDateInRanges(date: Date, ranges: DateRangeDescriptor[]): boole
5252
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
5353
const dateInMs = date.getTime();
5454

55+
if (!ranges) {
56+
return false;
57+
}
58+
5559
for (const descriptor of ranges) {
5660
const dRanges = descriptor.dateRange ? descriptor.dateRange.map(
5761
r => new Date(r.getFullYear(), r.getMonth(), r.getDate())) : undefined;
@@ -296,7 +300,7 @@ export class Calendar {
296300

297301
const toType = (partType: string) => {
298302
const index = formattedParts.findIndex(({ type }) => type === partType);
299-
const o: IFormattedParts = { value: '', literal: '', combined: ''};
303+
const o: IFormattedParts = { value: '', literal: '', combined: '' };
300304

301305
if (partType === 'era' && index > -1) {
302306
o.value = formattedParts[index].value;
@@ -316,7 +320,7 @@ export class Calendar {
316320
}
317321
} else {
318322
for (const each of parts) {
319-
result[each] = { value: '', literal: '', combined: ''};
323+
result[each] = { value: '', literal: '', combined: '' };
320324
}
321325
}
322326
return result;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<ng-content></ng-content>
1+
<span class="igx-calendar__date-content">
2+
<ng-content></ng-content>
3+
</span>

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

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input, Output, EventEmitter, HostBinding, ElementRef, HostListener } from '@angular/core';
2-
import { ICalendarDate, isDateInRanges } from '../calendar';
3-
import { DateRangeDescriptor } from '../../core/dates';
2+
import { ICalendarDate, isDateInRanges, Calendar } from '../calendar';
3+
import { DateRangeDescriptor, DateRangeType } from '../../core/dates';
44
import { CalendarSelection } from '../calendar-base';
55

66
/**
@@ -40,10 +40,13 @@ export class IgxDayItemComponent {
4040
}
4141

4242
if (this.selection === CalendarSelection.SINGLE) {
43-
this._selected = (this.value as Date).getTime() === date.getTime();
43+
this._selected = (this.value as Date).getTime() === date.getTime();
4444
} else {
45-
this._selected = (this.value as Date[])
46-
.some((each) => each.getTime() === date.getTime());
45+
const selectedDates = (this.value as Date[]);
46+
const currentDate = selectedDates.find(element => element.getTime() === date.getTime());
47+
48+
this._index = selectedDates.indexOf(currentDate) + 1;
49+
this._selected = !!this._index;
4750
}
4851

4952
return this._selected;
@@ -126,7 +129,7 @@ export class IgxDayItemComponent {
126129

127130
@HostBinding('class.igx-calendar__date--current')
128131
public get isTodayCSS(): boolean {
129-
return this.isToday && !this.selected;
132+
return this.isToday;
130133
}
131134

132135
@HostBinding('class.igx-calendar__date--selected')
@@ -144,11 +147,52 @@ export class IgxDayItemComponent {
144147
return this.isDisabled || this.isOutOfRange;
145148
}
146149

150+
@HostBinding('class.igx-calendar__date--range')
151+
public get isWithinRange() {
152+
if (Array.isArray(this.value) && this.value.length > 1) {
153+
154+
return isDateInRanges(this.date.date,
155+
[
156+
{
157+
type: DateRangeType.Between,
158+
dateRange: [this.value[0], this.value[this.value.length - 1]]
159+
}
160+
]
161+
);
162+
}
163+
164+
return false;
165+
}
166+
147167
@HostBinding('class.igx-calendar__date--special')
148168
public get isSpecialCSS(): boolean {
149169
return this.isSpecial;
150170
}
151171

172+
@HostBinding('class.igx-calendar__date--single')
173+
public get isSingleSelection(): boolean {
174+
return this.selection !== CalendarSelection.RANGE;
175+
}
176+
177+
@HostBinding('class.igx-calendar__date--first')
178+
public get isFirstInRange(): boolean {
179+
if (this.isSingleSelection) {
180+
return false;
181+
}
182+
183+
return this._index === 1;
184+
}
185+
186+
@HostBinding('class.igx-calendar__date--last')
187+
public get isLastInRange(): boolean {
188+
if (this.isSingleSelection) {
189+
return false;
190+
}
191+
192+
return (this.value as Date[]).length === this._index;
193+
}
194+
195+
private _index: Number;
152196
private _selected = false;
153197

154198
constructor(private elementRef: ElementRef) { }

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
</div>
66

77
<div *ngFor="let week of getCalendarMonth; last as isLast; index as i; trackBy: rowTracker" class="igx-calendar__body-row" [@animateChange]="animationAction" (@animateChange.done)="animationDone($event, isLast)">
8-
<igx-day-item [date]="day" [selection]="selection" [value]="value" [disabledDates]="disabledDates" [specialDates]="specialDates" [outOfRangeDates]="outOfRangeDates" (onDateSelection)="selectDay($event)" *ngFor="let day of week; trackBy: dateTracker">
9-
{{ formattedDate(day.date) }}
8+
<igx-day-item
9+
*ngFor="let day of week; trackBy: dateTracker"
10+
[date]="day"
11+
[selection]="selection"
12+
[value]="value"
13+
[disabledDates]="disabledDates"
14+
[specialDates]="specialDates"
15+
[outOfRangeDates]="outOfRangeDates"
16+
(onDateSelection)="selectDay($event)"
17+
>
18+
{{ formattedDate(day.date) }}
1019
</igx-day-item>
1120
</div>

projects/igniteui-angular/src/lib/core/styles/components/calendar/_calendar-component.scss

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,11 @@
4747

4848
@include e(date) {
4949
@extend %cal-value !optional;
50-
51-
&:hover,
52-
&:focus {
53-
@extend %cal-value--hover !optional;
54-
}
5550
}
5651

5752
@include e(date, 'inactive') {
5853
@extend %cal-value !optional;
5954
@extend %cal-value--inactive !optional;
60-
61-
&:hover,
62-
&:focus {
63-
@extend %cal-value--hover !optional;
64-
}
6555
}
6656

6757
@include e(date, 'selected') {
@@ -72,21 +62,11 @@
7262
@include e(date, 'current') {
7363
@extend %cal-value !optional;
7464
@extend %cal-value--current !optional;
75-
76-
&:hover,
77-
&:focus {
78-
@extend %cal-value--hover !optional;
79-
}
8065
}
8166

8267
@include e(date, 'weekend') {
8368
@extend %cal-value !optional;
8469
@extend %cal-value--weekend !optional;
85-
86-
&:hover,
87-
&:focus {
88-
@extend %cal-value--hover !optional;
89-
}
9070
}
9171

9272
@include e(date, 'special') {
@@ -99,11 +79,42 @@
9979
@extend %cal-value--disabled !optional;
10080
}
10181

82+
@include e(date, 'single') {
83+
@extend %cal-value--single !optional;
84+
}
85+
86+
@include e(date, $mods: ('selected', 'first')) {
87+
@extend %cal-value--first !optional;
88+
}
89+
90+
@include e(date, $mods: ('selected', 'last')) {
91+
@extend %cal-value--last !optional;
92+
}
93+
94+
@include e(date, $mods: ('selected', 'first', 'last')) {
95+
@extend %cal-value--single !optional;
96+
}
97+
10298
@include e(date, $mods: ('disabled', 'inactive')) {
10399
@extend %cal-value !optional;
104100
@extend %cal-value--disabled !optional;
105101
}
106102

103+
@include e(date, $mods: ('disabled', 'range')) {
104+
@extend %cal-value--disabled-range !optional;
105+
}
106+
107+
// This is added due to a bug in JavaScript
108+
// where the selected dates collection also includes
109+
// disabled dates.
110+
@include e(date, $mods: ('selected', 'disabled', 'range')) {
111+
@extend %cal-value--disabled-range !optional;
112+
}
113+
114+
@include e(date-content) {
115+
@extend %cal-value-content !optional;
116+
}
117+
107118
@include e(year) {
108119
@extend %cal-value !optional;
109120
@extend %cal-value--year !optional;

0 commit comments

Comments
 (0)