Skip to content

Commit 17d6346

Browse files
amcdnlmmalerba
authored andcommitted
docs(datepicker): datepicker overview demos (#5273)
* docs(datepicker): datepicker overview demos * chore(*): rename `DatePickerAPIExample` to `DatepickerApiExample` * chore(*): files end w/ new lines * chore(demo): update date filter demo to exclude weekends * docs(datepicker): add comments to filter * chore(lint): fix lint errors
1 parent 4a959e9 commit 17d6346

17 files changed

+107
-29
lines changed

src/lib/datepicker/datepicker.md

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The datepicker allows users to enter a date either through text input, or by choosing a date from
22
the calendar. It is made up of several components and directives that work together:
33

4-
<!-- TODO: INSERT OVERVIEW EXAMPLE HERE -->
4+
<!-- example(datepicker-overview) -->
55

66
### Current state
77
Currently the datepicker is in the beginning stages and supports basic date selection functionality.
@@ -51,14 +51,7 @@ open to the month or year containing today's date. This behavior can be overridd
5151
`startAt` property of `md-datepicker`. In this case the calendar will open to the month or year
5252
containing the `startAt` date.
5353

54-
```ts
55-
startDate = new Date(1990, 0, 1);
56-
```
57-
58-
```html
59-
...
60-
<md-datepicker startView="year" [startAt]="startDate"></md-datepicker>
61-
```
54+
<!-- example(datepicker-start-view) -->
6255

6356
### Date validation
6457
There are three properties that add date validation to the datepicker input. The first two are the
@@ -67,6 +60,8 @@ disable all dates on the calendar popup before or after the respective values an
6760
from advancing the calendar past the `month` or `year` (depending on current view) containing the
6861
`min` or `max` date.
6962

63+
<!-- example(datepicker-min-max) -->
64+
7065
The second way to add date validation is using the `mdDatepickerFilter` property of the datepicker
7166
input. This property accepts a function of `<D> => boolean` (where `<D>` is the date type used by
7267
the datepicker, see section on
@@ -77,16 +72,7 @@ difference between using `mdDatepickerFilter` vs using `min` or `max` is that fi
7772
dates before or after a certain point, will not prevent the user from advancing the calendar past
7873
that point.
7974

80-
```ts
81-
myFilter = (d: Date) => d.getFullYear() > 2005
82-
minDate = new Date(2000, 0, 1);
83-
maxDate = new Date(2020, 11, 31);
84-
```
85-
86-
```html
87-
<input [mdDatepicker]="d" [mdDatepickerFilter]="myFilter" [min]="minDate" [max]="maxDate" ngModel>
88-
<md-datepicker #d></md-datepicker>
89-
```
75+
<!-- example(datepicker-filter) -->
9076

9177
In this example the user can back past 2005, but all of the dates before then will be unselectable.
9278
They will not be able to go further back in the calendar than 2000. If they manually type in a date
@@ -103,20 +89,13 @@ devices that don't have as much screen real estate and need bigger click targets
10389
`md-datepicker` has a `touchUi` property that can be set to `true` in order to enable a more touch
10490
friendly UI where the calendar opens in a large dialog.
10591

92+
<!-- example(datepicker-touch) -->
93+
10694
### Manually opening and closing the calendar
10795
The calendar popup can be programmatically controlled using the `open` and `close` methods on the
10896
`md-datepicker`. It also has an `opened` property that reflects the status of the popup.
10997

110-
```ts
111-
@Component({...})
112-
export class MyComponent implements AfterViewInit {
113-
@ViewChild(MdDatepicker) dp: MdDatepicker<Date>;
114-
115-
ngAfterViewInit() {
116-
dp.open();
117-
}
118-
}
119-
```
98+
<!-- example(datepicker-api) -->
12099

121100
### Internationalization
122101
In order to support internationalization, the datepicker supports customization of the following
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<md-input-container class="example-full-width">
2+
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
3+
</md-input-container>
4+
<md-datepicker #picker></md-datepicker>
5+
<button md-raised-button (click)="picker.open()">Open</button>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'datepicker-api-example',
5+
templateUrl: 'datepicker-api-example.html',
6+
styleUrls: ['datepicker-api-example.css'],
7+
})
8+
export class DatepickerApiExample {
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<md-input-container class="example-full-width">
2+
<input mdInput [mdDatepickerFilter]="myFilter" [mdDatepicker]="picker" placeholder="Choose a date">
3+
<button mdSuffix [mdDatepickerToggle]="picker"></button>
4+
</md-input-container>
5+
<md-datepicker #picker></md-datepicker>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'datepicker-filter-example',
5+
templateUrl: 'datepicker-filter-example.html',
6+
styleUrls: ['datepicker-filter-example.css'],
7+
})
8+
export class DatepickerFilterExample {
9+
myFilter = (d: Date): boolean => {
10+
const day = d.getDay();
11+
// Prevent Saturday and Sunday from being selected.
12+
return day !== 0 && day !== 6;
13+
}
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<md-input-container class="example-full-width">
2+
<input mdInput [min]="minDate" [max]="maxDate" [mdDatepicker]="picker" placeholder="Choose a date">
3+
<button mdSuffix [mdDatepickerToggle]="picker"></button>
4+
</md-input-container>
5+
<md-datepicker #picker></md-datepicker>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'datepicker-min-max-example',
5+
templateUrl: 'datepicker-min-max-example.html',
6+
styleUrls: ['datepicker-min-max-example.css'],
7+
})
8+
export class DatepickerMinMaxExample {
9+
minDate = new Date(2000, 0, 1);
10+
maxDate = new Date(2020, 0, 1);
11+
}

0 commit comments

Comments
 (0)