1
1
import { Component , Input , Output , EventEmitter , HostBinding , ElementRef , HostListener } from '@angular/core' ;
2
2
import { ICalendarDate , isDateInRanges } from '../calendar' ;
3
- import { DateRangeDescriptor , DateRangeType } from '../../core/dates' ;
3
+ import { DateRangeDescriptor } from '../../core/dates' ;
4
4
import { CalendarSelection } from '../calendar-base' ;
5
5
6
6
/**
@@ -17,8 +17,21 @@ export class IgxDayItemComponent {
17
17
@Input ( )
18
18
public selection : string ;
19
19
20
+ /**
21
+ * Returns boolean indicating if the day is selected
22
+ *
23
+ */
20
24
@Input ( )
21
- public value : Date | Date [ ] ;
25
+ public get selected ( ) : any {
26
+ return this . _selected ;
27
+ }
28
+
29
+ /**
30
+ * Selects the day
31
+ */
32
+ public set selected ( value : any ) {
33
+ this . _selected = value ;
34
+ }
22
35
23
36
@Input ( )
24
37
public disabledDates : DateRangeDescriptor [ ] ;
@@ -32,32 +45,29 @@ export class IgxDayItemComponent {
32
45
@Input ( )
33
46
public hideOutsideDays = false ;
34
47
35
- @Output ( )
36
- public onDateSelection = new EventEmitter < ICalendarDate > ( ) ;
48
+ @Input ( )
49
+ @HostBinding ( 'class.igx-calendar__date--last' )
50
+ public isLastInRange = false ;
37
51
38
- public get selected ( ) : boolean {
39
- const date = this . date . date ;
52
+ @Input ( )
53
+ @HostBinding ( 'class.igx-calendar__date--first' )
54
+ public isFirstInRange = false ;
40
55
41
- if ( ! this . value ) {
42
- return ;
43
- }
56
+ @ Input ( )
57
+ @ HostBinding ( 'class.igx-calendar__date--firstday' )
58
+ public isFirstInMonth = false ;
44
59
45
- if ( this . selection === CalendarSelection . SINGLE ) {
46
- this . _selected = ( this . value as Date ) . getTime ( ) === date . getTime ( ) ;
47
- } else {
48
- const selectedDates = ( this . value as Date [ ] ) ;
49
- const currentDate = selectedDates . find ( element => element . getTime ( ) === date . getTime ( ) ) ;
60
+ @Input ( )
61
+ @HostBinding ( 'class.igx-calendar__date--lastday' )
62
+ public isLastInMonth = false ;
50
63
51
- this . _index = selectedDates . indexOf ( currentDate ) + 1 ;
52
- this . _selected = ! ! this . _index ;
53
- }
64
+ @ Input ( )
65
+ @ HostBinding ( 'class.igx-calendar__date--range' )
66
+ public isWithinRange = false ;
54
67
55
- return this . _selected ;
56
- }
68
+ @ Output ( )
69
+ public onDateSelection = new EventEmitter < ICalendarDate > ( ) ;
57
70
58
- public set selected ( value : boolean ) {
59
- this . _selected = value ;
60
- }
61
71
62
72
public get isCurrentMonth ( ) : boolean {
63
73
return this . date . isCurrentMonth ;
@@ -146,12 +156,12 @@ export class IgxDayItemComponent {
146
156
147
157
@HostBinding ( 'class.igx-calendar__date--selected' )
148
158
public get isSelectedCSS ( ) : boolean {
149
- return this . selected && this . isCurrentMonth ;
159
+ return this . isCurrentMonth && this . selected ;
150
160
}
151
161
152
162
@HostBinding ( 'class.igx-calendar__date--selected-dimmed' )
153
163
public get isSelectedDimmedCSS ( ) : boolean {
154
- return this . isSingleSelection && this . selected && ! this . isCurrentMonth ;
164
+ return ! this . isCurrentMonth && this . isSingleSelection && this . selected ;
155
165
}
156
166
157
167
@HostBinding ( 'class.igx-calendar__date--weekend' )
@@ -161,25 +171,9 @@ export class IgxDayItemComponent {
161
171
162
172
@HostBinding ( 'class.igx-calendar__date--disabled' )
163
173
public get isDisabledCSS ( ) : boolean {
164
- return this . isDisabled || this . isOutOfRange || this . isHidden ;
174
+ return this . isHidden || this . isDisabled || this . isOutOfRange ;
165
175
}
166
176
167
- @HostBinding ( 'class.igx-calendar__date--range' )
168
- public get isWithinRange ( ) {
169
- if ( Array . isArray ( this . value ) && this . value . length > 1 ) {
170
-
171
- return isDateInRanges ( this . date . date ,
172
- [
173
- {
174
- type : DateRangeType . Between ,
175
- dateRange : [ this . value [ 0 ] , this . value [ this . value . length - 1 ] ]
176
- }
177
- ]
178
- ) ;
179
- }
180
-
181
- return false ;
182
- }
183
177
184
178
@HostBinding ( 'class.igx-calendar__date--special' )
185
179
public get isSpecialCSS ( ) : boolean {
@@ -191,52 +185,11 @@ export class IgxDayItemComponent {
191
185
return this . selection !== CalendarSelection . RANGE ;
192
186
}
193
187
194
- @HostBinding ( 'class.igx-calendar__date--first' )
195
- public get isFirstInRange ( ) : boolean {
196
- if ( this . isSingleSelection ) {
197
- return false ;
198
- }
199
-
200
- return this . _index === 1 ;
201
- }
202
-
203
- @HostBinding ( 'class.igx-calendar__date--last' )
204
- public get isLastInRange ( ) : boolean {
205
- if ( this . isSingleSelection ) {
206
- return false ;
207
- }
208
-
209
- return ( this . value as Date [ ] ) . length === this . _index ;
210
- }
211
-
212
- @HostBinding ( 'class.igx-calendar__date--lastday' )
213
- public get isLastInMonth ( ) : boolean {
214
- const checkLast = true ;
215
- return this . isFirstLastInMonth ( checkLast ) ;
216
- }
217
-
218
- @HostBinding ( 'class.igx-calendar__date--firstday' )
219
- public get isFirstInMonth ( ) : boolean {
220
- const checkLast = false ;
221
- return this . isFirstLastInMonth ( checkLast ) ;
222
- }
223
188
224
- private _index : Number ;
225
189
private _selected = false ;
226
190
227
191
constructor ( private elementRef : ElementRef ) { }
228
192
229
- private isFirstLastInMonth ( checkLast : boolean ) : boolean {
230
- const inc = checkLast ? 1 : - 1 ;
231
- if ( ! this . isSingleSelection && this . isCurrentMonth && this . isWithinRange ) {
232
- const nextDay = new Date ( this . date . date ) ;
233
- nextDay . setDate ( nextDay . getDate ( ) + inc ) ;
234
- if ( this . date . date . getMonth ( ) + inc === nextDay . getMonth ( ) ) {
235
- return true ;
236
- }
237
- }
238
- return false ;
239
- }
240
193
241
194
@HostListener ( 'click' )
242
195
@HostListener ( 'keydown.enter' )
0 commit comments