forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datepicker): add month & year view (angular#2904)
* date picker initial commit * month view * added month view functionality * more month view tweaking * started extracting common stuff to calendar-table. * base month view on calendar table * added year view * add disclaimers * addressed comments * fix lint * fixed aot and added comment * started on tests * calendar table tests * tests for month and year view * rebase on top of CalendarLocale & SimpleDate * add some additional functionality to SimpleDate * fix lint * addressed comments * add comment
- Loading branch information
Showing
24 changed files
with
793 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Work in progress, not ready for use.</h1> | ||
|
||
<md-month-view [date]="date" [(selected)]="selected"></md-month-view> | ||
<md-year-view [date]="date" [(selected)]="selected"></md-year-view> | ||
|
||
<br> | ||
<div>{{selected?.toNativeDate()}}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {Component} from '@angular/core'; | ||
import {SimpleDate} from '@angular/material'; | ||
|
||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'datepicker-demo', | ||
templateUrl: 'datepicker-demo.html' | ||
}) | ||
export class DatepickerDemo { | ||
date = SimpleDate.today(); | ||
selected: SimpleDate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# md-datepicker | ||
|
||
Work in progress, not ready for use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@import '../core/theming/palette'; | ||
@import '../core/theming/theming'; | ||
|
||
|
||
@mixin mat-datepicker-theme($theme) { | ||
$primary: map-get($theme, primary); | ||
$foreground: map-get($theme, foreground); | ||
$background: map-get($theme, background); | ||
|
||
.mat-calendar-table-label { | ||
color: md-color($foreground, secondary-text); | ||
} | ||
|
||
.mat-calendar-table-cell-content { | ||
color: md-color($foreground, text); | ||
|
||
.mat-calendar-table-cell:hover & { | ||
background: md-color($background, hover); | ||
} | ||
|
||
.mat-calendar-table-cell &.mat-calendar-table-selected { | ||
background: md-color($primary); | ||
color: md-color($primary, default-contrast); | ||
} | ||
|
||
&.mat-calendar-table-today { | ||
border-color: md-color($foreground, divider); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<table class="mat-calendar-table-table"> | ||
<!-- If there's not enough space in the first row, create a separate label row. --> | ||
<tr *ngIf="_firstRowOffset < labelMinRequiredCells"> | ||
<td class="mat-calendar-table-label" [attr.colspan]="numCols" >{{label}}</td> | ||
</tr> | ||
|
||
<!-- Create the first row separately so we can include a special spacer cell. --> | ||
<tr *ngFor="let row of rows; let i = index"> | ||
<td *ngIf="i === 0 && _firstRowOffset" | ||
class="mat-calendar-table-label" | ||
[attr.colspan]="_firstRowOffset"> | ||
{{_firstRowOffset >= labelMinRequiredCells ? label : ''}} | ||
</td> | ||
<td *ngFor="let item of row" | ||
class="mat-calendar-table-cell" | ||
(click)="_cellClicked(item.value)"> | ||
<div class="mat-calendar-table-cell-content" | ||
[class.mat-calendar-table-selected]="selectedValue === item.value" | ||
[class.mat-calendar-table-today]="todayValue === item.value"> | ||
{{item.displayValue}} | ||
</div> | ||
</td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
$mat-calendar-table-font-size: 12px !default; | ||
$mat-calendar-table-cell-padding: 1px !default; | ||
$mat-calendar-table-cell-content-size: 32px !default; | ||
$mat-calendar-table-cell-content-border-width: 1px !default; | ||
|
||
|
||
.mat-calendar-table-table { | ||
border-spacing: 0; | ||
font-size: $mat-calendar-table-font-size; | ||
} | ||
|
||
.mat-calendar-table-label { | ||
height: $mat-calendar-table-cell-content-size; | ||
padding: 0 0 0 10px; | ||
text-align: left; | ||
font-weight: normal; | ||
} | ||
|
||
.mat-calendar-table-cell { | ||
padding: $mat-calendar-table-cell-padding; | ||
} | ||
|
||
.mat-calendar-table-cell-content { | ||
display: table-cell; | ||
box-sizing: border-box; | ||
width: $mat-calendar-table-cell-content-size; | ||
height: $mat-calendar-table-cell-content-size; | ||
border: $mat-calendar-table-cell-content-border-width solid transparent; | ||
border-radius: 50%; | ||
text-align: center; | ||
vertical-align: middle; | ||
} | ||
|
||
[dir='rtl'] { | ||
.mat-calendar-table-label { | ||
padding: 0 10px 0 0; | ||
text-align: right; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import {async, TestBed, ComponentFixture} from '@angular/core/testing'; | ||
import {MdDatepickerModule} from './index'; | ||
import {Component} from '@angular/core'; | ||
import {MdCalendarTable, MdCalendarCell} from './calendar-table'; | ||
import {By} from '@angular/platform-browser'; | ||
|
||
|
||
describe('MdCalendarTable', () => { | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdDatepickerModule], | ||
declarations: [ | ||
StandardCalendarTable, | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('standard calendar table', () => { | ||
let fixture: ComponentFixture<StandardCalendarTable>; | ||
let testComponent: StandardCalendarTable; | ||
let calendarTableNativeElement: Element; | ||
let rowEls: NodeListOf<Element>; | ||
let labelEls: NodeListOf<Element>; | ||
let cellEls: NodeListOf<Element>; | ||
|
||
let refreshElementLists = () => { | ||
rowEls = calendarTableNativeElement.querySelectorAll('tr'); | ||
labelEls = calendarTableNativeElement.querySelectorAll('.mat-calendar-table-label'); | ||
cellEls = calendarTableNativeElement.querySelectorAll('.mat-calendar-table-cell'); | ||
}; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(StandardCalendarTable); | ||
fixture.detectChanges(); | ||
|
||
let calendarTableDebugElement = fixture.debugElement.query(By.directive(MdCalendarTable)); | ||
calendarTableNativeElement = calendarTableDebugElement.nativeElement; | ||
testComponent = fixture.componentInstance; | ||
|
||
refreshElementLists(); | ||
}); | ||
|
||
it('creates table', () => { | ||
expect(rowEls.length).toBe(3); | ||
expect(labelEls.length).toBe(1); | ||
expect(cellEls.length).toBe(14); | ||
}); | ||
|
||
it('highlights today', () => { | ||
let todayCell = calendarTableNativeElement.querySelector('.mat-calendar-table-today'); | ||
expect(todayCell).not.toBeNull(); | ||
expect(todayCell.innerHTML.trim()).toBe('3'); | ||
}); | ||
|
||
it('highlights selected', () => { | ||
let selectedCell = calendarTableNativeElement.querySelector('.mat-calendar-table-selected'); | ||
expect(selectedCell).not.toBeNull(); | ||
expect(selectedCell.innerHTML.trim()).toBe('4'); | ||
}); | ||
|
||
it('places label in first row if space is available', () => { | ||
testComponent.rows[0] = testComponent.rows[0].slice(3); | ||
testComponent.rows = testComponent.rows.slice(); | ||
fixture.detectChanges(); | ||
refreshElementLists(); | ||
|
||
expect(rowEls.length).toBe(2); | ||
expect(labelEls.length).toBe(1); | ||
expect(cellEls.length).toBe(11); | ||
expect(rowEls[0].firstElementChild.classList.contains('mat-calendar-table-label')).toBe( | ||
true, 'first cell should be the label'); | ||
expect(labelEls[0].getAttribute('colspan')).toBe('3'); | ||
}); | ||
|
||
it('cell should be selected on click', () => { | ||
let todayElement = | ||
calendarTableNativeElement.querySelector('.mat-calendar-table-today') as HTMLElement; | ||
todayElement.click(); | ||
fixture.detectChanges(); | ||
|
||
expect(todayElement.classList.contains('mat-calendar-table-selected')).toBe( | ||
true, 'today should be selected'); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
@Component({ | ||
template: `<md-calendar-table [label]="label" | ||
[rows]="rows" | ||
[todayValue]="todayValue" | ||
[selectedValue]="selectedValue" | ||
[labelMinRequiredCells]="labelMinRequiredCells" | ||
[numCols]="numCols" | ||
(selectedValueChange)="onSelect($event)"> | ||
</md-calendar-table>`, | ||
}) | ||
class StandardCalendarTable { | ||
label = 'Jan 2017'; | ||
rows = [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14]].map(r => r.map(createCell)); | ||
todayValue = 3; | ||
selectedValue = 4; | ||
labelMinRequiredCells = 3; | ||
numCols = 7; | ||
|
||
onSelect(value: number) { | ||
this.selectedValue = value; | ||
} | ||
} | ||
|
||
|
||
function createCell(value: number) { | ||
return new MdCalendarCell(value, `${value}`); | ||
} |
Oops, something went wrong.