@@ -11,108 +11,29 @@ import {
11
11
ElementRef ,
12
12
ComponentFactory ,
13
13
Inject ,
14
- Renderer2
14
+ Renderer2 ,
15
+ TemplateRef
15
16
} from '@angular/core' ;
16
17
import { DOCUMENT } from '@angular/platform-browser' ;
17
18
import { Positioning } from 'positioning' ;
19
+ import { CalendarEvent } from 'calendar-utils' ;
18
20
19
21
@Component ( {
20
- styles : [ `
21
- .cal-tooltip {
22
- position: absolute;
23
- z-index: 1070;
24
- display: block;
25
- font-style: normal;
26
- font-weight: normal;
27
- letter-spacing: normal;
28
- line-break: auto;
29
- line-height: 1.5;
30
- text-align: start;
31
- text-decoration: none;
32
- text-shadow: none;
33
- text-transform: none;
34
- white-space: normal;
35
- word-break: normal;
36
- word-spacing: normal;
37
- font-size: 11px;
38
- word-wrap: break-word;
39
- opacity: 0.9;
40
- }
41
-
42
- .cal-tooltip.cal-tooltip-top {
43
- padding: 5px 0;
44
- margin-top: -3px;
45
- }
46
-
47
- .cal-tooltip.cal-tooltip-top .cal-tooltip-arrow {
48
- bottom: 0;
49
- left: 50%;
50
- margin-left: -5px;
51
- border-width: 5px 5px 0;
52
- border-top-color: #000;
53
- }
54
-
55
- .cal-tooltip.cal-tooltip-right {
56
- padding: 0 5px;
57
- margin-left: 3px;
58
- }
59
-
60
- .cal-tooltip.cal-tooltip-right .cal-tooltip-arrow {
61
- top: 50%;
62
- left: 0;
63
- margin-top: -5px;
64
- border-width: 5px 5px 5px 0;
65
- border-right-color: #000;
66
- }
67
-
68
- .cal-tooltip.cal-tooltip-bottom {
69
- padding: 5px 0;
70
- margin-top: 3px;
71
- }
72
-
73
- .cal-tooltip.cal-tooltip-bottom .cal-tooltip-arrow {
74
- top: 0;
75
- left: 50%;
76
- margin-left: -5px;
77
- border-width: 0 5px 5px;
78
- border-bottom-color: #000;
79
- }
80
-
81
- .cal-tooltip.cal-tooltip-left {
82
- padding: 0 5px;
83
- margin-left: -3px;
84
- }
85
-
86
- .cal-tooltip.cal-tooltip-left .cal-tooltip-arrow {
87
- top: 50%;
88
- right: 0;
89
- margin-top: -5px;
90
- border-width: 5px 0 5px 5px;
91
- border-left-color: #000;
92
- }
93
-
94
- .cal-tooltip-inner {
95
- max-width: 200px;
96
- padding: 3px 8px;
97
- color: #fff;
98
- text-align: center;
99
- background-color: #000;
100
- border-radius: 0.25rem;
101
- }
102
-
103
- .cal-tooltip-arrow {
104
- position: absolute;
105
- width: 0;
106
- height: 0;
107
- border-color: transparent;
108
- border-style: solid;
109
- }
110
- ` ] ,
111
22
template : `
112
- <div class="cal-tooltip" [ngClass]="'cal-tooltip-' + placement">
113
- <div class="cal-tooltip-arrow"></div>
114
- <div class="cal-tooltip-inner" [innerHtml]="contents"></div>
115
- </div>
23
+ <ng-template #defaultTemplate>
24
+ <div class="cal-tooltip" [ngClass]="'cal-tooltip-' + placement">
25
+ <div class="cal-tooltip-arrow"></div>
26
+ <div class="cal-tooltip-inner" [innerHtml]="contents"></div>
27
+ </div>
28
+ </ng-template>
29
+ <ng-template
30
+ [ngTemplateOutlet]="customTemplate || defaultTemplate"
31
+ [ngTemplateOutletContext]="{
32
+ contents: contents,
33
+ placement: placement,
34
+ event: event
35
+ }">
36
+ </ng-template>
116
37
`
117
38
} )
118
39
export class CalendarTooltipWindowComponent {
@@ -121,6 +42,10 @@ export class CalendarTooltipWindowComponent {
121
42
122
43
@Input ( ) placement : string ;
123
44
45
+ @Input ( ) event : CalendarEvent ;
46
+
47
+ @Input ( ) customTemplate : TemplateRef < any > ;
48
+
124
49
}
125
50
126
51
@Directive ( {
@@ -132,6 +57,10 @@ export class CalendarTooltipDirective implements OnDestroy {
132
57
133
58
@Input ( 'tooltipPlacement' ) placement : string = 'top' ; // tslint:disable-line no-input-rename
134
59
60
+ @Input ( 'tooltipTemplate' ) customTemplate : TemplateRef < any > ; // tslint:disable-line no-input-rename
61
+
62
+ @Input ( 'tooltipEvent' ) event : CalendarEvent ; // tslint:disable-line no-input-rename
63
+
135
64
private tooltipFactory : ComponentFactory < CalendarTooltipWindowComponent > ;
136
65
private tooltipRef : ComponentRef < CalendarTooltipWindowComponent > ;
137
66
private positioning : Positioning = new Positioning ( ) ;
@@ -166,6 +95,8 @@ export class CalendarTooltipDirective implements OnDestroy {
166
95
this . tooltipRef = this . viewContainerRef . createComponent ( this . tooltipFactory , 0 , this . injector , [ ] ) ;
167
96
this . tooltipRef . instance . contents = this . contents ;
168
97
this . tooltipRef . instance . placement = this . placement ;
98
+ this . tooltipRef . instance . customTemplate = this . customTemplate ;
99
+ this . tooltipRef . instance . event = this . event ;
169
100
this . document . body . appendChild ( this . tooltipRef . location . nativeElement ) ;
170
101
requestAnimationFrame ( ( ) => {
171
102
this . positionTooltip ( ) ;
0 commit comments