Skip to content

Commit 149b605

Browse files
author
Matt Lewis
committed
feat(dayView): allow the hour segment template to be customised
Closes #172
1 parent f6bd1fd commit 149b605

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/components/day/calendarDayView.component.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ import {
88
LOCALE_ID,
99
Inject,
1010
OnInit,
11-
OnDestroy
11+
OnDestroy,
12+
TemplateRef
1213
} from '@angular/core';
13-
import { getDayView, getDayViewHourGrid, CalendarEvent, DayView, DayViewHour, DayViewHourSegment, DayViewEvent } from 'calendar-utils';
14+
import {
15+
getDayView,
16+
getDayViewHourGrid,
17+
CalendarEvent,
18+
DayView,
19+
DayViewHour,
20+
DayViewHourSegment,
21+
DayViewEvent
22+
} from 'calendar-utils';
1423
import { Subject } from 'rxjs/Subject';
1524
import { Subscription } from 'rxjs/Subscription';
1625
import { ResizeEvent } from 'angular-resizable-element';
@@ -87,6 +96,7 @@ const SEGMENT_HEIGHT: number = 30;
8796
*ngFor="let segment of hour.segments"
8897
[segment]="segment"
8998
[locale]="locale"
99+
[customTemplate]="hourSegmentTemplate"
90100
(click)="hourSegmentClicked.emit({date: segment.date})"
91101
[class.cal-drag-over]="segment.dragOver"
92102
mwlDroppable
@@ -167,6 +177,11 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
167177
*/
168178
@Input() tooltipPlacement: string = 'top';
169179

180+
/**
181+
* A custom template to use to replace the hour segment
182+
*/
183+
@Input() hourSegmentTemplate: TemplateRef<any>;
184+
170185
/**
171186
* Called when an event title is clicked
172187
*/
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, TemplateRef } from '@angular/core';
22
import { DayViewHourSegment } from 'calendar-utils';
33

44
@Component({
55
selector: 'mwl-calendar-day-view-hour-segment',
66
template: `
7-
<div class="cal-hour-segment" [ngClass]="segment.cssClass">
8-
<div [hidden]="!segment.isStart" class="cal-time">
9-
{{ segment.date | calendarDate:'dayViewHour':locale }}
7+
<ng-template #defaultTemplate>
8+
<div class="cal-hour-segment" [ngClass]="segment.cssClass">
9+
<div [hidden]="!segment.isStart" class="cal-time">
10+
{{ segment.date | calendarDate:'dayViewHour':locale }}
11+
</div>
1012
</div>
11-
</div>
13+
</ng-template>
14+
<ng-template
15+
[ngTemplateOutlet]="customTemplate || defaultTemplate"
16+
[ngTemplateOutletContext]="{
17+
segment: segment,
18+
locale: locale
19+
}">
20+
</ng-template>
1221
`
1322
})
1423
export class CalendarDayViewHourSegmentComponent {
@@ -17,4 +26,6 @@ export class CalendarDayViewHourSegmentComponent {
1726

1827
@Input() locale: string;
1928

29+
@Input() customTemplate: TemplateRef<any>;
30+
2031
}

0 commit comments

Comments
 (0)