@materializecss/materialize 2.0.3-alpha → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/css/materialize.css +345 -236
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +518 -1979
- package/dist/js/materialize.min.js +2 -2
- package/dist/js/materialize.min.js.map +1 -1
- package/dist/src/buttons.d.ts.map +1 -1
- package/dist/src/cards.d.ts.map +1 -1
- package/dist/src/collapsible.d.ts +1 -0
- package/dist/src/collapsible.d.ts.map +1 -1
- package/dist/src/dropdown.d.ts.map +1 -1
- package/dist/src/global.d.ts.map +1 -1
- package/dist/src/materialbox.d.ts +14 -10
- package/dist/src/materialbox.d.ts.map +1 -1
- package/dist/src/modal.d.ts.map +1 -1
- package/dist/src/range.d.ts.map +1 -1
- package/dist/src/scrollspy.d.ts.map +1 -1
- package/dist/src/sidenav.d.ts +25 -25
- package/dist/src/sidenav.d.ts.map +1 -1
- package/dist/src/slider.d.ts +12 -12
- package/dist/src/slider.d.ts.map +1 -1
- package/dist/src/tabs.d.ts +1 -1
- package/dist/src/tabs.d.ts.map +1 -1
- package/dist/src/toasts.d.ts +7 -2
- package/dist/src/toasts.d.ts.map +1 -1
- package/dist/src/tooltip.d.ts +8 -2
- package/dist/src/tooltip.d.ts.map +1 -1
- package/package.json +14 -13
- package/sass/components/_buttons.scss +158 -73
- package/sass/components/_chips.scss +75 -28
- package/sass/components/_collapsible.scss +14 -2
- package/sass/components/_global.scss +6 -94
- package/sass/components/_materialbox.scss +2 -2
- package/sass/components/_modal.scss +0 -1
- package/sass/components/_preloader.scss +85 -0
- package/sass/components/_tooltip.scss +18 -8
- package/sass/components/_variables.scss +5 -4
- package/sass/components/forms/_range.scss +1 -1
- package/sass/components/forms/_switches.scss +44 -14
- package/Gruntfile.js +0 -480
- package/src/autocomplete.ts +0 -553
- package/src/bounding.ts +0 -6
- package/src/buttons.ts +0 -260
- package/src/cards.ts +0 -53
- package/src/carousel.ts +0 -676
- package/src/characterCounter.ts +0 -117
- package/src/chips.ts +0 -439
- package/src/collapsible.ts +0 -249
- package/src/component.ts +0 -120
- package/src/datepicker.ts +0 -1076
- package/src/dropdown.ts +0 -644
- package/src/edges.ts +0 -6
- package/src/forms.ts +0 -132
- package/src/global.ts +0 -114
- package/src/index.ts +0 -26
- package/src/materialbox.ts +0 -404
- package/src/modal.ts +0 -341
- package/src/parallax.ts +0 -149
- package/src/pushpin.ts +0 -165
- package/src/range.ts +0 -198
- package/src/scrollspy.ts +0 -263
- package/src/select.ts +0 -484
- package/src/sidenav.ts +0 -543
- package/src/slider.ts +0 -474
- package/src/tabs.ts +0 -347
- package/src/tapTarget.ts +0 -273
- package/src/timepicker.ts +0 -832
- package/src/toasts.ts +0 -290
- package/src/tooltip.ts +0 -346
- package/src/utils.ts +0 -271
- package/src/waves.ts +0 -70
package/src/toasts.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import anim from "animejs";
|
|
2
|
-
|
|
3
|
-
import { BaseOptions } from "./component";
|
|
4
|
-
|
|
5
|
-
export interface ToastOptions extends BaseOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The content of the Toast.
|
|
8
|
-
* @default ""
|
|
9
|
-
*/
|
|
10
|
-
text: string;
|
|
11
|
-
/**
|
|
12
|
-
* Length in ms the Toast stays before dismissal.
|
|
13
|
-
* @default 4000
|
|
14
|
-
*/
|
|
15
|
-
displayLength: number;
|
|
16
|
-
/**
|
|
17
|
-
* Transition in duration in milliseconds.
|
|
18
|
-
* @default 300
|
|
19
|
-
*/
|
|
20
|
-
inDuration: number;
|
|
21
|
-
/**
|
|
22
|
-
* Transition out duration in milliseconds.
|
|
23
|
-
* @default 375
|
|
24
|
-
*/
|
|
25
|
-
outDuration: number;
|
|
26
|
-
/**
|
|
27
|
-
* Classes to be added to the toast element.
|
|
28
|
-
* @default ""
|
|
29
|
-
*/
|
|
30
|
-
classes: string;
|
|
31
|
-
/**
|
|
32
|
-
* Callback function called when toast is dismissed.
|
|
33
|
-
* @default null
|
|
34
|
-
*/
|
|
35
|
-
completeCallback: () => void;
|
|
36
|
-
/**
|
|
37
|
-
* The percentage of the toast's width it takes fora drag
|
|
38
|
-
* to dismiss a Toast.
|
|
39
|
-
* @default 0.8
|
|
40
|
-
*/
|
|
41
|
-
activationPercent: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let _defaults: ToastOptions = {
|
|
45
|
-
text: '',
|
|
46
|
-
displayLength: 4000,
|
|
47
|
-
inDuration: 300,
|
|
48
|
-
outDuration: 375,
|
|
49
|
-
classes: '',
|
|
50
|
-
completeCallback: null,
|
|
51
|
-
activationPercent: 0.8
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export class Toast {
|
|
55
|
-
/** The toast element. */
|
|
56
|
-
el: HTMLDivElement;
|
|
57
|
-
/**
|
|
58
|
-
* The remaining amount of time in ms that the toast
|
|
59
|
-
* will stay before dismissal.
|
|
60
|
-
*/
|
|
61
|
-
timeRemaining: number;
|
|
62
|
-
/**
|
|
63
|
-
* Describes the current pan state of the Toast.
|
|
64
|
-
*/
|
|
65
|
-
panning: boolean;
|
|
66
|
-
options: ToastOptions;
|
|
67
|
-
message: string;
|
|
68
|
-
counterInterval: NodeJS.Timeout;
|
|
69
|
-
wasSwiped: boolean;
|
|
70
|
-
startingXPos: number;
|
|
71
|
-
xPos: number;
|
|
72
|
-
time: number;
|
|
73
|
-
deltaX: number;
|
|
74
|
-
velocityX: number;
|
|
75
|
-
|
|
76
|
-
static _toasts: Toast[];
|
|
77
|
-
static _container: any;
|
|
78
|
-
static _draggedToast: Toast;
|
|
79
|
-
|
|
80
|
-
constructor(options: Partial<ToastOptions>) {
|
|
81
|
-
this.options = {
|
|
82
|
-
...Toast.defaults,
|
|
83
|
-
...options
|
|
84
|
-
};
|
|
85
|
-
this.message = this.options.text;
|
|
86
|
-
this.panning = false;
|
|
87
|
-
this.timeRemaining = this.options.displayLength;
|
|
88
|
-
if (Toast._toasts.length === 0) {
|
|
89
|
-
Toast._createContainer();
|
|
90
|
-
}
|
|
91
|
-
// Create new toast
|
|
92
|
-
Toast._toasts.push(this);
|
|
93
|
-
let toastElement = this._createToast();
|
|
94
|
-
(toastElement as any).M_Toast = this;
|
|
95
|
-
this.el = toastElement;
|
|
96
|
-
this._animateIn();
|
|
97
|
-
this._setTimer();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static get defaults(): ToastOptions {
|
|
101
|
-
return _defaults;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
static getInstance(el: HTMLElement): Toast {
|
|
105
|
-
return (el as any).M_Toast;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static _createContainer() {
|
|
109
|
-
const container = document.createElement('div');
|
|
110
|
-
container.setAttribute('id', 'toast-container');
|
|
111
|
-
// Add event handler
|
|
112
|
-
container.addEventListener('touchstart', Toast._onDragStart);
|
|
113
|
-
container.addEventListener('touchmove', Toast._onDragMove);
|
|
114
|
-
container.addEventListener('touchend', Toast._onDragEnd);
|
|
115
|
-
container.addEventListener('mousedown', Toast._onDragStart);
|
|
116
|
-
document.addEventListener('mousemove', Toast._onDragMove);
|
|
117
|
-
document.addEventListener('mouseup', Toast._onDragEnd);
|
|
118
|
-
document.body.appendChild(container);
|
|
119
|
-
Toast._container = container;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static _removeContainer() {
|
|
123
|
-
document.removeEventListener('mousemove', Toast._onDragMove);
|
|
124
|
-
document.removeEventListener('mouseup', Toast._onDragEnd);
|
|
125
|
-
Toast._container.remove();
|
|
126
|
-
Toast._container = null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
static _onDragStart(e: TouchEvent | MouseEvent) {
|
|
130
|
-
if (e.target && (<HTMLElement>e.target).closest('.toast')) {
|
|
131
|
-
const toastElem = (<HTMLElement>e.target).closest('.toast');
|
|
132
|
-
const toast: Toast = (toastElem as any).M_Toast;
|
|
133
|
-
toast.panning = true;
|
|
134
|
-
Toast._draggedToast = toast;
|
|
135
|
-
toast.el.classList.add('panning');
|
|
136
|
-
toast.el.style.transition = '';
|
|
137
|
-
toast.startingXPos = Toast._xPos(e);
|
|
138
|
-
toast.time = Date.now();
|
|
139
|
-
toast.xPos = Toast._xPos(e);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
static _onDragMove(e: TouchEvent | MouseEvent) {
|
|
144
|
-
if (!!Toast._draggedToast) {
|
|
145
|
-
e.preventDefault();
|
|
146
|
-
const toast = Toast._draggedToast;
|
|
147
|
-
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
|
148
|
-
toast.xPos = Toast._xPos(e);
|
|
149
|
-
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
|
150
|
-
toast.time = Date.now();
|
|
151
|
-
|
|
152
|
-
const totalDeltaX = toast.xPos - toast.startingXPos;
|
|
153
|
-
const activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
154
|
-
toast.el.style.transform = `translateX(${totalDeltaX}px)`;
|
|
155
|
-
toast.el.style.opacity = (1 - Math.abs(totalDeltaX / activationDistance)).toString();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
static _onDragEnd() {
|
|
160
|
-
if (!!Toast._draggedToast) {
|
|
161
|
-
let toast = Toast._draggedToast;
|
|
162
|
-
toast.panning = false;
|
|
163
|
-
toast.el.classList.remove('panning');
|
|
164
|
-
|
|
165
|
-
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
166
|
-
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
167
|
-
let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
|
168
|
-
|
|
169
|
-
// Remove toast
|
|
170
|
-
if (shouldBeDismissed) {
|
|
171
|
-
toast.wasSwiped = true;
|
|
172
|
-
toast.dismiss();
|
|
173
|
-
// Animate toast back to original position
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
177
|
-
toast.el.style.transform = '';
|
|
178
|
-
toast.el.style.opacity = '';
|
|
179
|
-
}
|
|
180
|
-
Toast._draggedToast = null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
static _xPos(e: TouchEvent | MouseEvent) {
|
|
185
|
-
if (e.type.startsWith("touch") && (e as TouchEvent).targetTouches.length >= 1) {
|
|
186
|
-
return (e as TouchEvent).targetTouches[0].clientX;
|
|
187
|
-
}
|
|
188
|
-
// mouse event
|
|
189
|
-
return (e as MouseEvent).clientX;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* dismiss all toasts.
|
|
194
|
-
*/
|
|
195
|
-
static dismissAll() {
|
|
196
|
-
for (let toastIndex in Toast._toasts) {
|
|
197
|
-
Toast._toasts[toastIndex].dismiss();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
_createToast() {
|
|
202
|
-
const toast = document.createElement('div');
|
|
203
|
-
toast.classList.add('toast');
|
|
204
|
-
toast.setAttribute('role', 'alert');
|
|
205
|
-
toast.setAttribute('aria-live', 'assertive');
|
|
206
|
-
toast.setAttribute('aria-atomic', 'true');
|
|
207
|
-
|
|
208
|
-
// Add custom classes onto toast
|
|
209
|
-
if (this.options.classes.length > 0) {
|
|
210
|
-
toast.classList.add(...this.options.classes.split(' '));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Set text content
|
|
214
|
-
else toast.innerText = this.message;
|
|
215
|
-
|
|
216
|
-
// Append toast
|
|
217
|
-
Toast._container.appendChild(toast);
|
|
218
|
-
return toast;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
_animateIn() {
|
|
222
|
-
// Animate toast in
|
|
223
|
-
anim({
|
|
224
|
-
targets: this.el,
|
|
225
|
-
top: 0,
|
|
226
|
-
opacity: 1,
|
|
227
|
-
duration: this.options.inDuration,
|
|
228
|
-
easing: 'easeOutCubic'
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Create setInterval which automatically removes toast when timeRemaining >= 0
|
|
234
|
-
* has been reached.
|
|
235
|
-
*/
|
|
236
|
-
_setTimer() {
|
|
237
|
-
if (this.timeRemaining !== Infinity) {
|
|
238
|
-
this.counterInterval = setInterval(() => {
|
|
239
|
-
// If toast is not being dragged, decrease its time remaining
|
|
240
|
-
if (!this.panning) {
|
|
241
|
-
this.timeRemaining -= 20;
|
|
242
|
-
}
|
|
243
|
-
// Animate toast out
|
|
244
|
-
if (this.timeRemaining <= 0) {
|
|
245
|
-
this.dismiss();
|
|
246
|
-
}
|
|
247
|
-
}, 20);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Dismiss toast with animation.
|
|
253
|
-
*/
|
|
254
|
-
dismiss() {
|
|
255
|
-
window.clearInterval(this.counterInterval);
|
|
256
|
-
let activationDistance = this.el.offsetWidth * this.options.activationPercent;
|
|
257
|
-
|
|
258
|
-
if (this.wasSwiped) {
|
|
259
|
-
this.el.style.transition = 'transform .05s, opacity .05s';
|
|
260
|
-
this.el.style.transform = `translateX(${activationDistance}px)`;
|
|
261
|
-
this.el.style.opacity = '0';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
anim({
|
|
265
|
-
targets: this.el,
|
|
266
|
-
opacity: 0,
|
|
267
|
-
marginTop: -40,
|
|
268
|
-
duration: this.options.outDuration,
|
|
269
|
-
easing: 'easeOutExpo',
|
|
270
|
-
complete: () => {
|
|
271
|
-
// Call the optional callback
|
|
272
|
-
if (typeof this.options.completeCallback === 'function') {
|
|
273
|
-
this.options.completeCallback();
|
|
274
|
-
}
|
|
275
|
-
// Remove toast from DOM
|
|
276
|
-
this.el.remove();
|
|
277
|
-
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
|
|
278
|
-
if (Toast._toasts.length === 0) {
|
|
279
|
-
Toast._removeContainer();
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
static {
|
|
286
|
-
Toast._toasts = [];
|
|
287
|
-
Toast._container = null;
|
|
288
|
-
Toast._draggedToast = null;
|
|
289
|
-
}
|
|
290
|
-
}
|
package/src/tooltip.ts
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import anim from "animejs";
|
|
2
|
-
|
|
3
|
-
import { Utils } from "./utils";
|
|
4
|
-
import { Bounding } from "./bounding";
|
|
5
|
-
import { Component, BaseOptions, InitElements, MElement } from "./component";
|
|
6
|
-
|
|
7
|
-
export interface TooltipOptions extends BaseOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Delay time before tooltip disappears.
|
|
10
|
-
* @default 200
|
|
11
|
-
*/
|
|
12
|
-
exitDelay: number;
|
|
13
|
-
/**
|
|
14
|
-
* Delay time before tooltip appears.
|
|
15
|
-
* @default 0
|
|
16
|
-
*/
|
|
17
|
-
enterDelay: number;
|
|
18
|
-
/**
|
|
19
|
-
* Text string for the tooltip.
|
|
20
|
-
* @default ""
|
|
21
|
-
*/
|
|
22
|
-
text: string;
|
|
23
|
-
/**
|
|
24
|
-
* Set distance tooltip appears away from its activator
|
|
25
|
-
* excluding transitionMovement.
|
|
26
|
-
* @default 5
|
|
27
|
-
*/
|
|
28
|
-
margin: number;
|
|
29
|
-
/**
|
|
30
|
-
* Enter transition duration.
|
|
31
|
-
* @default 300
|
|
32
|
-
*/
|
|
33
|
-
inDuration: number;
|
|
34
|
-
/**
|
|
35
|
-
* Opacity of the tooltip.
|
|
36
|
-
* @default 1
|
|
37
|
-
*/
|
|
38
|
-
opacity: number;
|
|
39
|
-
/**
|
|
40
|
-
* Exit transition duration.
|
|
41
|
-
* @default 250
|
|
42
|
-
*/
|
|
43
|
-
outDuration: number;
|
|
44
|
-
/**
|
|
45
|
-
* Set the direction of the tooltip.
|
|
46
|
-
* @default 'bottom'
|
|
47
|
-
*/
|
|
48
|
-
position: 'top' | 'right' | 'bottom' | 'left';
|
|
49
|
-
/**
|
|
50
|
-
* Amount in px that the tooltip moves during its transition.
|
|
51
|
-
* @default 10
|
|
52
|
-
*/
|
|
53
|
-
transitionMovement: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const _defaults: TooltipOptions = {
|
|
57
|
-
exitDelay: 200,
|
|
58
|
-
enterDelay: 0,
|
|
59
|
-
text: '',
|
|
60
|
-
margin: 5,
|
|
61
|
-
inDuration: 250,
|
|
62
|
-
outDuration: 200,
|
|
63
|
-
position: 'bottom',
|
|
64
|
-
transitionMovement: 10,
|
|
65
|
-
opacity: 1
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export class Tooltip extends Component<TooltipOptions> {
|
|
69
|
-
/**
|
|
70
|
-
* If tooltip is open.
|
|
71
|
-
*/
|
|
72
|
-
isOpen: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* If tooltip is hovered.
|
|
75
|
-
*/
|
|
76
|
-
isHovered: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* If tooltip is focused.
|
|
79
|
-
*/
|
|
80
|
-
isFocused: boolean;
|
|
81
|
-
tooltipEl: HTMLElement;
|
|
82
|
-
private _exitDelayTimeout: string | number | NodeJS.Timeout;
|
|
83
|
-
private _enterDelayTimeout: string | number | NodeJS.Timeout;
|
|
84
|
-
xMovement: number;
|
|
85
|
-
yMovement: number;
|
|
86
|
-
|
|
87
|
-
constructor(el: HTMLElement, options: Partial<TooltipOptions>) {
|
|
88
|
-
super(el, options, Tooltip);
|
|
89
|
-
(this.el as any).M_Tooltip = this;
|
|
90
|
-
|
|
91
|
-
this.options = {
|
|
92
|
-
...Tooltip.defaults,
|
|
93
|
-
...options
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
this.isOpen = false;
|
|
97
|
-
this.isHovered = false;
|
|
98
|
-
this.isFocused = false;
|
|
99
|
-
this._appendTooltipEl();
|
|
100
|
-
this._setupEventHandlers();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static get defaults(): TooltipOptions {
|
|
104
|
-
return _defaults;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Initializes instance of Tooltip.
|
|
109
|
-
* @param el HTML element.
|
|
110
|
-
* @param options Component options.
|
|
111
|
-
*/
|
|
112
|
-
static init(el: HTMLElement, options?: Partial<TooltipOptions>): Tooltip;
|
|
113
|
-
/**
|
|
114
|
-
* Initializes instances of Tooltip.
|
|
115
|
-
* @param els HTML elements.
|
|
116
|
-
* @param options Component options.
|
|
117
|
-
*/
|
|
118
|
-
static init(els: InitElements<MElement>, options?: Partial<TooltipOptions>): Tooltip[];
|
|
119
|
-
/**
|
|
120
|
-
* Initializes instances of Tooltip.
|
|
121
|
-
* @param els HTML elements.
|
|
122
|
-
* @param options Component options.
|
|
123
|
-
*/
|
|
124
|
-
static init(els: HTMLElement | InitElements<MElement>, options: Partial<TooltipOptions> = {}): Tooltip | Tooltip[] {
|
|
125
|
-
return super.init(els, options, Tooltip);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
static getInstance(el: HTMLElement): Tooltip {
|
|
129
|
-
return (el as any).M_Tooltip;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
destroy() {
|
|
133
|
-
this.tooltipEl.remove();
|
|
134
|
-
this._removeEventHandlers();
|
|
135
|
-
(this.el as any).M_Tooltip = undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
_appendTooltipEl() {
|
|
139
|
-
this.tooltipEl = document.createElement('div');
|
|
140
|
-
this.tooltipEl.classList.add('material-tooltip');
|
|
141
|
-
|
|
142
|
-
const tooltipContentEl = document.createElement('div');
|
|
143
|
-
tooltipContentEl.classList.add('tooltip-content');
|
|
144
|
-
this._setTooltipContent(tooltipContentEl);
|
|
145
|
-
this.tooltipEl.appendChild(tooltipContentEl);
|
|
146
|
-
document.body.appendChild(this.tooltipEl);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
_setTooltipContent(tooltipContentEl: HTMLElement) {
|
|
150
|
-
tooltipContentEl.innerText = this.options.text;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
_updateTooltipContent() {
|
|
154
|
-
this._setTooltipContent(this.tooltipEl.querySelector('.tooltip-content'));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
_setupEventHandlers() {
|
|
158
|
-
this.el.addEventListener('mouseenter', this._handleMouseEnter);
|
|
159
|
-
this.el.addEventListener('mouseleave', this._handleMouseLeave);
|
|
160
|
-
this.el.addEventListener('focus', this._handleFocus, true);
|
|
161
|
-
this.el.addEventListener('blur', this._handleBlur, true);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
_removeEventHandlers() {
|
|
165
|
-
this.el.removeEventListener('mouseenter', this._handleMouseEnter);
|
|
166
|
-
this.el.removeEventListener('mouseleave', this._handleMouseLeave);
|
|
167
|
-
this.el.removeEventListener('focus', this._handleFocus, true);
|
|
168
|
-
this.el.removeEventListener('blur', this._handleBlur, true);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Show tooltip.
|
|
173
|
-
*/
|
|
174
|
-
open = (isManual: boolean) => {
|
|
175
|
-
if (this.isOpen) return;
|
|
176
|
-
isManual = isManual === undefined ? true : undefined; // Default value true
|
|
177
|
-
this.isOpen = true;
|
|
178
|
-
// Update tooltip content with HTML attribute options
|
|
179
|
-
this.options = {...this.options, ...this._getAttributeOptions()};
|
|
180
|
-
this._updateTooltipContent();
|
|
181
|
-
this._setEnterDelayTimeout(isManual);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Hide tooltip.
|
|
186
|
-
*/
|
|
187
|
-
close = () => {
|
|
188
|
-
if (!this.isOpen) return;
|
|
189
|
-
this.isHovered = false;
|
|
190
|
-
this.isFocused = false;
|
|
191
|
-
this.isOpen = false;
|
|
192
|
-
this._setExitDelayTimeout();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
_setExitDelayTimeout() {
|
|
196
|
-
clearTimeout(this._exitDelayTimeout);
|
|
197
|
-
this._exitDelayTimeout = setTimeout(() => {
|
|
198
|
-
if (this.isHovered || this.isFocused) return;
|
|
199
|
-
this._animateOut();
|
|
200
|
-
}, this.options.exitDelay);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
_setEnterDelayTimeout(isManual) {
|
|
204
|
-
clearTimeout(this._enterDelayTimeout);
|
|
205
|
-
this._enterDelayTimeout = setTimeout(() => {
|
|
206
|
-
if (!this.isHovered && !this.isFocused && !isManual) return;
|
|
207
|
-
this._animateIn();
|
|
208
|
-
}, this.options.enterDelay);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
_positionTooltip() {
|
|
212
|
-
const tooltip: HTMLElement = this.tooltipEl;
|
|
213
|
-
const origin = (this.el as HTMLElement),
|
|
214
|
-
originHeight = origin.offsetHeight,
|
|
215
|
-
originWidth = origin.offsetWidth,
|
|
216
|
-
tooltipHeight = tooltip.offsetHeight,
|
|
217
|
-
tooltipWidth = tooltip.offsetWidth,
|
|
218
|
-
margin = this.options.margin;
|
|
219
|
-
|
|
220
|
-
(this.xMovement = 0), (this.yMovement = 0);
|
|
221
|
-
|
|
222
|
-
let targetTop = origin.getBoundingClientRect().top + Utils.getDocumentScrollTop();
|
|
223
|
-
let targetLeft = origin.getBoundingClientRect().left + Utils.getDocumentScrollLeft();
|
|
224
|
-
if (this.options.position === 'top') {
|
|
225
|
-
targetTop += -tooltipHeight - margin;
|
|
226
|
-
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
227
|
-
this.yMovement = -this.options.transitionMovement;
|
|
228
|
-
} else if (this.options.position === 'right') {
|
|
229
|
-
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
230
|
-
targetLeft += originWidth + margin;
|
|
231
|
-
this.xMovement = this.options.transitionMovement;
|
|
232
|
-
} else if (this.options.position === 'left') {
|
|
233
|
-
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
234
|
-
targetLeft += -tooltipWidth - margin;
|
|
235
|
-
this.xMovement = -this.options.transitionMovement;
|
|
236
|
-
} else {
|
|
237
|
-
targetTop += originHeight + margin;
|
|
238
|
-
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
239
|
-
this.yMovement = this.options.transitionMovement;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const newCoordinates = this._repositionWithinScreen(
|
|
243
|
-
targetLeft,
|
|
244
|
-
targetTop,
|
|
245
|
-
tooltipWidth,
|
|
246
|
-
tooltipHeight
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
tooltip.style.top = newCoordinates.y+'px';
|
|
250
|
-
tooltip.style.left = newCoordinates.x+'px';
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
_repositionWithinScreen(x: number, y: number, width: number, height: number) {
|
|
254
|
-
const scrollLeft = Utils.getDocumentScrollLeft();
|
|
255
|
-
const scrollTop = Utils.getDocumentScrollTop();
|
|
256
|
-
let newX = x - scrollLeft;
|
|
257
|
-
let newY = y - scrollTop;
|
|
258
|
-
|
|
259
|
-
const bounding: Bounding = {
|
|
260
|
-
left: newX,
|
|
261
|
-
top: newY,
|
|
262
|
-
width: width,
|
|
263
|
-
height: height
|
|
264
|
-
};
|
|
265
|
-
const offset = this.options.margin + this.options.transitionMovement;
|
|
266
|
-
const edges = Utils.checkWithinContainer(document.body, bounding, offset);
|
|
267
|
-
|
|
268
|
-
if (edges.left) {
|
|
269
|
-
newX = offset;
|
|
270
|
-
} else if (edges.right) {
|
|
271
|
-
newX -= newX + width - window.innerWidth;
|
|
272
|
-
}
|
|
273
|
-
if (edges.top) {
|
|
274
|
-
newY = offset;
|
|
275
|
-
} else if (edges.bottom) {
|
|
276
|
-
newY -= newY + height - window.innerHeight;
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
x: newX + scrollLeft,
|
|
280
|
-
y: newY + scrollTop
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
_animateIn() {
|
|
285
|
-
this._positionTooltip();
|
|
286
|
-
this.tooltipEl.style.visibility = 'visible';
|
|
287
|
-
anim.remove(this.tooltipEl);
|
|
288
|
-
anim({
|
|
289
|
-
targets: this.tooltipEl,
|
|
290
|
-
opacity: this.options.opacity || 1,
|
|
291
|
-
translateX: this.xMovement,
|
|
292
|
-
translateY: this.yMovement,
|
|
293
|
-
duration: this.options.inDuration,
|
|
294
|
-
easing: 'easeOutCubic'
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
_animateOut() {
|
|
299
|
-
anim.remove(this.tooltipEl);
|
|
300
|
-
anim({
|
|
301
|
-
targets: this.tooltipEl,
|
|
302
|
-
opacity: 0,
|
|
303
|
-
translateX: 0,
|
|
304
|
-
translateY: 0,
|
|
305
|
-
duration: this.options.outDuration,
|
|
306
|
-
easing: 'easeOutCubic'
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
_handleMouseEnter = () => {
|
|
311
|
-
this.isHovered = true;
|
|
312
|
-
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
313
|
-
this.open(false);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
_handleMouseLeave = () => {
|
|
317
|
-
this.isHovered = false;
|
|
318
|
-
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
319
|
-
this.close();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
_handleFocus = () => {
|
|
323
|
-
if (Utils.tabPressed) {
|
|
324
|
-
this.isFocused = true;
|
|
325
|
-
this.open(false);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
_handleBlur = () => {
|
|
330
|
-
this.isFocused = false;
|
|
331
|
-
this.close();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
_getAttributeOptions() {
|
|
335
|
-
const attributeOptions = {};
|
|
336
|
-
const tooltipTextOption = this.el.getAttribute('data-tooltip');
|
|
337
|
-
const positionOption = this.el.getAttribute('data-position');
|
|
338
|
-
if (tooltipTextOption) {
|
|
339
|
-
(attributeOptions as any).text = tooltipTextOption;
|
|
340
|
-
}
|
|
341
|
-
if (positionOption) {
|
|
342
|
-
(attributeOptions as any).position = positionOption;
|
|
343
|
-
}
|
|
344
|
-
return attributeOptions;
|
|
345
|
-
}
|
|
346
|
-
}
|