Skip to content

Commit 7789fda

Browse files
committed
feat(week-view): add minimumEventHeight option
BREAKING CHANGE: events on the week and day view will now always be at least 30 pixels high by default. To restore the old behaviour you can set `[minimumEventHeight]="1"`. Closes #1192
1 parent 6a72448 commit 7789fda

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

projects/angular-calendar/src/modules/day/calendar-day-view.component.ts

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type CalendarDayViewBeforeRenderEvent = CalendarWeekViewBeforeRenderEvent
3434
[hourSegments]="hourSegments"
3535
[hourDuration]="hourDuration"
3636
[hourSegmentHeight]="hourSegmentHeight"
37+
[minimumEventHeight]="minimumEventHeight"
3738
[dayStartHour]="dayStartHour"
3839
[dayStartMinute]="dayStartMinute"
3940
[dayEndHour]="dayEndHour"
@@ -86,6 +87,11 @@ export class CalendarDayViewComponent {
8687
*/
8788
@Input() hourDuration: number;
8889

90+
/**
91+
* The minimum height in pixels of each event
92+
*/
93+
@Input() minimumEventHeight: number = 30;
94+
8995
/**
9096
* The day start hours in 24 hour time. Must be 0-23
9197
*/

projects/angular-calendar/src/modules/week/calendar-week-view.component.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
508508
*/
509509
@Input() hourSegmentHeight: number = 30;
510510

511+
/**
512+
* The minimum height in pixels of each event
513+
*/
514+
@Input() minimumEventHeight: number = 30;
515+
511516
/**
512517
* The day start hours in 24 hour time. Must be 0-23
513518
*/
@@ -754,7 +759,8 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
754759
changes.excludeDays ||
755760
changes.hourSegmentHeight ||
756761
changes.events ||
757-
changes.daysInWeek;
762+
changes.daysInWeek ||
763+
changes.minimumEventHeight;
758764

759765
if (refreshHeader) {
760766
this.refreshHeader();
@@ -1148,6 +1154,7 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
11481154
},
11491155
segmentHeight: this.hourSegmentHeight,
11501156
weekendDays: this.weekendDays,
1157+
minimumEventHeight: this.minimumEventHeight,
11511158
...getWeekViewPeriod(
11521159
this.dateAdapter,
11531160
this.viewDate,

projects/angular-calendar/test/calendar-week-view.component.spec.ts

+37-17
Original file line numberDiff line numberDiff line change
@@ -2246,16 +2246,16 @@ describe('calendarWeekView component', () => {
22462246
.add(18, 'hours')
22472247
.toDate(),
22482248
title: 'foo',
2249-
draggable: true
2250-
}
2249+
draggable: true,
2250+
},
22512251
];
22522252
fixture.componentInstance.hourDuration = 40;
22532253
fixture.componentInstance.ngOnChanges({
22542254
viewDate: {},
22552255
events: {},
22562256
excludeDays: {},
22572257
daysInWeek: {},
2258-
hourColumns: {}
2258+
hourColumns: {},
22592259
});
22602260
fixture.detectChanges();
22612261
document.body.appendChild(fixture.nativeElement);
@@ -2265,24 +2265,24 @@ describe('calendarWeekView component', () => {
22652265
const dayWidth: number = events[0].parentElement.offsetWidth;
22662266
const rect1: ClientRect = events[0].getBoundingClientRect();
22672267
let dragEvent: CalendarEventTimesChangedEvent;
2268-
fixture.componentInstance.eventTimesChanged.pipe(take(1)).subscribe(e => {
2268+
fixture.componentInstance.eventTimesChanged.pipe(take(1)).subscribe((e) => {
22692269
dragEvent = e;
22702270
});
22712271
triggerDomEvent('mousedown', events[0], {
22722272
clientX: rect1.right,
22732273
clientY: rect1.bottom,
2274-
button: 0
2274+
button: 0,
22752275
});
22762276
fixture.detectChanges();
22772277
triggerDomEvent('mousemove', events[0], {
22782278
clientX: rect1.right + dayWidth - 5,
2279-
clientY: rect1.bottom + 95
2279+
clientY: rect1.bottom + 95,
22802280
});
22812281
fixture.detectChanges();
22822282
triggerDomEvent('mouseup', events[0], {
22832283
clientX: rect1.right + dayWidth - 5,
22842284
clientY: rect1.bottom + 95,
2285-
button: 0
2285+
button: 0,
22862286
});
22872287
fixture.detectChanges();
22882288
fixture.destroy();
@@ -2297,7 +2297,7 @@ describe('calendarWeekView component', () => {
22972297
newEnd: moment(fixture.componentInstance.events[0].end)
22982298
.add(3, 'days')
22992299
.add(1, 'hour')
2300-
.toDate()
2300+
.toDate(),
23012301
});
23022302
});
23032303

@@ -2379,6 +2379,7 @@ describe('calendarWeekView component', () => {
23792379
},
23802380
},
23812381
];
2382+
fixture.componentInstance.minimumEventHeight = 1;
23822383
fixture.componentInstance.hourSegmentHeight = 20;
23832384
fixture.componentInstance.ngOnChanges({
23842385
viewDate: {},
@@ -2441,17 +2442,18 @@ describe('calendarWeekView component', () => {
24412442
.toDate(),
24422443
title: 'foo',
24432444
resizable: {
2444-
afterEnd: true
2445-
}
2446-
}
2445+
afterEnd: true,
2446+
},
2447+
},
24472448
];
24482449
fixture.componentInstance.hourDuration = 40;
2450+
fixture.componentInstance.minimumEventHeight = 1;
24492451
fixture.componentInstance.hourSegmentHeight = 20;
24502452
fixture.componentInstance.ngOnChanges({
24512453
viewDate: {},
24522454
events: {},
24532455
hourDuration: {},
2454-
hourSegmentHeight: {}
2456+
hourSegmentHeight: {},
24552457
});
24562458
fixture.detectChanges();
24572459
document.body.appendChild(fixture.nativeElement);
@@ -2461,25 +2463,25 @@ describe('calendarWeekView component', () => {
24612463
const rect: ClientRect = event.getBoundingClientRect();
24622464
const resizeHandle = event.querySelector('.cal-resize-handle-after-end');
24632465
let resizeEvent: CalendarEventTimesChangedEvent;
2464-
fixture.componentInstance.eventTimesChanged.pipe(take(1)).subscribe(e => {
2466+
fixture.componentInstance.eventTimesChanged.pipe(take(1)).subscribe((e) => {
24652467
resizeEvent = e;
24662468
});
24672469
triggerDomEvent('mousedown', resizeHandle, {
24682470
clientX: rect.right,
24692471
clientY: rect.bottom,
2470-
button: 0
2472+
button: 0,
24712473
});
24722474
fixture.detectChanges();
24732475
triggerDomEvent('mousemove', document.body, {
24742476
clientX: rect.right,
2475-
clientY: rect.bottom - 120
2477+
clientY: rect.bottom - 120,
24762478
});
24772479
fixture.detectChanges();
24782480
expect(event.getBoundingClientRect().height).to.equal(20);
24792481
triggerDomEvent('mouseup', document.body, {
24802482
clientX: rect.right,
24812483
clientY: rect.bottom - 120,
2482-
button: 0
2484+
button: 0,
24832485
});
24842486
fixture.detectChanges();
24852487
expect(resizeEvent).to.deep.equal({
@@ -2488,7 +2490,7 @@ describe('calendarWeekView component', () => {
24882490
newStart: fixture.componentInstance.events[0].start,
24892491
newEnd: moment(fixture.componentInstance.events[0].start)
24902492
.add(20, 'minutes')
2491-
.toDate()
2493+
.toDate(),
24922494
});
24932495
});
24942496

@@ -2632,6 +2634,24 @@ describe('calendarWeekView component', () => {
26322634
expect(updatedEvent1.innerText).to.equal('4:30 - 6:30');
26332635
});
26342636

2637+
it('should set a minimum event height', () => {
2638+
const fixture = TestBed.createComponent(CalendarWeekViewComponent);
2639+
fixture.componentInstance.viewDate = moment().startOf('week').toDate();
2640+
fixture.componentInstance.events = [
2641+
{
2642+
start: moment().startOf('week').toDate(),
2643+
end: moment().startOf('week').add(5, 'minutes').toDate(),
2644+
title: 'foo',
2645+
},
2646+
];
2647+
fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} });
2648+
fixture.detectChanges();
2649+
expect(
2650+
fixture.nativeElement.querySelector('.cal-event-container').offsetHeight
2651+
).to.equal(30);
2652+
fixture.destroy();
2653+
});
2654+
26352655
describe('current time marker', () => {
26362656
let clock: any;
26372657
beforeEach(() => {

0 commit comments

Comments
 (0)