igniteui-angular-sovn
Version:
Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps
169 lines (132 loc) • 4.4 kB
text/typescript
import { Component, Input, Output, EventEmitter, HostBinding, ElementRef, HostListener } from '@angular/core';
import { CalendarSelection, ICalendarDate, isDateInRanges } from '../calendar';
import { DateRangeDescriptor } from '../../core/dates';
/**
* @hidden
*/
export class IgxDayItemComponent {
public date: ICalendarDate;
public selection: string;
/**
* Returns boolean indicating if the day is selected
*
*/
public get selected(): any {
return this._selected;
}
/**
* Selects the day
*/
public set selected(value: any) {
this._selected = value;
}
public disabledDates: DateRangeDescriptor[];
public outOfRangeDates: DateRangeDescriptor[];
public specialDates: DateRangeDescriptor[];
public hideOutsideDays = false;
public isLastInRange = false;
public isFirstInRange = false;
public isWithinRange = false;
public dateSelection = new EventEmitter<ICalendarDate>();
public get isCurrentMonth(): boolean {
return this.date.isCurrentMonth;
}
public get isPreviousMonth(): boolean {
return this.date.isPrevMonth;
}
public get isNextMonth(): boolean {
return this.date.isNextMonth;
}
public get nativeElement() {
return this.elementRef.nativeElement;
}
public get isSelectedCSS(): boolean {
return (!this.isDisabled && this.selected);
}
public get isInactive(): boolean {
return this.date.isNextMonth || this.date.isPrevMonth;
}
public get isHidden(): boolean {
return this.hideOutsideDays && this.isInactive;
}
public get isToday(): boolean {
const today = new Date(Date.now());
const date = this.date.date;
if (date.getDate() === today.getDate()) {
this.nativeElement.setAttribute('aria-current', 'date');
}
return (date.getFullYear() === today.getFullYear() &&
date.getMonth() === today.getMonth() &&
date.getDate() === today.getDate()
);
}
public get isWeekend(): boolean {
const day = this.date.date.getDay();
return day === 0 || day === 6;
}
public get isDisabled(): boolean {
if (this.disabledDates === null) {
return false;
}
return isDateInRanges(this.date.date, this.disabledDates);
}
public get isOutOfRange(): boolean {
if (!this.outOfRangeDates) {
return false;
}
return isDateInRanges(this.date.date, this.outOfRangeDates);
}
public get isFocusable(): boolean {
return this.isCurrentMonth && !this.isHidden && !this.isDisabled && !this.isOutOfRange;
}
public get isWithinRangeCSS(): boolean {
return !this.isSingleSelection && this.isWithinRange;
}
public get isSpecial(): boolean {
if (this.specialDates === null) {
return false;
}
return isDateInRanges(this.date.date, this.specialDates);
}
public get isDisabledCSS(): boolean {
return this.isHidden || this.isDisabled || this.isOutOfRange;
}
public get isSingleSelection(): boolean {
return this.selection !== CalendarSelection.RANGE;
}
private _selected = false;
constructor(private elementRef: ElementRef) { }
public onSelect(event) {
event.stopPropagation();
this.dateSelection.emit(this.date);
}
}