Skip to content

Commit 4f9ed24

Browse files
etwillbefinemattlewis92
authored andcommitted
feat: make event colors optional
Closes #468
1 parent f76641a commit 4f9ed24

15 files changed

+130
-20
lines changed

demos/demo-modules/exclude-days/component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export class DemoComponent {
2828
{
2929
start: new Date('2016-01-01'),
3030
end: new Date('2016-01-09'),
31-
title: 'Multiple weeks event',
32-
color: colors.blue
31+
title: 'Multiple weeks event'
3332
}
3433
];
3534

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
"dependencies": {
184184
"angular-draggable-droppable": "^2.0.0",
185185
"angular-resizable-element": "^2.0.0",
186-
"calendar-utils": "^0.1.1",
186+
"calendar-utils": "^0.1.2",
187187
"date-fns": "^1.28.5",
188188
"positioning": "^1.3.1"
189189
}

src/modules/day/calendar-all-day-event.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { CalendarEvent } from 'calendar-utils';
1616
let-eventClicked="eventClicked">
1717
<div
1818
class="cal-all-day-event"
19-
[style.backgroundColor]="event.color.secondary"
20-
[style.borderColor]="event.color.primary">
19+
[style.backgroundColor]="event.color?.secondary"
20+
[style.borderColor]="event.color?.primary">
2121
<mwl-calendar-event-actions [event]="event"></mwl-calendar-event-actions>
2222
<mwl-calendar-event-title
2323
[event]="event"

src/modules/day/calendar-day-view-event.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { DayViewEvent } from 'calendar-utils';
1919
let-tooltipAppendToBody="tooltipAppendToBody">
2020
<div
2121
class="cal-event"
22-
[style.backgroundColor]="dayEvent.event.color.secondary"
23-
[style.borderColor]="dayEvent.event.color.primary"
22+
[style.backgroundColor]="dayEvent.event.color?.secondary"
23+
[style.borderColor]="dayEvent.event.color?.primary"
2424
[mwlCalendarTooltip]="dayEvent.event.title | calendarEventTitle:'dayTooltip':dayEvent.event"
2525
[tooltipPlacement]="tooltipPlacement"
2626
[tooltipEvent]="dayEvent.event"

src/modules/day/calendar-day-view.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@
4848
}
4949

5050
.cal-event {
51-
border: solid 1px;
5251
padding: 5px;
5352
font-size: 12px;
5453
overflow: hidden;
5554
text-overflow: ellipsis;
5655
white-space: nowrap;
5756
height: 100%;
5857
box-sizing: border-box;
58+
background-color: #D1E8FF;
59+
border: 1px solid #1e90ff;
60+
color: #1e90ff;
61+
}
62+
63+
.cal-event-title:link {
64+
color: currentColor;
5965
}
6066

6167
.cal-draggable {

src/modules/month/calendar-month-cell.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { trackByEventId } from '../common/util';
3030
<div
3131
class="cal-event"
3232
*ngFor="let event of day.events; trackBy:trackByEventId"
33-
[style.backgroundColor]="event.color.primary"
33+
[style.backgroundColor]="event.color?.primary"
3434
[ngClass]="event?.cssClass"
3535
(mouseenter)="highlightDay.emit({event: event})"
3636
(mouseleave)="unhighlightDay.emit({event: event})"

src/modules/month/calendar-month-view.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ export class CalendarMonthViewComponent
312312
toggleDayHighlight(event: CalendarEvent, isHighlighted: boolean): void {
313313
this.view.days.forEach(day => {
314314
if (isHighlighted && day.events.indexOf(event) > -1) {
315-
day.backgroundColor = event.color.secondary;
315+
day.backgroundColor =
316+
(event.color && event.color.secondary) || '#D1E8FF';
316317
} else {
317318
delete day.backgroundColor;
318319
}

src/modules/month/calendar-month-view.scss

+7-4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@
9797
border-radius: 50%;
9898
display: inline-block;
9999
margin: 2px;
100+
background-color: #1e90ff;
101+
border-color: #D1E8FF;
102+
color: #fff;
103+
}
104+
105+
.cal-event-title:link {
106+
color: currentColor;
100107
}
101108

102109
.cal-day-cell.cal-in-month.cal-has-events {
@@ -136,10 +143,6 @@
136143
top: 2px;
137144
}
138145

139-
.cal-event-title {
140-
color: white;
141-
}
142-
143146
.cal-out-month {
144147
.cal-day-badge,
145148
.cal-event {

src/modules/month/calendar-open-day-events.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { trackByEventId } from '../common/util';
2424
[dragAxis]="{x: event.draggable, y: event.draggable}">
2525
<span
2626
class="cal-event"
27-
[style.backgroundColor]="event.color.primary">
27+
[style.backgroundColor]="event.color?.primary">
2828
</span>
2929
<mwl-calendar-event-title
3030
[event]="event"

src/modules/week/calendar-week-view-event.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { WeekViewEvent } from 'calendar-utils';
1919
let-tooltipAppendToBody="tooltipAppendToBody">
2020
<div
2121
class="cal-event"
22-
[style.backgroundColor]="weekEvent.event.color.secondary"
22+
[style.backgroundColor]="weekEvent.event.color?.secondary"
23+
[style.borderColor]="weekEvent.event.color?.primary"
2324
[mwlCalendarTooltip]="weekEvent.event.title | calendarEventTitle:'weekTooltip':weekEvent.event"
2425
[tooltipPlacement]="tooltipPlacement"
2526
[tooltipEvent]="weekEvent.event"

src/modules/week/calendar-week-view.scss

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
margin-right: 2px;
4545
height: 30px;
4646
line-height: 30px;
47+
background-color: #D1E8FF;
48+
border: 1px solid #1e90ff;
49+
color: #1e90ff;
50+
}
51+
52+
.cal-event-title:link {
53+
color: currentColor;
4754
}
4855

4956
.cal-draggable {

test/calendar-day-view.component.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,37 @@ describe('CalendarDayViewComponent component', () => {
7272
expect(fixture.componentInstance.hours.length).to.equal(24);
7373
});
7474

75+
it('should generate the week view with default colors for events', () => {
76+
const fixture: ComponentFixture<
77+
CalendarDayViewComponent
78+
> = TestBed.createComponent(CalendarDayViewComponent);
79+
fixture.componentInstance.ngOnInit();
80+
fixture.componentInstance.viewDate = new Date('2016-06-01');
81+
fixture.componentInstance.events = [
82+
{
83+
start: new Date('2016-05-30'),
84+
end: new Date('2016-06-02'),
85+
title: 'foo'
86+
}
87+
];
88+
fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} });
89+
fixture.detectChanges();
90+
91+
const computedStyles: CSSStyleDeclaration = window.getComputedStyle(
92+
fixture.nativeElement.querySelector('.cal-event')
93+
);
94+
expect(computedStyles.getPropertyValue('background-color')).to.equal(
95+
'rgb(209, 232, 255)'
96+
);
97+
expect(computedStyles.getPropertyValue('border-color')).to.equal(
98+
'rgb(30, 144, 255)'
99+
);
100+
expect(computedStyles.getPropertyValue('color')).to.equal(
101+
'rgb(30, 144, 255)'
102+
);
103+
fixture.destroy();
104+
});
105+
75106
it(
76107
'should call the event clicked callback',
77108
async(() => {

test/calendar-month-view.component.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ describe('calendarMonthView component', () => {
7171
fixture.destroy();
7272
});
7373

74+
it('should generate the week view with default colors for events', () => {
75+
const fixture: ComponentFixture<
76+
CalendarMonthViewComponent
77+
> = TestBed.createComponent(CalendarMonthViewComponent);
78+
fixture.componentInstance.ngOnInit();
79+
fixture.componentInstance.viewDate = new Date('2016-06-01');
80+
fixture.componentInstance.events = [
81+
{
82+
start: new Date('2016-05-30'),
83+
end: new Date('2016-06-02'),
84+
title: 'foo'
85+
}
86+
];
87+
fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} });
88+
fixture.detectChanges();
89+
90+
const computedStyles: CSSStyleDeclaration = window.getComputedStyle(
91+
fixture.nativeElement.querySelector('.cal-event')
92+
);
93+
expect(computedStyles.getPropertyValue('background-color')).to.equal(
94+
'rgb(30, 144, 255)'
95+
);
96+
expect(computedStyles.getPropertyValue('border-color')).to.equal(
97+
'rgb(209, 232, 255)'
98+
);
99+
expect(computedStyles.getPropertyValue('color')).to.equal(
100+
'rgb(255, 255, 255)'
101+
);
102+
fixture.destroy();
103+
});
104+
74105
it('should generate the month view without from week excluded days', () => {
75106
const fixture: ComponentFixture<
76107
CalendarMonthViewComponent

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

+31
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ describe('calendarWeekView component', () => {
9292
fixture.destroy();
9393
});
9494

95+
it('should generate the week view with default colors for events', () => {
96+
const fixture: ComponentFixture<
97+
CalendarWeekViewComponent
98+
> = TestBed.createComponent(CalendarWeekViewComponent);
99+
fixture.componentInstance.ngOnInit();
100+
fixture.componentInstance.viewDate = new Date('2016-06-01');
101+
fixture.componentInstance.events = [
102+
{
103+
start: new Date('2016-05-30'),
104+
end: new Date('2016-06-02'),
105+
title: 'foo'
106+
}
107+
];
108+
fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} });
109+
fixture.detectChanges();
110+
111+
const computedStyles: CSSStyleDeclaration = window.getComputedStyle(
112+
fixture.nativeElement.querySelector('.cal-event')
113+
);
114+
expect(computedStyles.getPropertyValue('background-color')).to.equal(
115+
'rgb(209, 232, 255)'
116+
);
117+
expect(computedStyles.getPropertyValue('border-color')).to.equal(
118+
'rgb(30, 144, 255)'
119+
);
120+
expect(computedStyles.getPropertyValue('color')).to.equal(
121+
'rgb(30, 144, 255)'
122+
);
123+
fixture.destroy();
124+
});
125+
95126
it('should emit on the dayHeaderClicked output', () => {
96127
const fixture: ComponentFixture<
97128
CalendarWeekViewComponent

0 commit comments

Comments
 (0)