Skip to content

Commit

Permalink
feat(emptyWeekColumnClass): add emptyWeekColumnClass attribute to add…
Browse files Browse the repository at this point in the history
… a custom class for all date in a week not in the current month

Fixes #315 #294 #126
  • Loading branch information
fetrarij committed Sep 1, 2020
1 parent 7c3265b commit ba1d136
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -227,7 +227,8 @@ You can use theses options:
| --- | --- |--- |
| firstMonthDayClass | string | add a custom class for all first day of the month |
| lastMonthDayClass | string | add a custom class for all last day of the month |
| emptyWeekRowClass | string | add a custom class for all date in a week not in the current month |
| emptyWeekRowClass | string | add a custom class in a row with a date in a week not in the current month |
| emptyWeekColumnClass | string | add a custom class for all date in a week not in the current month |
| lastDayOfPreviousMonthClass | string | add a custom class for the last day of the previous month |
| firstDayOfNextMonthClass | string | add a custom class for the first day of the next month |

Expand Down
3 changes: 2 additions & 1 deletion demo/src/app/full/full.component.html
Expand Up @@ -26,7 +26,8 @@
[closeOnAutoApply]="options.closeOnAutoApply"
firstMonthDayClass="first-day"
lastMonthDayClass="last-day"
emptyWeekRowClass="empty-week"
emptyWeekRowClass="empty-week-row"
emptyWeekColumnClass="empty-week-column"
lastDayOfPreviousMonthClass="last-previous-day"
firstDayOfNextMonthClass="first-next-day"
[opens]="opens"
Expand Down
15 changes: 9 additions & 6 deletions demo/src/styles.scss
Expand Up @@ -7,17 +7,20 @@
color: white !important;
}
.first-day {
background-color: greenyellow;
background-color: greenyellow !important;
}
.last-day {
background-color: green;
background-color: green !important;
}
.empty-week {
background-color: rosybrown;
.empty-week-row {
background-color: rosybrown !important;
}
.empty-week-column {
background-color: rgb(133, 45, 45) !important;
}
.last-previous-day {
background-color: rgb(218, 226, 145);
background-color: rgb(218, 226, 145) !important;
}
.first-next-day {
background-color: rgb(229, 255, 0);
background-color: rgb(229, 255, 0) !important;
}
13 changes: 12 additions & 1 deletion src/daterangepicker/daterangepicker.component.ts
Expand Up @@ -86,6 +86,8 @@ export class DaterangepickerComponent implements OnInit {
@Input()
emptyWeekRowClass: string = null;
@Input()
emptyWeekColumnClass: string = null;
@Input()
firstDayOfNextMonthClass: string = null;
@Input()
lastDayOfPreviousMonthClass: string = null;
Expand Down Expand Up @@ -1161,11 +1163,20 @@ export class DaterangepickerComponent implements OnInit {
for (let row = 0; row < 6; row++) {
this.calendarVariables[side].classes[row] = {};
const rowClasses = [];
if (this.emptyWeekRowClass && !this.hasCurrentMonthDays(this.calendarVariables[side].month, calendar[row])) {
if (
this.emptyWeekRowClass &&
Array.from(Array(7).keys()).some(i => calendar[row][i].month() !== this.calendarVariables[side].month)
) {
rowClasses.push(this.emptyWeekRowClass);
}
for (let col = 0; col < 7; col++) {
const classes = [];
// empty week row class
if (this.emptyWeekColumnClass) {
if (calendar[row][col].month() !== this.calendarVariables[side].month) {
classes.push(this.emptyWeekColumnClass);
}
}
// highlight today's date
if (calendar[row][col].isSame(new Date(), 'day')) {
classes.push('today');
Expand Down
3 changes: 3 additions & 0 deletions src/daterangepicker/daterangepicker.directive.ts
Expand Up @@ -92,6 +92,8 @@ export class DaterangepickerDirective implements OnInit, OnChanges, DoCheck {
@Input()
emptyWeekRowClass: string;
@Input()
emptyWeekColumnClass: string;
@Input()
firstDayOfNextMonthClass: string;
@Input()
lastDayOfPreviousMonthClass: string;
Expand Down Expand Up @@ -203,6 +205,7 @@ export class DaterangepickerDirective implements OnInit, OnChanges, DoCheck {
this.picker.firstMonthDayClass = this.firstMonthDayClass;
this.picker.lastMonthDayClass = this.lastMonthDayClass;
this.picker.emptyWeekRowClass = this.emptyWeekRowClass;
this.picker.emptyWeekColumnClass = this.emptyWeekColumnClass;
this.picker.firstDayOfNextMonthClass = this.firstDayOfNextMonthClass;
this.picker.lastDayOfPreviousMonthClass = this.lastDayOfPreviousMonthClass;
this.picker.drops = this.drops;
Expand Down

0 comments on commit ba1d136

Please sign in to comment.