Skip to content

Commit 86b8a6d

Browse files
author
Matt Lewis
committed
refactor(dayView): move events into a container element
1 parent 0e4237f commit 86b8a6d

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

scss/day-view.scss

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@
4141
background-color: #ededed;
4242
}
4343

44-
.cal-event {
44+
.cal-event-container {
4545
position: absolute;
46+
}
47+
48+
.cal-event {
4649
border: solid 1px;
4750
padding: 5px;
4851
font-size: 12px;
4952
overflow: hidden;
5053
text-overflow: ellipsis;
5154
white-space: nowrap;
55+
height: 100%;
5256
}
5357

5458
.cal-draggable {

src/components/day/calendarDayView.component.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const SEGMENT_HEIGHT: number = 30;
5858
<div
5959
#event
6060
*ngFor="let dayEvent of view?.events"
61+
class="cal-event-container"
62+
[class.cal-draggable]="dayEvent.event.draggable"
6163
mwlResizable
6264
[resizeEdges]="{top: dayEvent.event?.resizable?.beforeStart, bottom: dayEvent.event?.resizable?.afterEnd}"
6365
[resizeSnapGrid]="{top: eventSnapSize, bottom: eventSnapSize}"
@@ -71,25 +73,26 @@ const SEGMENT_HEIGHT: number = 30;
7173
[validateDrag]="validateDrag"
7274
(dragStart)="dragStart(event, dayViewContainer)"
7375
(dragEnd)="eventDragged(dayEvent, $event.y)"
74-
class="cal-event"
7576
[style.marginTop.px]="dayEvent.top"
76-
[style.marginLeft.px]="dayEvent.left + 70"
77-
[style.height.px]="dayEvent.height"
78-
[style.width.px]="dayEvent.width - 1"
79-
[style.backgroundColor]="dayEvent.event.color.secondary"
80-
[style.borderColor]="dayEvent.event.color.primary"
81-
[class.cal-starts-within-day]="!dayEvent.startsBeforeDay"
82-
[class.cal-ends-within-day]="!dayEvent.endsAfterDay"
83-
[class.cal-draggable]="dayEvent.event.draggable"
84-
[ngClass]="dayEvent.event.cssClass"
85-
[mwlCalendarTooltip]="dayEvent.event.title | calendarEventTitle:'dayTooltip':dayEvent.event"
86-
[tooltipPlacement]="tooltipPlacement">
87-
<mwl-calendar-event-title
88-
[event]="dayEvent.event"
89-
view="day"
90-
(click)="eventClicked.emit({event: dayEvent.event})">
91-
</mwl-calendar-event-title>
92-
<mwl-calendar-event-actions [event]="dayEvent.event"></mwl-calendar-event-actions>
77+
[style.height.px]="dayEvent.height">
78+
<div
79+
class="cal-event"
80+
[style.marginLeft.px]="dayEvent.left + 70"
81+
[style.width.px]="dayEvent.width - 1"
82+
[style.backgroundColor]="dayEvent.event.color.secondary"
83+
[style.borderColor]="dayEvent.event.color.primary"
84+
[class.cal-starts-within-day]="!dayEvent.startsBeforeDay"
85+
[class.cal-ends-within-day]="!dayEvent.endsAfterDay"
86+
[ngClass]="dayEvent.event.cssClass"
87+
[mwlCalendarTooltip]="dayEvent.event.title | calendarEventTitle:'dayTooltip':dayEvent.event"
88+
[tooltipPlacement]="tooltipPlacement">
89+
<mwl-calendar-event-title
90+
[event]="dayEvent.event"
91+
view="day"
92+
(click)="eventClicked.emit({event: dayEvent.event})">
93+
</mwl-calendar-event-title>
94+
<mwl-calendar-event-actions [event]="dayEvent.event"></mwl-calendar-event-actions>
95+
</div>
9396
</div>
9497
</div>
9598
<div class="cal-hour" *ngFor="let hour of hours" [style.minWidth.px]="view?.width + 70">

test/calendarDayView.component.spec.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ describe('CalendarDayViewComponent component', () => {
274274
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
275275
fixture.detectChanges();
276276
document.body.appendChild(fixture.nativeElement);
277-
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
278-
event.style.position = 'absolute';
277+
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event-container');
279278
const rect: ClientRect = event.getBoundingClientRect();
280279
let resizeEvent: CalendarEventTimesChangedEvent;
281280
fixture.componentInstance.eventTimesChanged.subscribe(event => {
@@ -312,8 +311,7 @@ describe('CalendarDayViewComponent component', () => {
312311
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
313312
fixture.detectChanges();
314313
document.body.appendChild(fixture.nativeElement);
315-
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
316-
event.style.position = 'absolute';
314+
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event-container');
317315
const rect: ClientRect = event.getBoundingClientRect();
318316
let resizeEvent: CalendarEventTimesChangedEvent;
319317
fixture.componentInstance.eventTimesChanged.subscribe(event => {
@@ -324,7 +322,7 @@ describe('CalendarDayViewComponent component', () => {
324322
triggerDomEvent('mousemove', document.body, {clientY: rect.bottom + 30, clientX: rect.left + 10});
325323
fixture.detectChanges();
326324
expect(event.getBoundingClientRect().bottom).to.equal(rect.bottom + 30);
327-
expect(event.getBoundingClientRect().height).to.equal(162);
325+
expect(event.getBoundingClientRect().height).to.equal(150);
328326
triggerDomEvent('mouseup', document.body, {clientY: rect.top + 30, clientX: rect.left + 10});
329327
fixture.detectChanges();
330328
fixture.destroy();
@@ -470,8 +468,7 @@ describe('CalendarDayViewComponent component', () => {
470468
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
471469
fixture.detectChanges();
472470
document.body.appendChild(fixture.nativeElement);
473-
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event');
474-
event.style.position = 'absolute';
471+
const event: HTMLElement = fixture.nativeElement.querySelector('.cal-event-container');
475472
const rect: ClientRect = event.getBoundingClientRect();
476473
triggerDomEvent('mousedown', document.body, {clientY: rect.top, clientX: rect.left + 10});
477474
fixture.detectChanges();

0 commit comments

Comments
 (0)