-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datepicker): allow custom classes to be applied to individual da…
…tes (#13971) Adds the `dateClass` function which allows consumers to apply custom CSS classes to specific dates. This is useful for highlighting specific dates like a holiday. Fixes #13943.
- Loading branch information
1 parent
69ffd33
commit 4be1b06
Showing
13 changed files
with
106 additions
and
9 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
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
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
4 changes: 4 additions & 0 deletions
4
src/material-examples/datepicker-date-class/datepicker-date-class-example.css
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,4 @@ | ||
.example-custom-date-class { | ||
background: orange; | ||
border-radius: 100%; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/material-examples/datepicker-date-class/datepicker-date-class-example.html
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,5 @@ | ||
<mat-form-field class="example-full-width"> | ||
<input matInput [matDatepicker]="picker" placeholder="Choose a date"> | ||
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle> | ||
<mat-datepicker [dateClass]="dateClass" #picker></mat-datepicker> | ||
</mat-form-field> |
17 changes: 17 additions & 0 deletions
17
src/material-examples/datepicker-date-class/datepicker-date-class-example.ts
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,17 @@ | ||
import {Component, ViewEncapsulation} from '@angular/core'; | ||
|
||
/** @title Datepicker with custom date classes */ | ||
@Component({ | ||
selector: 'datepicker-date-class-example', | ||
templateUrl: 'datepicker-date-class-example.html', | ||
styleUrls: ['datepicker-date-class-example.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class DatepickerDateClassExample { | ||
dateClass = (d: Date) => { | ||
const date = d.getDate(); | ||
|
||
// Highlight the 1st and 20th day of each month. | ||
return (date === 1 || date === 20) ? 'example-custom-date-class' : undefined; | ||
} | ||
} |