Skip to content

Commit 53db16b

Browse files
author
Matt Lewis
committed
feat(monthView): allow the header template to be customised
1 parent 595a667 commit 53db16b

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/components/month/calendarMonthView.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
OnInit,
99
OnDestroy,
1010
LOCALE_ID,
11-
Inject
11+
Inject,
12+
TemplateRef
1213
} from '@angular/core';
1314
import {
1415
CalendarEvent,
@@ -47,7 +48,8 @@ import { CalendarEventTimesChangedEvent } from '../../interfaces/calendarEventTi
4748
<div class="cal-month-view">
4849
<mwl-calendar-month-view-header
4950
[days]="columnHeaders"
50-
[locale]="locale">
51+
[locale]="locale"
52+
[customTemplate]="headerTemplate">
5153
</mwl-calendar-month-view-header>
5254
<div class="cal-days">
5355
<div *ngFor="let rowIndex of view.rowOffsets">
@@ -127,6 +129,11 @@ export class CalendarMonthViewComponent implements OnChanges, OnInit, OnDestroy
127129
*/
128130
@Input() weekStartsOn: number;
129131

132+
/**
133+
* A custom template to use to replace the header
134+
*/
135+
@Input() headerTemplate: TemplateRef<any>;
136+
130137
/**
131138
* Called when the day cell is clicked
132139
*/
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, TemplateRef } from '@angular/core';
22
import { WeekDay } from 'calendar-utils';
33

44
@Component({
55
selector: 'mwl-calendar-month-view-header',
6-
template: `
7-
<div class="cal-cell-row cal-header">
8-
<div
9-
class="cal-cell"
10-
*ngFor="let day of days"
11-
[class.cal-past]="day.isPast"
12-
[class.cal-today]="day.isToday"
13-
[class.cal-future]="day.isFuture"
14-
[class.cal-weekend]="day.isWeekend">
15-
{{ day.date | calendarDate:'monthViewColumnHeader':locale }}
6+
template: `
7+
<template #defaultTemplate>
8+
<div class="cal-cell-row cal-header">
9+
<div
10+
class="cal-cell"
11+
*ngFor="let day of days"
12+
[class.cal-past]="day.isPast"
13+
[class.cal-today]="day.isToday"
14+
[class.cal-future]="day.isFuture"
15+
[class.cal-weekend]="day.isWeekend">
16+
{{ day.date | calendarDate:'monthViewColumnHeader':locale }}
17+
</div>
1618
</div>
17-
</div>
19+
</template>
20+
<template
21+
[ngTemplateOutlet]="customTemplate || defaultTemplate"
22+
[ngOutletContext]="{days: days, locale: locale}">
23+
</template>
1824
`
1925
})
2026
export class CalendarMonthViewHeaderComponent {
@@ -23,4 +29,6 @@ export class CalendarMonthViewHeaderComponent {
2329

2430
@Input() locale: string;
2531

32+
@Input() customTemplate: TemplateRef<any>;
33+
2634
}

0 commit comments

Comments
 (0)