ipsos-components
Version:
Material Design components for Angular
106 lines (86 loc) • 2.96 kB
text/typescript
/**
* @license
* Copyright Google LLC 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 MatCalendarCell {
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
*/
export class MatCalendarBody {
/** The label for the table. (e.g. "Jan 2017"). */
label: string;
/** The cells to display in the table. */
rows: MatCalendarCell[][];
/** The value in the table that corresponds to today. */
todayValue: number;
/** The value in the table that is currently selected. */
selectedValue: number;
/** The minimum number of free cells needed to fit the label in the first row. */
labelMinRequiredCells: number;
/** The number of columns in the table. */
numCols = 7;
/** Whether to allow selection of disabled cells. */
allowDisabledSelection = false;
/** The cell number of the active cell in the table. */
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.
*/
cellAspectRatio = 1;
/** Emits when a new value is selected. */
selectedValueChange = new EventEmitter<number>();
_cellClicked(cell: MatCalendarCell): 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;
}
}