Skip to content

Commit ade32c6

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

18 files changed

+565
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ ng_module(
1515
deps = [
1616
"//src/cdk/testing",
1717
"//src/cdk/testing/testbed",
18+
"//src/material/button",
19+
"//src/material/datepicker",
20+
"//src/material/form-field",
21+
"//src/material/icon",
22+
"//src/material/input",
1823
"//src/material/timepicker",
1924
"//src/material/timepicker/testing",
25+
"@npm//@angular/common",
26+
"@npm//@angular/forms",
2027
"@npm//@angular/platform-browser",
2128
"@npm//@types/jasmine",
2229
],
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
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';
7+
export {TimepickerLocaleExample} from './timepicker-locale/timepicker-locale-example';
28
export {TimepickerHarnessExample} from './timepicker-harness/timepicker-harness-example';
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: 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 [(ngModel)]="value" [matTimepicker]="picker">
4+
<mat-timepicker-toggle matIconSuffix [for]="picker"/>
5+
<mat-timepicker #picker/>
6+
</mat-form-field>
7+
8+
<button mat-button (click)="switchLocale()">Dynamically switch to Bulgarian</button>

0 commit comments

Comments
 (0)