react-tooltip 4.2.6 → 4.2.10
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/CHANGELOG.md +21 -0
- package/README.md +2 -4
- package/dist/index.es.js +144 -137
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +144 -137
- package/dist/index.js.map +1 -1
- package/dist/react-tooltip.d.ts +2 -2
- package/package.json +32 -25
package/dist/index.es.js
CHANGED
|
@@ -156,9 +156,9 @@ function _possibleConstructorReturn(self, call) {
|
|
|
156
156
|
|
|
157
157
|
var CONSTANT = {
|
|
158
158
|
GLOBAL: {
|
|
159
|
-
HIDE:
|
|
160
|
-
REBUILD:
|
|
161
|
-
SHOW:
|
|
159
|
+
HIDE: '__react_tooltip_hide_event',
|
|
160
|
+
REBUILD: '__react_tooltip_rebuild_event',
|
|
161
|
+
SHOW: '__react_tooltip_show_event'
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
164
|
|
|
@@ -172,12 +172,12 @@ var dispatchGlobalEvent = function dispatchGlobalEvent(eventName, opts) {
|
|
|
172
172
|
// @see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
|
|
173
173
|
var event;
|
|
174
174
|
|
|
175
|
-
if (typeof window.CustomEvent ===
|
|
175
|
+
if (typeof window.CustomEvent === 'function') {
|
|
176
176
|
event = new window.CustomEvent(eventName, {
|
|
177
177
|
detail: opts
|
|
178
178
|
});
|
|
179
179
|
} else {
|
|
180
|
-
event = document.createEvent(
|
|
180
|
+
event = document.createEvent('Event');
|
|
181
181
|
event.initEvent(eventName, false, true, opts);
|
|
182
182
|
}
|
|
183
183
|
|
|
@@ -259,8 +259,8 @@ function windowListener (target) {
|
|
|
259
259
|
window.addEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow, false); // Resize
|
|
260
260
|
|
|
261
261
|
if (resizeHide) {
|
|
262
|
-
window.removeEventListener(
|
|
263
|
-
window.addEventListener(
|
|
262
|
+
window.removeEventListener('resize', this.onWindowResize);
|
|
263
|
+
window.addEventListener('resize', this.onWindowResize, false);
|
|
264
264
|
}
|
|
265
265
|
};
|
|
266
266
|
|
|
@@ -268,7 +268,7 @@ function windowListener (target) {
|
|
|
268
268
|
window.removeEventListener(CONSTANT.GLOBAL.HIDE, this.globalHide);
|
|
269
269
|
window.removeEventListener(CONSTANT.GLOBAL.REBUILD, this.globalRebuild);
|
|
270
270
|
window.removeEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow);
|
|
271
|
-
window.removeEventListener(
|
|
271
|
+
window.removeEventListener('resize', this.onWindowResize);
|
|
272
272
|
};
|
|
273
273
|
/**
|
|
274
274
|
* invoked by resize event of window
|
|
@@ -292,13 +292,13 @@ var checkStatus = function checkStatus(dataEventOff, e) {
|
|
|
292
292
|
var show = this.state.show;
|
|
293
293
|
var id = this.props.id;
|
|
294
294
|
var isCapture = this.isCapture(e.currentTarget);
|
|
295
|
-
var currentItem = e.currentTarget.getAttribute(
|
|
295
|
+
var currentItem = e.currentTarget.getAttribute('currentItem');
|
|
296
296
|
if (!isCapture) e.stopPropagation();
|
|
297
297
|
|
|
298
|
-
if (show && currentItem ===
|
|
298
|
+
if (show && currentItem === 'true') {
|
|
299
299
|
if (!dataEventOff) this.hideTooltip(e);
|
|
300
300
|
} else {
|
|
301
|
-
e.currentTarget.setAttribute(
|
|
301
|
+
e.currentTarget.setAttribute('currentItem', 'true');
|
|
302
302
|
setUntargetItems(e.currentTarget, this.getTargetArray(id));
|
|
303
303
|
this.showTooltip(e);
|
|
304
304
|
}
|
|
@@ -307,15 +307,15 @@ var checkStatus = function checkStatus(dataEventOff, e) {
|
|
|
307
307
|
var setUntargetItems = function setUntargetItems(currentTarget, targetArray) {
|
|
308
308
|
for (var i = 0; i < targetArray.length; i++) {
|
|
309
309
|
if (currentTarget !== targetArray[i]) {
|
|
310
|
-
targetArray[i].setAttribute(
|
|
310
|
+
targetArray[i].setAttribute('currentItem', 'false');
|
|
311
311
|
} else {
|
|
312
|
-
targetArray[i].setAttribute(
|
|
312
|
+
targetArray[i].setAttribute('currentItem', 'true');
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
};
|
|
316
316
|
|
|
317
317
|
var customListeners = {
|
|
318
|
-
id:
|
|
318
|
+
id: '9b69f92e-d3fe-498b-b1b4-c5e63a51b0cf',
|
|
319
319
|
set: function set(target, event, listener) {
|
|
320
320
|
if (this.id in target) {
|
|
321
321
|
var map = target[this.id];
|
|
@@ -339,7 +339,7 @@ var customListeners = {
|
|
|
339
339
|
function customEvent (target) {
|
|
340
340
|
target.prototype.isCustomEvent = function (ele) {
|
|
341
341
|
var event = this.state.event;
|
|
342
|
-
return event || !!ele.getAttribute(
|
|
342
|
+
return event || !!ele.getAttribute('data-event');
|
|
343
343
|
};
|
|
344
344
|
/* Bind listener for custom event */
|
|
345
345
|
|
|
@@ -350,9 +350,9 @@ function customEvent (target) {
|
|
|
350
350
|
var _this$state = this.state,
|
|
351
351
|
event = _this$state.event,
|
|
352
352
|
eventOff = _this$state.eventOff;
|
|
353
|
-
var dataEvent = ele.getAttribute(
|
|
354
|
-
var dataEventOff = ele.getAttribute(
|
|
355
|
-
dataEvent.split(
|
|
353
|
+
var dataEvent = ele.getAttribute('data-event') || event;
|
|
354
|
+
var dataEventOff = ele.getAttribute('data-event-off') || eventOff;
|
|
355
|
+
dataEvent.split(' ').forEach(function (event) {
|
|
356
356
|
ele.removeEventListener(event, customListeners.get(ele, event));
|
|
357
357
|
var customListener = checkStatus.bind(_this, dataEventOff);
|
|
358
358
|
customListeners.set(ele, event, customListener);
|
|
@@ -360,7 +360,7 @@ function customEvent (target) {
|
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
if (dataEventOff) {
|
|
363
|
-
dataEventOff.split(
|
|
363
|
+
dataEventOff.split(' ').forEach(function (event) {
|
|
364
364
|
ele.removeEventListener(event, _this.hideTooltip);
|
|
365
365
|
ele.addEventListener(event, _this.hideTooltip, false);
|
|
366
366
|
});
|
|
@@ -373,8 +373,8 @@ function customEvent (target) {
|
|
|
373
373
|
var _this$state2 = this.state,
|
|
374
374
|
event = _this$state2.event,
|
|
375
375
|
eventOff = _this$state2.eventOff;
|
|
376
|
-
var dataEvent = event || ele.getAttribute(
|
|
377
|
-
var dataEventOff = eventOff || ele.getAttribute(
|
|
376
|
+
var dataEvent = event || ele.getAttribute('data-event');
|
|
377
|
+
var dataEventOff = eventOff || ele.getAttribute('data-event-off');
|
|
378
378
|
ele.removeEventListener(dataEvent, customListeners.get(ele, event));
|
|
379
379
|
if (dataEventOff) ele.removeEventListener(dataEventOff, this.hideTooltip);
|
|
380
380
|
};
|
|
@@ -385,7 +385,7 @@ function customEvent (target) {
|
|
|
385
385
|
*/
|
|
386
386
|
function isCapture (target) {
|
|
387
387
|
target.prototype.isCapture = function (currentTarget) {
|
|
388
|
-
return currentTarget && currentTarget.getAttribute(
|
|
388
|
+
return currentTarget && currentTarget.getAttribute('data-iscapture') === 'true' || this.props.isCapture || false;
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
|
|
@@ -394,8 +394,8 @@ function isCapture (target) {
|
|
|
394
394
|
*/
|
|
395
395
|
function getEffect (target) {
|
|
396
396
|
target.prototype.getEffect = function (currentTarget) {
|
|
397
|
-
var dataEffect = currentTarget.getAttribute(
|
|
398
|
-
return dataEffect || this.props.effect ||
|
|
397
|
+
var dataEffect = currentTarget.getAttribute('data-effect');
|
|
398
|
+
return dataEffect || this.props.effect || 'float';
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
401
|
|
|
@@ -407,7 +407,7 @@ var makeProxy = function makeProxy(e) {
|
|
|
407
407
|
var proxy = {};
|
|
408
408
|
|
|
409
409
|
for (var key in e) {
|
|
410
|
-
if (typeof e[key] ===
|
|
410
|
+
if (typeof e[key] === 'function') {
|
|
411
411
|
proxy[key] = e[key].bind(e);
|
|
412
412
|
} else {
|
|
413
413
|
proxy[key] = e[key];
|
|
@@ -423,8 +423,8 @@ var bodyListener = function bodyListener(callback, options, e) {
|
|
|
423
423
|
_options$customEvent = options.customEvent,
|
|
424
424
|
customEvent = _options$customEvent === void 0 ? false : _options$customEvent;
|
|
425
425
|
var id = this.props.id;
|
|
426
|
-
var tip = e.target.getAttribute(
|
|
427
|
-
var forId = e.target.getAttribute(
|
|
426
|
+
var tip = e.target.getAttribute('data-tip') || null;
|
|
427
|
+
var forId = e.target.getAttribute('data-for') || null;
|
|
428
428
|
var target = e.target;
|
|
429
429
|
|
|
430
430
|
if (this.isCustomEvent(target) && !customEvent) {
|
|
@@ -433,7 +433,7 @@ var bodyListener = function bodyListener(callback, options, e) {
|
|
|
433
433
|
|
|
434
434
|
var isTargetBelongsToTooltip = id == null && forId == null || forId === id;
|
|
435
435
|
|
|
436
|
-
if (tip != null && (!respectEffect || this.getEffect(target) ===
|
|
436
|
+
if (tip != null && (!respectEffect || this.getEffect(target) === 'float') && isTargetBelongsToTooltip) {
|
|
437
437
|
var proxy = makeProxy(e);
|
|
438
438
|
proxy.currentTarget = target;
|
|
439
439
|
callback(proxy);
|
|
@@ -444,7 +444,7 @@ var findCustomEvents = function findCustomEvents(targetArray, dataAttribute) {
|
|
|
444
444
|
var events = {};
|
|
445
445
|
targetArray.forEach(function (target) {
|
|
446
446
|
var event = target.getAttribute(dataAttribute);
|
|
447
|
-
if (event) event.split(
|
|
447
|
+
if (event) event.split(' ').forEach(function (event) {
|
|
448
448
|
return events[event] = true;
|
|
449
449
|
});
|
|
450
450
|
});
|
|
@@ -452,7 +452,7 @@ var findCustomEvents = function findCustomEvents(targetArray, dataAttribute) {
|
|
|
452
452
|
};
|
|
453
453
|
|
|
454
454
|
var getBody = function getBody() {
|
|
455
|
-
return document.getElementsByTagName(
|
|
455
|
+
return document.getElementsByTagName('body')[0];
|
|
456
456
|
};
|
|
457
457
|
|
|
458
458
|
function bodyMode (target) {
|
|
@@ -469,14 +469,14 @@ function bodyMode (target) {
|
|
|
469
469
|
possibleCustomEvents = _this$state.possibleCustomEvents,
|
|
470
470
|
possibleCustomEventsOff = _this$state.possibleCustomEventsOff;
|
|
471
471
|
var body = getBody();
|
|
472
|
-
var customEvents = findCustomEvents(targetArray,
|
|
473
|
-
var customEventsOff = findCustomEvents(targetArray,
|
|
472
|
+
var customEvents = findCustomEvents(targetArray, 'data-event');
|
|
473
|
+
var customEventsOff = findCustomEvents(targetArray, 'data-event-off');
|
|
474
474
|
if (event != null) customEvents[event] = true;
|
|
475
475
|
if (eventOff != null) customEventsOff[eventOff] = true;
|
|
476
|
-
possibleCustomEvents.split(
|
|
476
|
+
possibleCustomEvents.split(' ').forEach(function (event) {
|
|
477
477
|
return customEvents[event] = true;
|
|
478
478
|
});
|
|
479
|
-
possibleCustomEventsOff.split(
|
|
479
|
+
possibleCustomEventsOff.split(' ').forEach(function (event) {
|
|
480
480
|
return customEventsOff[event] = true;
|
|
481
481
|
});
|
|
482
482
|
this.unbindBodyListener(body);
|
|
@@ -492,7 +492,7 @@ function bodyMode (target) {
|
|
|
492
492
|
|
|
493
493
|
for (var _event in customEvents) {
|
|
494
494
|
listeners[_event] = bodyListener.bind(this, function (e) {
|
|
495
|
-
var targetEventOff = e.currentTarget.getAttribute(
|
|
495
|
+
var targetEventOff = e.currentTarget.getAttribute('data-event-off') || eventOff;
|
|
496
496
|
checkStatus.call(_this, targetEventOff, e);
|
|
497
497
|
}, {
|
|
498
498
|
customEvent: true
|
|
@@ -671,7 +671,7 @@ function getPosition (e, target, node, place, desiredPlace, effect, offset) {
|
|
|
671
671
|
return !outside(p);
|
|
672
672
|
};
|
|
673
673
|
|
|
674
|
-
var placesList = [
|
|
674
|
+
var placesList = ['top', 'bottom', 'left', 'right'];
|
|
675
675
|
var insideList = [];
|
|
676
676
|
|
|
677
677
|
for (var i = 0; i < 4; i++) {
|
|
@@ -733,7 +733,7 @@ var getCurrentOffset = function getCurrentOffset(e, currentTarget, effect) {
|
|
|
733
733
|
targetWidth = _getDimensions3.width,
|
|
734
734
|
targetHeight = _getDimensions3.height;
|
|
735
735
|
|
|
736
|
-
if (effect ===
|
|
736
|
+
if (effect === 'float') {
|
|
737
737
|
return {
|
|
738
738
|
mouseX: e.clientX,
|
|
739
739
|
mouseY: e.clientY
|
|
@@ -757,7 +757,7 @@ var getDefaultPosition = function getDefaultPosition(effect, targetWidth, target
|
|
|
757
757
|
var triangleHeight = 2;
|
|
758
758
|
var cursorHeight = 12; // Optimize for float bottom only, cause the cursor will hide the tooltip
|
|
759
759
|
|
|
760
|
-
if (effect ===
|
|
760
|
+
if (effect === 'float') {
|
|
761
761
|
top = {
|
|
762
762
|
l: -(tipWidth / 2),
|
|
763
763
|
r: tipWidth / 2,
|
|
@@ -782,7 +782,7 @@ var getDefaultPosition = function getDefaultPosition(effect, targetWidth, target
|
|
|
782
782
|
t: -(tipHeight / 2),
|
|
783
783
|
b: tipHeight / 2
|
|
784
784
|
};
|
|
785
|
-
} else if (effect ===
|
|
785
|
+
} else if (effect === 'solid') {
|
|
786
786
|
top = {
|
|
787
787
|
l: -(tipWidth / 2),
|
|
788
788
|
r: tipWidth / 2,
|
|
@@ -822,18 +822,18 @@ var calculateOffset = function calculateOffset(offset) {
|
|
|
822
822
|
var extraOffsetX = 0;
|
|
823
823
|
var extraOffsetY = 0;
|
|
824
824
|
|
|
825
|
-
if (Object.prototype.toString.apply(offset) ===
|
|
825
|
+
if (Object.prototype.toString.apply(offset) === '[object String]') {
|
|
826
826
|
offset = JSON.parse(offset.toString().replace(/'/g, '"'));
|
|
827
827
|
}
|
|
828
828
|
|
|
829
829
|
for (var key in offset) {
|
|
830
|
-
if (key ===
|
|
830
|
+
if (key === 'top') {
|
|
831
831
|
extraOffsetY -= parseInt(offset[key], 10);
|
|
832
|
-
} else if (key ===
|
|
832
|
+
} else if (key === 'bottom') {
|
|
833
833
|
extraOffsetY += parseInt(offset[key], 10);
|
|
834
|
-
} else if (key ===
|
|
834
|
+
} else if (key === 'left') {
|
|
835
835
|
extraOffsetX -= parseInt(offset[key], 10);
|
|
836
|
-
} else if (key ===
|
|
836
|
+
} else if (key === 'right') {
|
|
837
837
|
extraOffsetX += parseInt(offset[key], 10);
|
|
838
838
|
}
|
|
839
839
|
}
|
|
@@ -849,7 +849,10 @@ var getParent = function getParent(currentTarget) {
|
|
|
849
849
|
var currentParent = currentTarget;
|
|
850
850
|
|
|
851
851
|
while (currentParent) {
|
|
852
|
-
|
|
852
|
+
var computedStyle = window.getComputedStyle(currentParent); // transform and will-change: transform change the containing block
|
|
853
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_Block
|
|
854
|
+
|
|
855
|
+
if (computedStyle.getPropertyValue('transform') !== 'none' || computedStyle.getPropertyValue('will-change') === 'transform') break;
|
|
853
856
|
currentParent = currentParent.parentElement;
|
|
854
857
|
}
|
|
855
858
|
|
|
@@ -882,7 +885,7 @@ function getTipContent (tip, children, getContent, multiline) {
|
|
|
882
885
|
|
|
883
886
|
var regexp = /<br\s*\/?>/;
|
|
884
887
|
|
|
885
|
-
if (!multiline || multiline ===
|
|
888
|
+
if (!multiline || multiline === 'false' || !regexp.test(tip)) {
|
|
886
889
|
// No trim(), so that user can keep their input
|
|
887
890
|
return tip;
|
|
888
891
|
} // Multiline tooltip content
|
|
@@ -931,7 +934,7 @@ function nodeListToArray (nodeList) {
|
|
|
931
934
|
}
|
|
932
935
|
|
|
933
936
|
function generateUUID() {
|
|
934
|
-
return
|
|
937
|
+
return 't' + v4();
|
|
935
938
|
}
|
|
936
939
|
|
|
937
940
|
___$insertStyle(".__react_component_tooltip {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n left: -999em;\n opacity: 0;\n padding: 8px 21px;\n position: fixed;\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n top: -999em;\n visibility: hidden;\n z-index: 999;\n}\n.__react_component_tooltip.allow_hover, .__react_component_tooltip.allow_click {\n pointer-events: auto;\n}\n.__react_component_tooltip::before, .__react_component_tooltip::after {\n content: \"\";\n width: 0;\n height: 0;\n position: absolute;\n}\n.__react_component_tooltip.show {\n opacity: 0.9;\n margin-top: 0;\n margin-left: 0;\n visibility: visible;\n}\n.__react_component_tooltip.place-top::before {\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n bottom: -8px;\n left: 50%;\n margin-left: -10px;\n}\n.__react_component_tooltip.place-bottom::before {\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n top: -8px;\n left: 50%;\n margin-left: -10px;\n}\n.__react_component_tooltip.place-left::before {\n border-top: 6px solid transparent;\n border-bottom: 6px solid transparent;\n right: -8px;\n top: 50%;\n margin-top: -5px;\n}\n.__react_component_tooltip.place-right::before {\n border-top: 6px solid transparent;\n border-bottom: 6px solid transparent;\n left: -8px;\n top: 50%;\n margin-top: -5px;\n}\n.__react_component_tooltip .multi-line {\n display: block;\n padding: 2px 0;\n text-align: center;\n}");
|
|
@@ -940,41 +943,41 @@ ___$insertStyle(".__react_component_tooltip {\n border-radius: 3px;\n display:
|
|
|
940
943
|
* Default pop-up style values (text color, background color).
|
|
941
944
|
*/
|
|
942
945
|
var defaultColors = {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
946
|
+
dark: {
|
|
947
|
+
text: '#fff',
|
|
948
|
+
background: '#222',
|
|
949
|
+
border: 'transparent',
|
|
950
|
+
arrow: '#222'
|
|
948
951
|
},
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
952
|
+
success: {
|
|
953
|
+
text: '#fff',
|
|
954
|
+
background: '#8DC572',
|
|
955
|
+
border: 'transparent',
|
|
956
|
+
arrow: '#8DC572'
|
|
954
957
|
},
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
958
|
+
warning: {
|
|
959
|
+
text: '#fff',
|
|
960
|
+
background: '#F0AD4E',
|
|
961
|
+
border: 'transparent',
|
|
962
|
+
arrow: '#F0AD4E'
|
|
960
963
|
},
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
964
|
+
error: {
|
|
965
|
+
text: '#fff',
|
|
966
|
+
background: '#BE6464',
|
|
967
|
+
border: 'transparent',
|
|
968
|
+
arrow: '#BE6464'
|
|
966
969
|
},
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
970
|
+
info: {
|
|
971
|
+
text: '#fff',
|
|
972
|
+
background: '#337AB7',
|
|
973
|
+
border: 'transparent',
|
|
974
|
+
arrow: '#337AB7'
|
|
972
975
|
},
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
976
|
+
light: {
|
|
977
|
+
text: '#222',
|
|
978
|
+
background: '#fff',
|
|
979
|
+
border: 'transparent',
|
|
980
|
+
arrow: '#fff'
|
|
978
981
|
}
|
|
979
982
|
};
|
|
980
983
|
function getDefaultPopupColors(type) {
|
|
@@ -982,8 +985,8 @@ function getDefaultPopupColors(type) {
|
|
|
982
985
|
}
|
|
983
986
|
|
|
984
987
|
/**
|
|
985
|
-
* Generates the specific tooltip style for use on render.
|
|
986
|
-
*/
|
|
988
|
+
* Generates the specific tooltip style for use on render.
|
|
989
|
+
*/
|
|
987
990
|
|
|
988
991
|
function generateTooltipStyle(uuid, customColors, type, hasBorder) {
|
|
989
992
|
return generateStyle(uuid, getPopupColors(customColors, type, hasBorder));
|
|
@@ -1019,7 +1022,7 @@ function getPopupColors(customColors, type, hasBorder) {
|
|
|
1019
1022
|
if (borderColor) {
|
|
1020
1023
|
colors.border = borderColor;
|
|
1021
1024
|
} else {
|
|
1022
|
-
colors.border = type ===
|
|
1025
|
+
colors.border = type === 'light' ? 'black' : 'white';
|
|
1023
1026
|
}
|
|
1024
1027
|
}
|
|
1025
1028
|
|
|
@@ -1089,18 +1092,18 @@ function (_React$Component) {
|
|
|
1089
1092
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(ReactTooltip).call(this, props));
|
|
1090
1093
|
_this.state = {
|
|
1091
1094
|
uuid: props.uuid || generateUUID(),
|
|
1092
|
-
place: props.place ||
|
|
1095
|
+
place: props.place || 'top',
|
|
1093
1096
|
// Direction of tooltip
|
|
1094
|
-
desiredPlace: props.place ||
|
|
1095
|
-
type:
|
|
1097
|
+
desiredPlace: props.place || 'top',
|
|
1098
|
+
type: 'dark',
|
|
1096
1099
|
// Color theme of tooltip
|
|
1097
|
-
effect:
|
|
1100
|
+
effect: 'float',
|
|
1098
1101
|
// float or fixed
|
|
1099
1102
|
show: false,
|
|
1100
1103
|
border: false,
|
|
1101
1104
|
customColors: {},
|
|
1102
1105
|
offset: {},
|
|
1103
|
-
extraClass:
|
|
1106
|
+
extraClass: '',
|
|
1104
1107
|
html: false,
|
|
1105
1108
|
delayHide: 0,
|
|
1106
1109
|
delayShow: 0,
|
|
@@ -1114,13 +1117,13 @@ function (_React$Component) {
|
|
|
1114
1117
|
// aria- and role attributes
|
|
1115
1118
|
isEmptyTip: false,
|
|
1116
1119
|
disable: false,
|
|
1117
|
-
possibleCustomEvents: props.possibleCustomEvents ||
|
|
1118
|
-
possibleCustomEventsOff: props.possibleCustomEventsOff ||
|
|
1120
|
+
possibleCustomEvents: props.possibleCustomEvents || '',
|
|
1121
|
+
possibleCustomEventsOff: props.possibleCustomEventsOff || '',
|
|
1119
1122
|
originTooltip: null,
|
|
1120
1123
|
isMultiline: false
|
|
1121
1124
|
};
|
|
1122
1125
|
|
|
1123
|
-
_this.bind([
|
|
1126
|
+
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'hideTooltipOnScroll', 'getTooltipContent', 'globalRebuild', 'globalShow', 'globalHide', 'onWindowResize', 'mouseOnToolTip']);
|
|
1124
1127
|
|
|
1125
1128
|
_this.mount = true;
|
|
1126
1129
|
_this.delayShowLoop = null;
|
|
@@ -1184,7 +1187,7 @@ function (_React$Component) {
|
|
|
1184
1187
|
}
|
|
1185
1188
|
}
|
|
1186
1189
|
|
|
1187
|
-
return this.tooltipRef.matches(
|
|
1190
|
+
return this.tooltipRef.matches(':hover');
|
|
1188
1191
|
}
|
|
1189
1192
|
|
|
1190
1193
|
return false;
|
|
@@ -1200,14 +1203,14 @@ function (_React$Component) {
|
|
|
1200
1203
|
var selector;
|
|
1201
1204
|
|
|
1202
1205
|
if (!id) {
|
|
1203
|
-
selector =
|
|
1206
|
+
selector = '[data-tip]:not([data-for])';
|
|
1204
1207
|
} else {
|
|
1205
|
-
var escaped = id.replace(/\\/g,
|
|
1208
|
+
var escaped = id.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
1206
1209
|
selector = "[data-tip][data-for=\"".concat(escaped, "\"]");
|
|
1207
1210
|
} // Scan document for shadow DOM elements
|
|
1208
1211
|
|
|
1209
1212
|
|
|
1210
|
-
nodeListToArray(document.getElementsByTagName(
|
|
1213
|
+
nodeListToArray(document.getElementsByTagName('*')).filter(function (element) {
|
|
1211
1214
|
return element.shadowRoot;
|
|
1212
1215
|
}).forEach(function (element) {
|
|
1213
1216
|
targetArray = targetArray.concat(nodeListToArray(element.shadowRoot.querySelectorAll(selector)));
|
|
@@ -1230,8 +1233,8 @@ function (_React$Component) {
|
|
|
1230
1233
|
isCapture = _this$props2.isCapture;
|
|
1231
1234
|
var targetArray = this.getTargetArray(id);
|
|
1232
1235
|
targetArray.forEach(function (target) {
|
|
1233
|
-
if (target.getAttribute(
|
|
1234
|
-
target.setAttribute(
|
|
1236
|
+
if (target.getAttribute('currentItem') === null) {
|
|
1237
|
+
target.setAttribute('currentItem', 'false');
|
|
1235
1238
|
}
|
|
1236
1239
|
|
|
1237
1240
|
_this3.unbindBasicListener(target);
|
|
@@ -1255,13 +1258,13 @@ function (_React$Component) {
|
|
|
1255
1258
|
return;
|
|
1256
1259
|
}
|
|
1257
1260
|
|
|
1258
|
-
target.addEventListener(
|
|
1261
|
+
target.addEventListener('mouseenter', _this3.showTooltip, isCaptureMode);
|
|
1259
1262
|
|
|
1260
|
-
if (effect ===
|
|
1261
|
-
target.addEventListener(
|
|
1263
|
+
if (effect === 'float') {
|
|
1264
|
+
target.addEventListener('mousemove', _this3.updateTooltip, isCaptureMode);
|
|
1262
1265
|
}
|
|
1263
1266
|
|
|
1264
|
-
target.addEventListener(
|
|
1267
|
+
target.addEventListener('mouseleave', _this3.hideTooltip, isCaptureMode);
|
|
1265
1268
|
});
|
|
1266
1269
|
} // Global event to hide tooltip
|
|
1267
1270
|
|
|
@@ -1311,9 +1314,9 @@ function (_React$Component) {
|
|
|
1311
1314
|
key: "unbindBasicListener",
|
|
1312
1315
|
value: function unbindBasicListener(target) {
|
|
1313
1316
|
var isCaptureMode = this.isCapture(target);
|
|
1314
|
-
target.removeEventListener(
|
|
1315
|
-
target.removeEventListener(
|
|
1316
|
-
target.removeEventListener(
|
|
1317
|
+
target.removeEventListener('mouseenter', this.showTooltip, isCaptureMode);
|
|
1318
|
+
target.removeEventListener('mousemove', this.updateTooltip, isCaptureMode);
|
|
1319
|
+
target.removeEventListener('mouseleave', this.hideTooltip, isCaptureMode);
|
|
1317
1320
|
}
|
|
1318
1321
|
}, {
|
|
1319
1322
|
key: "getTooltipContent",
|
|
@@ -1337,7 +1340,7 @@ function (_React$Component) {
|
|
|
1337
1340
|
}, {
|
|
1338
1341
|
key: "isEmptyTip",
|
|
1339
1342
|
value: function isEmptyTip(placeholder) {
|
|
1340
|
-
return typeof placeholder ===
|
|
1343
|
+
return typeof placeholder === 'string' && placeholder === '' || placeholder === null;
|
|
1341
1344
|
}
|
|
1342
1345
|
/**
|
|
1343
1346
|
* When mouse enter, show the tooltip
|
|
@@ -1346,6 +1349,10 @@ function (_React$Component) {
|
|
|
1346
1349
|
}, {
|
|
1347
1350
|
key: "showTooltip",
|
|
1348
1351
|
value: function showTooltip(e, isGlobalCall) {
|
|
1352
|
+
if (!this.tooltipRef) {
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1349
1356
|
if (isGlobalCall) {
|
|
1350
1357
|
// Don't trigger other elements belongs to other ReactTooltip
|
|
1351
1358
|
var targetArray = this.getTargetArray(this.props.id);
|
|
@@ -1360,23 +1367,23 @@ function (_React$Component) {
|
|
|
1360
1367
|
var _this$props5 = this.props,
|
|
1361
1368
|
multiline = _this$props5.multiline,
|
|
1362
1369
|
getContent = _this$props5.getContent;
|
|
1363
|
-
var originTooltip = e.currentTarget.getAttribute(
|
|
1364
|
-
var isMultiline = e.currentTarget.getAttribute(
|
|
1370
|
+
var originTooltip = e.currentTarget.getAttribute('data-tip');
|
|
1371
|
+
var isMultiline = e.currentTarget.getAttribute('data-multiline') || multiline || false; // If it is focus event or called by ReactTooltip.show, switch to `solid` effect
|
|
1365
1372
|
|
|
1366
1373
|
var switchToSolid = e instanceof window.FocusEvent || isGlobalCall; // if it needs to skip adding hide listener to scroll
|
|
1367
1374
|
|
|
1368
1375
|
var scrollHide = true;
|
|
1369
1376
|
|
|
1370
|
-
if (e.currentTarget.getAttribute(
|
|
1371
|
-
scrollHide = e.currentTarget.getAttribute(
|
|
1377
|
+
if (e.currentTarget.getAttribute('data-scroll-hide')) {
|
|
1378
|
+
scrollHide = e.currentTarget.getAttribute('data-scroll-hide') === 'true';
|
|
1372
1379
|
} else if (this.props.scrollHide != null) {
|
|
1373
1380
|
scrollHide = this.props.scrollHide;
|
|
1374
1381
|
} // Make sure the correct place is set
|
|
1375
1382
|
|
|
1376
1383
|
|
|
1377
|
-
var desiredPlace = e.currentTarget.getAttribute(
|
|
1378
|
-
var effect = switchToSolid &&
|
|
1379
|
-
var offset = e.currentTarget.getAttribute(
|
|
1384
|
+
var desiredPlace = e.currentTarget.getAttribute('data-place') || this.props.place || 'top';
|
|
1385
|
+
var effect = switchToSolid && 'solid' || this.getEffect(e.currentTarget);
|
|
1386
|
+
var offset = e.currentTarget.getAttribute('data-offset') || this.props.offset || {};
|
|
1380
1387
|
var result = getPosition(e, e.currentTarget, this.tooltipRef, desiredPlace, desiredPlace, effect, offset);
|
|
1381
1388
|
|
|
1382
1389
|
if (result.position && this.props.overridePosition) {
|
|
@@ -1387,7 +1394,7 @@ function (_React$Component) {
|
|
|
1387
1394
|
|
|
1388
1395
|
this.clearTimer();
|
|
1389
1396
|
var target = e.currentTarget;
|
|
1390
|
-
var reshowDelay = this.state.show ? target.getAttribute(
|
|
1397
|
+
var reshowDelay = this.state.show ? target.getAttribute('data-delay-update') || this.props.delayUpdate : 0;
|
|
1391
1398
|
var self = this;
|
|
1392
1399
|
|
|
1393
1400
|
var updateState = function updateState() {
|
|
@@ -1396,22 +1403,22 @@ function (_React$Component) {
|
|
|
1396
1403
|
isMultiline: isMultiline,
|
|
1397
1404
|
desiredPlace: desiredPlace,
|
|
1398
1405
|
place: place,
|
|
1399
|
-
type: target.getAttribute(
|
|
1406
|
+
type: target.getAttribute('data-type') || self.props.type || 'dark',
|
|
1400
1407
|
customColors: {
|
|
1401
|
-
text: target.getAttribute(
|
|
1402
|
-
background: target.getAttribute(
|
|
1403
|
-
border: target.getAttribute(
|
|
1404
|
-
arrow: target.getAttribute(
|
|
1408
|
+
text: target.getAttribute('data-text-color') || self.props.textColor || null,
|
|
1409
|
+
background: target.getAttribute('data-background-color') || self.props.backgroundColor || null,
|
|
1410
|
+
border: target.getAttribute('data-border-color') || self.props.borderColor || null,
|
|
1411
|
+
arrow: target.getAttribute('data-arrow-color') || self.props.arrowColor || null
|
|
1405
1412
|
},
|
|
1406
1413
|
effect: effect,
|
|
1407
1414
|
offset: offset,
|
|
1408
|
-
html: (target.getAttribute(
|
|
1409
|
-
delayShow: target.getAttribute(
|
|
1410
|
-
delayHide: target.getAttribute(
|
|
1411
|
-
delayUpdate: target.getAttribute(
|
|
1412
|
-
border: (target.getAttribute(
|
|
1413
|
-
extraClass: target.getAttribute(
|
|
1414
|
-
disable: (target.getAttribute(
|
|
1415
|
+
html: (target.getAttribute('data-html') ? target.getAttribute('data-html') === 'true' : self.props.html) || false,
|
|
1416
|
+
delayShow: target.getAttribute('data-delay-show') || self.props.delayShow || 0,
|
|
1417
|
+
delayHide: target.getAttribute('data-delay-hide') || self.props.delayHide || 0,
|
|
1418
|
+
delayUpdate: target.getAttribute('data-delay-update') || self.props.delayUpdate || 0,
|
|
1419
|
+
border: (target.getAttribute('data-border') ? target.getAttribute('data-border') === 'true' : self.props.border) || false,
|
|
1420
|
+
extraClass: target.getAttribute('data-class') || self.props["class"] || self.props.className || '',
|
|
1421
|
+
disable: (target.getAttribute('data-tip-disable') ? target.getAttribute('data-tip-disable') === 'true' : self.props.disable) || false,
|
|
1415
1422
|
currentTarget: target
|
|
1416
1423
|
}, function () {
|
|
1417
1424
|
if (scrollHide) {
|
|
@@ -1424,7 +1431,7 @@ function (_React$Component) {
|
|
|
1424
1431
|
self.intervalUpdateContent = setInterval(function () {
|
|
1425
1432
|
if (self.mount) {
|
|
1426
1433
|
var _getContent = self.props.getContent;
|
|
1427
|
-
var placeholder = getTipContent(originTooltip,
|
|
1434
|
+
var placeholder = getTipContent(originTooltip, '', _getContent[0](), isMultiline);
|
|
1428
1435
|
var isEmptyTip = self.isEmptyTip(placeholder);
|
|
1429
1436
|
self.setState({
|
|
1430
1437
|
isEmptyTip: isEmptyTip
|
|
@@ -1505,7 +1512,7 @@ function (_React$Component) {
|
|
|
1505
1512
|
var show = this.state.show;
|
|
1506
1513
|
|
|
1507
1514
|
if (show && this.tooltipRef) {
|
|
1508
|
-
this.tooltipRef.addEventListener(
|
|
1515
|
+
this.tooltipRef.addEventListener('mouseleave', this.hideTooltip);
|
|
1509
1516
|
}
|
|
1510
1517
|
}
|
|
1511
1518
|
}, {
|
|
@@ -1514,7 +1521,7 @@ function (_React$Component) {
|
|
|
1514
1521
|
var show = this.state.show;
|
|
1515
1522
|
|
|
1516
1523
|
if (show && this.tooltipRef) {
|
|
1517
|
-
this.tooltipRef.removeEventListener(
|
|
1524
|
+
this.tooltipRef.removeEventListener('mouseleave', this.hideTooltip);
|
|
1518
1525
|
}
|
|
1519
1526
|
}
|
|
1520
1527
|
/**
|
|
@@ -1596,13 +1603,13 @@ function (_React$Component) {
|
|
|
1596
1603
|
key: "addScrollListener",
|
|
1597
1604
|
value: function addScrollListener(currentTarget) {
|
|
1598
1605
|
var isCaptureMode = this.isCapture(currentTarget);
|
|
1599
|
-
window.addEventListener(
|
|
1606
|
+
window.addEventListener('scroll', this.hideTooltipOnScroll, isCaptureMode);
|
|
1600
1607
|
}
|
|
1601
1608
|
}, {
|
|
1602
1609
|
key: "removeScrollListener",
|
|
1603
1610
|
value: function removeScrollListener(currentTarget) {
|
|
1604
1611
|
var isCaptureMode = this.isCapture(currentTarget);
|
|
1605
|
-
window.removeEventListener(
|
|
1612
|
+
window.removeEventListener('scroll', this.hideTooltipOnScroll, isCaptureMode);
|
|
1606
1613
|
} // Calculation the position
|
|
1607
1614
|
|
|
1608
1615
|
}, {
|
|
@@ -1632,8 +1639,8 @@ function (_React$Component) {
|
|
|
1632
1639
|
} // Set tooltip position
|
|
1633
1640
|
|
|
1634
1641
|
|
|
1635
|
-
node.style.left = result.position.left +
|
|
1636
|
-
node.style.top = result.position.top +
|
|
1642
|
+
node.style.left = result.position.left + 'px';
|
|
1643
|
+
node.style.top = result.position.top + 'px';
|
|
1637
1644
|
}
|
|
1638
1645
|
/**
|
|
1639
1646
|
* CLear all kinds of timeout of interval
|
|
@@ -1653,8 +1660,8 @@ function (_React$Component) {
|
|
|
1653
1660
|
var _this8 = this;
|
|
1654
1661
|
|
|
1655
1662
|
return Boolean(Object.keys(this.state.customColors).find(function (color) {
|
|
1656
|
-
return color !==
|
|
1657
|
-
}) || this.state.border && this.state.customColors[
|
|
1663
|
+
return color !== 'border' && _this8.state.customColors[color];
|
|
1664
|
+
}) || this.state.border && this.state.customColors['border']);
|
|
1658
1665
|
}
|
|
1659
1666
|
}, {
|
|
1660
1667
|
key: "render",
|
|
@@ -1669,16 +1676,16 @@ function (_React$Component) {
|
|
|
1669
1676
|
var content = this.getTooltipContent();
|
|
1670
1677
|
var isEmptyTip = this.isEmptyTip(content);
|
|
1671
1678
|
var style = generateTooltipStyle(this.state.uuid, this.state.customColors, this.state.type, this.state.border);
|
|
1672
|
-
var tooltipClass =
|
|
1673
|
-
" type-".concat(this.hasCustomColors() ?
|
|
1674
|
-
this.props.delayUpdate ?
|
|
1679
|
+
var tooltipClass = '__react_component_tooltip' + " ".concat(this.state.uuid) + (this.state.show && !disable && !isEmptyTip ? ' show' : '') + (this.state.border ? ' border' : '') + " place-".concat(this.state.place) + // top, bottom, left, right
|
|
1680
|
+
" type-".concat(this.hasCustomColors() ? 'custom' : this.state.type) + ( // dark, success, warning, error, info, light, custom
|
|
1681
|
+
this.props.delayUpdate ? ' allow_hover' : '') + (this.props.clickable ? ' allow_click' : '');
|
|
1675
1682
|
var Wrapper = this.props.wrapper;
|
|
1676
1683
|
|
|
1677
1684
|
if (ReactTooltip.supportedWrappers.indexOf(Wrapper) < 0) {
|
|
1678
1685
|
Wrapper = ReactTooltip.defaultProps.wrapper;
|
|
1679
1686
|
}
|
|
1680
1687
|
|
|
1681
|
-
var wrapperClassName = [tooltipClass, extraClass].filter(Boolean).join(
|
|
1688
|
+
var wrapperClassName = [tooltipClass, extraClass].filter(Boolean).join(' ');
|
|
1682
1689
|
|
|
1683
1690
|
if (html) {
|
|
1684
1691
|
var htmlContent = "".concat(content, "\n<style>").concat(style, "</style>");
|
|
@@ -1733,9 +1740,9 @@ function (_React$Component) {
|
|
|
1733
1740
|
}(React.Component), _defineProperty(_class2, "defaultProps", {
|
|
1734
1741
|
insecure: true,
|
|
1735
1742
|
resizeHide: true,
|
|
1736
|
-
wrapper:
|
|
1743
|
+
wrapper: 'div',
|
|
1737
1744
|
clickable: false
|
|
1738
|
-
}), _defineProperty(_class2, "supportedWrappers", [
|
|
1745
|
+
}), _defineProperty(_class2, "supportedWrappers", ['div', 'span']), _defineProperty(_class2, "displayName", 'ReactTooltip'), _temp)) || _class) || _class) || _class) || _class) || _class) || _class) || _class;
|
|
1739
1746
|
|
|
1740
1747
|
export default ReactTooltip;
|
|
1741
1748
|
//# sourceMappingURL=index.es.js.map
|