Skip to content

Commit 068d08b

Browse files
author
Matt Lewis
committed
feat(weekView): allow a custom css class to be added to a column header
Closes #222
1 parent abf02d8 commit 068d08b

3 files changed

+22
-0
lines changed

src/components/week/calendarWeekView.component.ts

+9
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
165165
*/
166166
@Output() eventTimesChanged: EventEmitter<CalendarEventTimesChangedEvent> = new EventEmitter<CalendarEventTimesChangedEvent>();
167167

168+
/**
169+
* An output that will be called before the view is rendered for the current week.
170+
* If you add the `cssClass` property to a day in the header it will add that class to the cell element in the template
171+
*/
172+
@Output() beforeViewRender: EventEmitter<{header: WeekDay[]}> = new EventEmitter();
173+
168174
/**
169175
* @hidden
170176
*/
@@ -339,6 +345,9 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
339345
excluded: this.excludeDays,
340346
weekendDays: this.weekendDays
341347
});
348+
this.beforeViewRender.emit({
349+
header: this.days
350+
});
342351
}
343352

344353
private refreshBody(): void {

src/components/week/calendarWeekViewHeader.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CalendarEvent, WeekDay } from 'calendar-utils';
1414
[class.cal-future]="day.isFuture"
1515
[class.cal-weekend]="day.isWeekend"
1616
[class.cal-drag-over]="day.dragOver"
17+
[ngClass]="day.cssClass"
1718
(mwlClick)="dayClicked.emit({date: day.date})"
1819
mwlDroppable
1920
(dragEnter)="day.dragOver = true"

test/calendarWeekView.component.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,16 @@ describe('calendarWeekView component', () => {
547547
fixture.destroy();
548548
});
549549

550+
it('should add a custom CSS class to headers via the beforeViewRender output', () => {
551+
const fixture: ComponentFixture<CalendarWeekViewComponent> = TestBed.createComponent(CalendarWeekViewComponent);
552+
fixture.componentInstance.viewDate = new Date('2016-06-27');
553+
fixture.componentInstance.beforeViewRender.take(1).subscribe(({header}) => {
554+
header[0].cssClass = 'foo';
555+
});
556+
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
557+
fixture.detectChanges();
558+
expect(fixture.nativeElement.querySelector('.cal-header').classList.contains('foo')).to.equal(true);
559+
fixture.destroy();
560+
});
561+
550562
});

0 commit comments

Comments
 (0)