-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
calendar-body.ts
103 lines (84 loc) · 2.73 KB
/
calendar-body.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
ViewEncapsulation
} from '@angular/core';
/**
* An internal class that represents the data corresponding to a single calendar cell.
* @docs-private
*/
export class MdCalendarCell {
constructor(public value: number,
public displayValue: string,
public ariaLabel: string,
public enabled: boolean) {}
}
/**
* An internal component used to display calendar data in a table.
* @docs-private
*/
@Component({
moduleId: module.id,
selector: '[md-calendar-body]',
templateUrl: 'calendar-body.html',
styleUrls: ['calendar-body.css'],
host: {
'class': 'mat-calendar-body',
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MdCalendarBody {
/** The label for the table. (e.g. "Jan 2017"). */
@Input() label: string;
/** The cells to display in the table. */
@Input() rows: MdCalendarCell[][];
/** The value in the table that corresponds to today. */
@Input() todayValue: number;
/** The value in the table that is currently selected. */
@Input() selectedValue: number;
/** The minimum number of free cells needed to fit the label in the first row. */
@Input() labelMinRequiredCells: number;
/** The number of columns in the table. */
@Input() numCols = 7;
/** Whether to allow selection of disabled cells. */
@Input() allowDisabledSelection = false;
/** The cell number of the active cell in the table. */
@Input() activeCell = 0;
/**
* The aspect ratio (width / height) to use for the cells in the table. This aspect ratio will be
* maintained even as the table resizes.
*/
@Input() cellAspectRatio = 1;
/** Emits when a new value is selected. */
@Output() selectedValueChange = new EventEmitter<number>();
_cellClicked(cell: MdCalendarCell): void {
if (!this.allowDisabledSelection && !cell.enabled) {
return;
}
this.selectedValueChange.emit(cell.value);
}
/** The number of blank cells to put at the beginning for the first row. */
get _firstRowOffset(): number {
return this.rows && this.rows.length && this.rows[0].length ?
this.numCols - this.rows[0].length : 0;
}
_isActiveCell(rowIndex: number, colIndex: number): boolean {
let cellNumber = rowIndex * this.numCols + colIndex;
// Account for the fact that the first row may not have as many cells.
if (rowIndex) {
cellNumber -= this._firstRowOffset;
}
return cellNumber == this.activeCell;
}
}