Skip to content

Commit 067d052

Browse files
committed
docs(material/timepicker): add timepicker documentation and live examples
Populates the timepicker's guide and add live examples.
1 parent 1e4aa1b commit 067d052

16 files changed

+528
-1
lines changed

src/components-examples/material/timepicker/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ ng_module(
1515
deps = [
1616
"//src/cdk/testing",
1717
"//src/cdk/testing/testbed",
18+
"//src/material/datepicker",
19+
"//src/material/form-field",
20+
"//src/material/icon",
21+
"//src/material/input",
1822
"//src/material/timepicker",
1923
"//src/material/timepicker/testing",
24+
"@npm//@angular/common",
25+
"@npm//@angular/forms",
2026
"@npm//@angular/platform-browser",
2127
"@npm//@types/jasmine",
2228
],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
export {TimepickerOverviewExample} from './timepicker-overview/timepicker-overview-example';
2+
export {TimepickerFormsExample} from './timepicker-forms/timepicker-forms-example';
3+
export {TimepickerDatepickerIntegrationExample} from './timepicker-datepicker-integration/timepicker-datepicker-integration-example';
4+
export {TimepickerValidationExample} from './timepicker-validation/timepicker-validation-example';
5+
export {TimepickerOptionsExample} from './timepicker-options/timepicker-options-example';
6+
export {TimepickerCustomIconExample} from './timepicker-custom-icon/timepicker-custom-icon-example';
27
export {TimepickerHarnessExample} from './timepicker-harness/timepicker-harness-example';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<mat-form-field>
2+
<mat-label>Pick a time</mat-label>
3+
<input matInput [matTimepicker]="picker">
4+
<mat-timepicker-toggle matIconSuffix [for]="picker">
5+
<mat-icon matTimepickerToggleIcon>globe</mat-icon>
6+
</mat-timepicker-toggle>
7+
<mat-timepicker #picker/>
8+
</mat-form-field>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {ChangeDetectionStrategy, Component} from '@angular/core';
2+
import {MatTimepickerModule} from '@angular/material/timepicker';
3+
import {MatIcon} from '@angular/material/icon';
4+
import {MatInputModule} from '@angular/material/input';
5+
import {MatFormFieldModule} from '@angular/material/form-field';
6+
import {provideNativeDateAdapter} from '@angular/material/core';
7+
8+
/** @title Timepicker with custom toggle icon */
9+
@Component({
10+
selector: 'timepicker-custom-icon-example',
11+
templateUrl: 'timepicker-custom-icon-example.html',
12+
providers: [provideNativeDateAdapter()],
13+
imports: [MatFormFieldModule, MatInputModule, MatTimepickerModule, MatIcon],
14+
changeDetection: ChangeDetectionStrategy.OnPush,
15+
})
16+
export class TimepickerCustomIconExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mat-form-field {
2+
margin-right: 16px;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<mat-form-field>
2+
<mat-label>Meeting date</mat-label>
3+
<input matInput [matDatepicker]="datepicker" [(ngModel)]="value">
4+
<mat-datepicker #datepicker/>
5+
<mat-datepicker-toggle [for]="datepicker" matSuffix/>
6+
</mat-form-field>
7+
8+
<mat-form-field>
9+
<mat-label>Meeting time</mat-label>
10+
<input matInput
11+
[matTimepicker]="timepicker"
12+
[(ngModel)]="value"
13+
[ngModelOptions]="{updateOn: 'blur'}">
14+
<mat-timepicker #timepicker/>
15+
<mat-timepicker-toggle [for]="timepicker" matSuffix/>
16+
</mat-form-field>
17+
18+
<p>Value: {{value}}</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {ChangeDetectionStrategy, Component} from '@angular/core';
2+
import {FormsModule} from '@angular/forms';
3+
import {MatTimepickerModule} from '@angular/material/timepicker';
4+
import {MatInputModule} from '@angular/material/input';
5+
import {MatFormFieldModule} from '@angular/material/form-field';
6+
import {provideNativeDateAdapter} from '@angular/material/core';
7+
import {MatDatepickerModule} from '@angular/material/datepicker';
8+
9+
/** @title Timepicker integration with datepicker */
10+
@Component({
11+
selector: 'timepicker-datepicker-integration-example',
12+
templateUrl: 'timepicker-datepicker-integration-example.html',
13+
styleUrl: './timepicker-datepicker-integration-example.css',
14+
providers: [provideNativeDateAdapter()],
15+
imports: [
16+
MatFormFieldModule,
17+
MatInputModule,
18+
MatTimepickerModule,
19+
MatDatepickerModule,
20+
FormsModule,
21+
],
22+
changeDetection: ChangeDetectionStrategy.OnPush,
23+
})
24+
export class TimepickerDatepickerIntegrationExample {
25+
value: Date;
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<mat-form-field>
2+
<mat-label>Pick a time</mat-label>
3+
<input matInput [formControl]="formControl" [matTimepicker]="picker">
4+
<mat-timepicker-toggle matIconSuffix [for]="picker"/>
5+
<mat-timepicker #picker/>
6+
</mat-form-field>
7+
8+
<p>Value: {{formControl.value}}</p>
9+
<p>Touched: {{formControl.touched}}</p>
10+
<p>Dirty: {{formControl.dirty}}</p>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {ChangeDetectionStrategy, Component} from '@angular/core';
2+
import {FormControl, ReactiveFormsModule} from '@angular/forms';
3+
import {MatTimepickerModule} from '@angular/material/timepicker';
4+
import {MatInputModule} from '@angular/material/input';
5+
import {MatFormFieldModule} from '@angular/material/form-field';
6+
import {provideNativeDateAdapter} from '@angular/material/core';
7+
8+
/** @title Timepicker forms integration */
9+
@Component({
10+
selector: 'timepicker-forms-example',
11+
templateUrl: 'timepicker-forms-example.html',
12+
providers: [provideNativeDateAdapter()],
13+
imports: [MatFormFieldModule, MatInputModule, MatTimepickerModule, ReactiveFormsModule],
14+
changeDetection: ChangeDetectionStrategy.OnPush,
15+
})
16+
export class TimepickerFormsExample {
17+
formControl: FormControl<Date | null>;
18+
19+
constructor() {
20+
const initialValue = new Date();
21+
initialValue.setHours(12, 30, 0);
22+
this.formControl = new FormControl(initialValue);
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h3>Interval examples</h3>
2+
3+
<div>
4+
<mat-form-field>
5+
<mat-label>Every 45 minutes</mat-label>
6+
<input matInput [matTimepicker]="minutesPicker">
7+
<mat-timepicker-toggle matIconSuffix [for]="minutesPicker"/>
8+
<mat-timepicker interval="45min" #minutesPicker/>
9+
</mat-form-field>
10+
</div>
11+
12+
<div>
13+
<mat-form-field>
14+
<mat-label>Every 3.5 hours</mat-label>
15+
<input matInput [matTimepicker]="hoursPicker">
16+
<mat-timepicker-toggle matIconSuffix [for]="hoursPicker"/>
17+
<mat-timepicker interval="3.5h" #hoursPicker/>
18+
</mat-form-field>
19+
</div>
20+
21+
<h3>Custom list of options</h3>
22+
23+
<div>
24+
<mat-form-field>
25+
<mat-label>Pick a time of day</mat-label>
26+
<input matInput [matTimepicker]="customPicker">
27+
<mat-timepicker-toggle matIconSuffix [for]="customPicker"/>
28+
<mat-timepicker [options]="customOptions" #customPicker/>
29+
</mat-form-field>
30+
</div>

0 commit comments

Comments
 (0)