|
@@ -1,9 +1,10 @@
|
1
|
1
|
import { Directive, forwardRef, Input, AfterViewInit, ElementRef, ViewContainerRef, OnDestroy, NgZone } from '@angular/core';
|
2
|
|
-import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
2
|
+import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
3
|
3
|
import { C3Tooltip } from './c3-tooltip.component';
|
4
|
4
|
import { Overlay, OverlayConfig, ScrollDispatcher, OverlayRef } from '@angular/cdk/overlay';
|
5
|
5
|
import { Platform } from '@angular/cdk/platform';
|
6
|
6
|
import { TemplatePortal } from '@angular/cdk/portal';
|
|
7
|
+import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
7
|
8
|
|
8
|
9
|
export const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
|
9
|
10
|
provide: NG_VALUE_ACCESSOR,
|
|
@@ -19,17 +20,37 @@ export const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
|
19
|
20
|
export class C3TooltipTrigger implements AfterViewInit, OnDestroy {
|
20
|
21
|
overlayRef: OverlayRef | null;
|
21
|
22
|
|
|
23
|
+ /** The timeout ID of any current timer set to show the tooltip */
|
|
24
|
+ _showTimeoutId: number | null;
|
|
25
|
+
|
|
26
|
+ /** The timeout ID of any current timer set to hide the tooltip */
|
|
27
|
+ _hideTimeoutId: number | null;
|
|
28
|
+
|
|
29
|
+ private _manualListeners = new Map<string, EventListenerOrEventListenerObject>();
|
|
30
|
+ private _tooltipClass: string | string[] | Set<string> | { [key: string]: any };
|
|
31
|
+ private _tootipDisabled: boolean = false;
|
|
32
|
+
|
22
|
33
|
@Input('c3Tooltip') tooltip: C3Tooltip;
|
23
|
34
|
|
24
|
|
- @Input('c3TooltipDisabled') disabled: Boolean = false;
|
|
35
|
+ @Input('c3TooltipDisabled')
|
|
36
|
+ get tooltipDisabled(): boolean { return this._tootipDisabled; }
|
|
37
|
+ set tooltipDisabled(value: boolean) {
|
|
38
|
+ this._tootipDisabled = coerceBooleanProperty(value)
|
|
39
|
+ };
|
25
|
40
|
|
26
|
|
- /** The default delay in ms before showing the tooltip after show is called */
|
27
|
41
|
@Input('c3TooltipShowDelay') showDelay = 0;
|
28
|
42
|
|
29
|
|
- /** The default delay in ms before hiding the tooltip after hide is called */
|
30
|
43
|
@Input('c3TooltipHideDelay') hideDelay = 0;
|
31
|
44
|
|
32
|
|
- private _manualListeners = new Map<string, EventListenerOrEventListenerObject>();
|
|
45
|
+ @Input('c3TooltipClass')
|
|
46
|
+ get tooltipClass() { return this._tooltipClass; }
|
|
47
|
+ set tooltipClass(value: string | string[] | Set<string> | { [key: string]: any }) {
|
|
48
|
+ this._tooltipClass = value;
|
|
49
|
+ if (this.tooltip) {
|
|
50
|
+ this.tooltip.tooltipClass = this._tooltipClass;
|
|
51
|
+ this.tooltip._markForCheck()
|
|
52
|
+ }
|
|
53
|
+ }
|
33
|
54
|
|
34
|
55
|
constructor(
|
35
|
56
|
private _element: ElementRef<HTMLElement>,
|
|
@@ -56,16 +77,38 @@ export class C3TooltipTrigger implements AfterViewInit, OnDestroy {
|
56
|
77
|
this._manualListeners.clear();
|
57
|
78
|
}
|
58
|
79
|
|
59
|
|
- show() {
|
60
|
|
- const overlayRef = this._overlay.create(this.getOverlayConfig());
|
61
|
|
- const portal = new TemplatePortal(this.tooltip.template, this._viewContainerRef);
|
62
|
|
- overlayRef.attach(portal);
|
|
80
|
+ show(delay: number = this.showDelay) {
|
|
81
|
+ if (this.tooltipDisabled) {
|
|
82
|
+ return;
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ if (this._hideTimeoutId) {
|
|
86
|
+ clearTimeout(this._hideTimeoutId);
|
|
87
|
+ this._hideTimeoutId = null;
|
|
88
|
+ }
|
|
89
|
+ this._showTimeoutId = window.setTimeout(() => {
|
|
90
|
+ this._showTimeoutId = null;
|
|
91
|
+
|
|
92
|
+ const overlayRef = this._overlay.create(this.getOverlayConfig());
|
|
93
|
+ const portal = new TemplatePortal(this.tooltip.template, this._viewContainerRef);
|
|
94
|
+ overlayRef.attach(portal);
|
63
|
95
|
|
64
|
|
- this.overlayRef = overlayRef;
|
|
96
|
+ this.overlayRef = overlayRef;
|
|
97
|
+ }, delay);
|
65
|
98
|
}
|
66
|
99
|
|
67
|
|
- hide() {
|
68
|
|
- this.overlayRef.detach();
|
|
100
|
+ hide(delay: number = this.hideDelay) {
|
|
101
|
+ if (this._showTimeoutId) {
|
|
102
|
+ clearTimeout(this._showTimeoutId);
|
|
103
|
+ this._showTimeoutId = null;
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ this._hideTimeoutId = window.setTimeout(() => {
|
|
107
|
+ this._hideTimeoutId = null;
|
|
108
|
+
|
|
109
|
+ if (this.overlayRef && this.overlayRef.hasAttached())
|
|
110
|
+ this.overlayRef.detach();
|
|
111
|
+ }, delay);
|
69
|
112
|
}
|
70
|
113
|
|
71
|
114
|
private getOverlayConfig(): OverlayConfig {
|