/
datepicker-month-view.ts
51 lines (47 loc) · 1.99 KB
/
datepicker-month-view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {Component, Input, TemplateRef, Output, EventEmitter, ViewEncapsulation} from '@angular/core';
import {MonthViewModel, DayViewModel} from './datepicker-view-model';
import {NgbDate} from './ngb-date';
import {NgbDatepickerI18n} from './datepicker-i18n';
import {DayTemplateContext} from './datepicker-day-template-context';
@Component({
selector: 'ngb-datepicker-month-view',
host: {'role': 'grid'},
encapsulation: ViewEncapsulation.None,
styleUrls: ['./datepicker-month-view.scss'],
template: `
<div *ngIf="showWeekdays" class="ngb-dp-week ngb-dp-weekdays">
<div *ngIf="showWeekNumbers" class="ngb-dp-weekday ngb-dp-showweek"></div>
<div *ngFor="let w of month.weekdays" class="ngb-dp-weekday small" role="columnheader">
{{ i18n.getWeekdayShortName(w) }}
</div>
</div>
<ng-template ngFor let-week [ngForOf]="month.weeks">
<div *ngIf="!week.collapsed" class="ngb-dp-week" role="row">
<div *ngIf="showWeekNumbers" class="ngb-dp-week-number small text-muted">{{ i18n.getWeekNumerals(week.number) }}</div>
<div *ngFor="let day of week.days" (click)="doSelect(day)" class="ngb-dp-day" role="gridcell"
[class.disabled]="day.context.disabled"
[tabindex]="day.tabindex"
[class.hidden]="day.hidden"
[class.ngb-dp-today]="day.context.today"
[attr.aria-label]="day.ariaLabel">
<ng-template [ngIf]="!day.hidden">
<ng-template [ngTemplateOutlet]="dayTemplate" [ngTemplateOutletContext]="day.context"></ng-template>
</ng-template>
</div>
</div>
</ng-template>
`
})
export class NgbDatepickerMonthView {
@Input() dayTemplate: TemplateRef<DayTemplateContext>;
@Input() month: MonthViewModel;
@Input() showWeekdays;
@Input() showWeekNumbers;
@Output() select = new EventEmitter<NgbDate>();
constructor(public i18n: NgbDatepickerI18n) {}
doSelect(day: DayViewModel) {
if (!day.context.disabled && !day.hidden) {
this.select.emit(day.date);
}
}
}