Skip to content

Commit cfab254

Browse files
author
Matt Lewis
committed
feat(dayView): introduce the beforeViewRender output
BREAKING CHANGE: the `hourSegmentModifier` has been replaced with the `beforeViewRender` output.
1 parent eb6f73b commit cfab254

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/components/day/calendarDayView.component.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
170170
*/
171171
@Input() locale: string;
172172

173-
/**
174-
* A function that will be called before each hour segment is called. The first argument will contain the hour segment.
175-
* If you add the `cssClass` property to the segment it will add that class to the hour segment in the template
176-
*/
177-
@Input() hourSegmentModifier: Function;
178-
179173
/**
180174
* The grid size to snap resizing and dragging of events to
181175
*/
@@ -221,6 +215,12 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
221215
*/
222216
@Output() eventTimesChanged: EventEmitter<CalendarEventTimesChangedEvent> = new EventEmitter<CalendarEventTimesChangedEvent>();
223217

218+
/**
219+
* An output that will be called before the view is rendered for the current day.
220+
* If you add the `cssClass` property to a segment it will add that class to the hour segment in the template
221+
*/
222+
@Output() beforeViewRender: EventEmitter<{body: DayViewHour[]}> = new EventEmitter();
223+
224224
/**
225225
* @hidden
226226
*/
@@ -399,11 +399,9 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
399399
minute: this.dayEndMinute
400400
}
401401
});
402-
if (this.hourSegmentModifier) {
403-
this.hours.forEach(hour => {
404-
hour.segments.forEach(segment => this.hourSegmentModifier(segment));
405-
});
406-
}
402+
this.beforeViewRender.emit({
403+
body: this.hours
404+
});
407405
}
408406

409407
private refreshView(): void {

test/calendarDayView.component.spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,16 @@ describe('CalendarDayViewComponent component', () => {
251251
fixture.destroy();
252252
});
253253

254-
it('should add a custom CSS class to days via the hour segment modifier', () => {
254+
it('should add a custom CSS class to days via the beforeViewRender output', () => {
255255
const fixture: ComponentFixture<CalendarDayViewComponent> = TestBed.createComponent(CalendarDayViewComponent);
256256
fixture.componentInstance.viewDate = new Date('2016-06-27');
257-
fixture.componentInstance.hourSegmentModifier = segment => {
258-
segment.cssClass = 'foo';
259-
};
257+
fixture.componentInstance.beforeViewRender.take(1).subscribe(({body}) => {
258+
body.forEach((hour) => {
259+
hour.segments.forEach((segment) => {
260+
segment.cssClass = 'foo';
261+
});
262+
});
263+
});
260264
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
261265
fixture.detectChanges();
262266
expect(fixture.nativeElement.querySelector('.cal-hour-segment').classList.contains('foo')).to.equal(true);

0 commit comments

Comments
 (0)