react-tooltip-lite
Advanced tools
Comparing version 1.11.1 to 1.11.2
@@ -206,4 +206,39 @@ "use strict"; | ||
}); | ||
it('should support onToggle prop'); | ||
it('should support zIndex prop'); | ||
it('should support onToggle prop', function () { | ||
var spy = jest.fn(); | ||
var _render9 = (0, _reactTestingLibrary.render)(_react["default"].createElement(_index["default"], { | ||
content: tipContent, | ||
onToggle: spy | ||
}, targetContent)), | ||
getByText = _render9.getByText; | ||
var target = getByText(targetContent); | ||
_reactTestingLibrary.fireEvent.mouseOver(target); | ||
jest.runAllTimers(); | ||
expect(spy).toHaveBeenCalledWith(true); | ||
_reactTestingLibrary.fireEvent.mouseOut(target); | ||
jest.runAllTimers(); | ||
expect(spy).toHaveBeenCalledWith(false); | ||
}); | ||
it('should support zIndex prop', function () { | ||
var _render10 = (0, _reactTestingLibrary.render)(_react["default"].createElement(_index["default"], { | ||
content: tipContent, | ||
zIndex: 5000 | ||
}, targetContent)), | ||
getByText = _render10.getByText; | ||
var target = getByText(targetContent); | ||
_reactTestingLibrary.fireEvent.mouseOver(target); | ||
jest.runAllTimers(); | ||
var tip = getByText(tipContent); | ||
var styles = window.getComputedStyle(tip); | ||
expect(styles['z-index']).toEqual('5000'); | ||
}); | ||
}); |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _position = require("./position"); | ||
var _functions = require("./functions"); | ||
@@ -33,3 +33,3 @@ /** | ||
var halfTargetHeight = target.offsetHeight / 2; | ||
var arrowClearance = props.arrowSize + _position.minArrowPadding; | ||
var arrowClearance = props.arrowSize + _functions.minArrowPadding; | ||
var bottomOverhangAmount = targetRect.bottom - window.innerHeight; | ||
@@ -47,3 +47,3 @@ var topOverhangAmount = -targetRect.top; | ||
function checkForArrowOverhang(props, arrowStyles, bodyPadding) { | ||
var scrollLeft = (0, _position.getScrollLeft)(); | ||
var scrollLeft = (0, _functions.getScrollLeft)(); | ||
var hasLeftClearance = arrowStyles.left - scrollLeft > bodyPadding; | ||
@@ -61,3 +61,3 @@ var hasRightClearance = arrowStyles.left + props.arrowSize * 2 < scrollLeft + document.documentElement.clientWidth - bodyPadding; | ||
var targetRect = target.getBoundingClientRect(); | ||
var arrowSpacing = (0, _position.getArrowSpacing)(props); // this is how much space is needed to display the tip above or below the target | ||
var arrowSpacing = (0, _functions.getArrowSpacing)(props); // this is how much space is needed to display the tip above or below the target | ||
@@ -64,0 +64,0 @@ var heightOfTipWithArrow = tip.offsetHeight + arrowSpacing + bodyPadding; |
@@ -21,3 +21,3 @@ declare module 'react-tooltip-lite' { | ||
mouseOutDelay?: number; | ||
padding?: string; | ||
padding?: string | number; | ||
styles?: object; | ||
@@ -24,0 +24,0 @@ tagName?: string; |
@@ -16,2 +16,4 @@ "use strict"; | ||
var _functions = require("./functions"); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } } | ||
@@ -113,4 +115,5 @@ | ||
this.scrollParent = (0, _functions.getScrollParent)(this.target); | ||
window.addEventListener('resize', this.listenResizeScroll); | ||
window.addEventListener('scroll', this.listenResizeScroll); | ||
this.scrollParent.addEventListener('scroll', this.listenResizeScroll); | ||
window.addEventListener('touchstart', this.bodyTouchStart); | ||
@@ -141,3 +144,3 @@ window.addEventListener('touchEnd', this.bodyTouchEnd); | ||
window.removeEventListener('resize', this.listenResizeScroll); | ||
window.removeEventListener('scroll', this.listenResizeScroll); | ||
this.scrollParent.removeEventListener('scroll', this.listenResizeScroll); | ||
window.removeEventListener('touchstart', this.bodyTouchStart); | ||
@@ -406,3 +409,3 @@ window.removeEventListener('touchEnd', this.bodyTouchEnd); | ||
mouseOutDelay: _propTypes["default"].number, | ||
padding: _propTypes["default"].string, | ||
padding: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]), | ||
styles: _propTypes["default"].object, | ||
@@ -409,0 +412,0 @@ tagName: _propTypes["default"].string, |
@@ -6,9 +6,8 @@ "use strict"; | ||
}); | ||
exports.getScrollLeft = getScrollLeft; | ||
exports.getArrowSpacing = getArrowSpacing; | ||
exports["default"] = positions; | ||
exports.minArrowPadding = void 0; | ||
var _getDirection = _interopRequireDefault(require("./getDirection")); | ||
var _functions = require("./functions"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -20,24 +19,7 @@ | ||
var minArrowPadding = 5; | ||
exports.minArrowPadding = minArrowPadding; | ||
var bodyPadding = 10; | ||
var noArrowDistance = 3; | ||
/** | ||
* cross browser scroll positions | ||
*/ | ||
function getScrollTop() { | ||
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
} | ||
function getScrollLeft() { | ||
return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; | ||
} | ||
/** | ||
* Sets tip max width safely for mobile | ||
*/ | ||
function getTipMaxWidth() { | ||
return typeof document !== 'undefined' ? document.documentElement.clientWidth - bodyPadding * 2 : 1000; | ||
return typeof document !== 'undefined' ? document.documentElement.clientWidth - _functions.bodyPadding * 2 : 1000; | ||
} | ||
@@ -59,7 +41,2 @@ /** | ||
} | ||
function getArrowSpacing(props) { | ||
var defaultArrowSpacing = props.arrow ? props.arrowSize : noArrowDistance; | ||
return typeof props.distance === 'number' ? props.distance : defaultArrowSpacing; | ||
} | ||
/** | ||
@@ -74,7 +51,7 @@ * Gets wrapper's left position for top/bottom tooltips as well as needed width restriction | ||
var transform = state.showTip ? undefined : 'translateX(-10000000px)'; | ||
var arrowSpacing = getArrowSpacing(props); | ||
var arrowSpacing = (0, _functions.getArrowSpacing)(props); | ||
if (tip) { | ||
// get wrapper left position | ||
var scrollLeft = getScrollLeft(); | ||
var scrollLeft = (0, _functions.getScrollLeft)(); | ||
var targetRect = target.getBoundingClientRect(); | ||
@@ -93,6 +70,6 @@ var targetLeft = targetRect.left + scrollLeft; | ||
var rightEdge = props.arrow ? rightWithArrow : targetLeft + target.offsetWidth; | ||
left = Math.max(rightEdge - tipWidth, bodyPadding + scrollLeft); | ||
left = Math.max(rightEdge - tipWidth, _functions.bodyPadding + scrollLeft); | ||
} else { | ||
var centeredLeft = targetLeft + halfTargetWidth - Math.round(tipWidth / 2); | ||
var availableSpaceOnLeft = bodyPadding + scrollLeft; | ||
var availableSpaceOnLeft = _functions.bodyPadding + scrollLeft; | ||
left = Math.max(centeredLeft, availableSpaceOnLeft); | ||
@@ -103,3 +80,3 @@ } // check for right overhang | ||
var rightOfTip = left + tipWidth; | ||
var rightOfScreen = scrollLeft + document.documentElement.clientWidth - bodyPadding; | ||
var rightOfScreen = scrollLeft + document.documentElement.clientWidth - _functions.bodyPadding; | ||
var rightOverhang = rightOfTip - rightOfScreen; | ||
@@ -112,5 +89,5 @@ | ||
if (direction === 'up') { | ||
top = targetRect.top + getScrollTop() - (tip.offsetHeight + arrowSpacing); | ||
top = targetRect.top + (0, _functions.getScrollTop)() - (tip.offsetHeight + arrowSpacing); | ||
} else { | ||
top = targetRect.bottom + getScrollTop() + arrowSpacing; | ||
top = targetRect.bottom + (0, _functions.getScrollTop)() + arrowSpacing; | ||
} | ||
@@ -134,8 +111,8 @@ } | ||
var transform = state.showTip ? undefined : 'translateX(-10000000px)'; | ||
var arrowSpacing = getArrowSpacing(props); | ||
var arrowPadding = props.arrow ? minArrowPadding : 0; | ||
var arrowSpacing = (0, _functions.getArrowSpacing)(props); | ||
var arrowPadding = props.arrow ? _functions.minArrowPadding : 0; | ||
if (tip) { | ||
var scrollTop = getScrollTop(); | ||
var scrollLeft = getScrollLeft(); | ||
var scrollTop = (0, _functions.getScrollTop)(); | ||
var scrollLeft = (0, _functions.getScrollLeft)(); | ||
var targetRect = target.getBoundingClientRect(); | ||
@@ -154,3 +131,3 @@ var targetTop = targetRect.top + scrollTop; | ||
// default to middle, but don't go below body | ||
var centeredTop = Math.max(targetTop + halfTargetHeight - Math.round(tip.offsetHeight / 2), bodyPadding + scrollTop); // make sure it doesn't go below the arrow | ||
var centeredTop = Math.max(targetTop + halfTargetHeight - Math.round(tip.offsetHeight / 2), _functions.bodyPadding + scrollTop); // make sure it doesn't go below the arrow | ||
@@ -161,3 +138,3 @@ top = Math.min(centeredTop, arrowTop - arrowPadding); | ||
var bottomOverhang = top - scrollTop + tip.offsetHeight + bodyPadding - window.innerHeight; | ||
var bottomOverhang = top - scrollTop + tip.offsetHeight + _functions.bodyPadding - window.innerHeight; | ||
@@ -198,5 +175,5 @@ if (bottomOverhang > 0) { | ||
var halfTargetWidth = Math.round(target.offsetWidth / 2); | ||
var scrollTop = getScrollTop(); | ||
var scrollLeft = getScrollLeft(); | ||
var arrowSpacing = getArrowSpacing(props); | ||
var scrollTop = (0, _functions.getScrollTop)(); | ||
var scrollLeft = (0, _functions.getScrollLeft)(); | ||
var arrowSpacing = (0, _functions.getArrowSpacing)(props); | ||
var borderStyles = {}; | ||
@@ -283,3 +260,3 @@ | ||
var testArrowStyles = props.arrow && getArrowStyles(target, tip, trimmedDirection, state, props); | ||
realDirection = (0, _getDirection["default"])(trimmedDirection, tip, target, props, bodyPadding, testArrowStyles); | ||
realDirection = (0, _getDirection["default"])(trimmedDirection, tip, target, props, _functions.bodyPadding, testArrowStyles); | ||
} | ||
@@ -286,0 +263,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","ReactDOM"],e):"object"==typeof exports?exports.ReactToolTipLite=e(require("React"),require("ReactDOM")):t.ReactToolTipLite=e(t.React,t.ReactDOM)}(window,function(t,e){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=3)}([function(t,e,o){t.exports=o(4)()},function(e,o){e.exports=t},function(t,o){t.exports=e},function(t,e,o){t.exports=o(8)},function(t,e,o){"use strict";var n=o(5),r=o(6),i=o(7);t.exports=function(){function t(t,e,o,n,a,s){s!==i&&r(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var o={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return o.checkPropTypes=n,o.PropTypes=o,o}},function(t,e,o){"use strict";function n(t){return function(){return t}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(t){return t},t.exports=r},function(t,e,o){"use strict";var n=function(t){};t.exports=function(t,e,o,r,i,a,s,u){if(n(e),!t){var c;if(void 0===e)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[o,r,i,a,s,u],f=0;(c=new Error(e.replace(/%s/g,function(){return l[f++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}}},function(t,e,o){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,o){"use strict";o.r(e);var n=o(1),r=o.n(n),i=o(0),a=o.n(i),s=o(2),u=o.n(s);function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function f(t,e){return!e||"object"!==c(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function p(t,e){return(p=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var d="function"==typeof u.a.createPortal,b="undefined"!=typeof window,m=function(t){function e(t){var o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),o=f(this,h(e).call(this,t)),b&&(o.container=document.createElement("div"),document.body.appendChild(o.container),o.renderLayer()),o}var o,n,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&p(t,e)}(e,r.a.Component),o=e,(n=[{key:"componentDidUpdate",value:function(){this.renderLayer()}},{key:"componentWillUnmount",value:function(){d||u.a.unmountComponentAtNode(this.container),document.body.removeChild(this.container)}},{key:"renderLayer",value:function(){d||u.a.unstable_renderSubtreeIntoContainer(this,this.props.children,this.container)}},{key:"render",value:function(){return d?u.a.createPortal(this.props.children,this.container):null}}])&&l(o.prototype,n),i&&l(o,i),e}();m.propTypes={children:a.a.node.isRequired};var v=m;function y(t,e,o,n){var r=e.getBoundingClientRect(),i=Math.min(r.left,document.documentElement.clientWidth-r.right);return t.offsetWidth+e.offsetWidth+o+n+i<document.documentElement.clientWidth}function g(t,e,o){var n=t.getBoundingClientRect(),r=n.bottom>window.innerHeight,i=n.top<0;if(i&&r)return!0;if(t.offsetHeight>e.offsetHeight){var a=t.offsetHeight/2,s=o.arrowSize+O,u=n.bottom-window.innerHeight,c=-n.top;return a-u>=s&&a-c>=s}return!r&&!i}function w(t,e,o){var n=k(),r=e.left-n>o,i=e.left+2*t.arrowSize<n+document.documentElement.clientWidth-o;return!r||!i}function T(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter(function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable}))),n.forEach(function(e){S(t,e,o[e])})}return t}function S(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var O=5,x=10,z=3;function E(){return window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0}function k(){return window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0}function R(){return"undefined"!=typeof document?document.documentElement.clientWidth-2*x:1e3}function H(t){var e=t.arrow?t.arrowSize:z;return"number"==typeof t.distance?t.distance:e}function j(t,e,o,n,r){if(!t||!r.arrow)return{top:"0",left:"-10000000px"};var i=t.getBoundingClientRect(),a=Math.round(t.offsetHeight/2),s=Math.round(t.offsetWidth/2),u=E(),c=k(),l=H(r),f={};switch(o){case"right":return f.borderTop="".concat(r.arrowSize,"px solid transparent"),f.borderBottom="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderRight="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderRightWidth="".concat(r.arrowSize,"px"),f.borderRightStyle="solid"),T({},f,{top:n.showTip&&e?i.top+u+a-r.arrowSize:"-10000000px",left:i.right+c+l-r.arrowSize});case"left":return f.borderTop="".concat(r.arrowSize,"px solid transparent"),f.borderBottom="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderLeft="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderLeftWidth="".concat(r.arrowSize,"px"),f.borderLeftStyle="solid"),T({},f,{top:n.showTip&&e?i.top+u+a-r.arrowSize:"-10000000px",left:i.left+c-l-1});case"up":return f.borderLeft="".concat(r.arrowSize,"px solid transparent"),f.borderRight="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderTop="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderTopWidth="".concat(r.arrowSize,"px"),f.borderTopStyle="solid"),T({},f,{left:n.showTip&&e?i.left+c+s-r.arrowSize:"-10000000px",top:i.top+u-l});case"down":default:return f.borderLeft="".concat(r.arrowSize,"px solid transparent"),f.borderRight="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderBottom="10px solid ".concat(r.background):(f.borderBottomWidth="".concat(r.arrowSize,"px"),f.borderBottomStyle="solid"),T({},f,{left:n.showTip&&e?i.left+c+s-r.arrowSize:"-10000000px",top:i.bottom+u+l-r.arrowSize})}}function P(t,e,o,n,r,i){var a=function(t){var e=t.split("-");return e.length>1?e[1]:"middle"}(t),s=t.split("-")[0],u=s;if(!e&&o){var c=i.arrow&&j(n,o,s,r,i);u=function t(e,o,n,r,i,a,s){if(!n)return e;var u=n.getBoundingClientRect(),c=H(r),l=o.offsetHeight+c+i,f=window.innerHeight-u.bottom>=l,h=u.top>=l;switch(e){case"right":return y(o,n,c,i)&&g(n,o,r)?document.documentElement.clientWidth-u.right<o.offsetWidth+c+i?"left":"right":t("up",o,n,c,i,a,!0);case"left":return y(o,n,c,i)&&g(n,o,r)?u.left<o.offsetWidth+c+i?"right":"left":t("up",o,n,c,i,a,!0);case"up":if(!s&&a&&w(r,a,i))return t("left",o,n,c,i,a,!0);if(!h){if(f)return"down";if(!s&&y(o,n,c,i))return t("right",o,n,c,i,a,!0)}return"up";case"down":default:if(!s&&a&&w(r,a,i))return t("right",o,n,c,i,a,!0);if(!f){if(h)return"up";if(!s&&y(o,n,c,i))return t("right",o,n,c,i,a,!0)}return"down"}}(s,o,n,i,x,c)}var l,f=R();if(o){var h=o.style.width?0:1;l=Math.min(o.offsetWidth,f)+h}return{tip:T({},"up"===u||"down"===u?function(t,e,o,n,r,i){var a,s=-1e7,u=o.showTip?void 0:"translateX(-10000000px)",c=H(i);if(t){var l=k(),f=e.getBoundingClientRect(),h=f.left+l,p=Math.round(e.offsetWidth/2),d=Math.min(R(),t.offsetWidth),b=h+p,m=b-i.arrowSize,v=b+i.arrowSize;if("start"===r)s=i.arrow?Math.min(m,h):h;else if("end"===r){var y=Math.max(v,h+e.offsetWidth),g=i.arrow?y:h+e.offsetWidth;s=Math.max(g-d,x+l)}else{var w=h+p-Math.round(d/2),T=x+l;s=Math.max(w,T)}var S=s+d-(l+document.documentElement.clientWidth-x);S>0&&(s-=S),a="up"===n?f.top+E()-(t.offsetHeight+c):f.bottom+E()+c}return{left:s,top:a,transform:u}}(o,n,r,u,a,i):function(t,e,o,n,r,i){var a=-1e7,s=0,u=o.showTip?void 0:"translateX(-10000000px)",c=H(i),l=i.arrow?O:0;if(t){var f=E(),h=k(),p=e.getBoundingClientRect(),d=p.top+f,b=Math.round(e.offsetHeight/2),m=d+b-i.arrowSize,v=p.top+f+b+i.arrowSize;if("start"===r)s=i.arrow?Math.min(d,m):d;else if("end"===r){var y=p.bottom+f-t.offsetHeight;s=i.arrow?Math.max(y,v-t.offsetHeight):y}else{var g=Math.max(d+b-Math.round(t.offsetHeight/2),x+f);s=Math.min(g,m-l)}var w=s-f+t.offsetHeight+x-window.innerHeight;w>0&&(s=Math.max(s-w,v+l-t.offsetHeight)),a="right"===n?p.right+c+h:p.left-c-t.offsetWidth+h}return{left:a,top:s,transform:u}}(o,n,r,u,a,i),{maxWidth:f,width:l}),arrow:j(n,o,u,r,i),realDirection:u}}function M(t){return(M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _(){return(_=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t}).apply(this,arguments)}function D(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter(function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable}))),n.forEach(function(e){I(t,e,o[e])})}return t}function W(t){return(W=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function C(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function L(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function B(t,e,o){return e&&L(t.prototype,e),o&&L(t,o),t}function N(t,e){return(N=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function I(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var q=function(t){return t.stopPropagation()},U=function(t){function e(){var t,o,n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),o=this,t=!(n=W(e).call(this))||"object"!==M(n)&&"function"!=typeof n?C(o):n,I(C(t),"debounceTimeout",!1),I(C(t),"hoverTimeout",!1),t.state={showTip:!1,hasHover:!1,ignoreShow:!1,hasBeenShown:!1},t.showTip=t.showTip.bind(C(t)),t.hideTip=t.hideTip.bind(C(t)),t.checkHover=t.checkHover.bind(C(t)),t.toggleTip=t.toggleTip.bind(C(t)),t.startHover=t.startHover.bind(C(t)),t.endHover=t.endHover.bind(C(t)),t.listenResizeScroll=t.listenResizeScroll.bind(C(t)),t.handleResizeScroll=t.handleResizeScroll.bind(C(t)),t.bodyTouchStart=t.bodyTouchStart.bind(C(t)),t.bodyTouchEnd=t.bodyTouchEnd.bind(C(t)),t.targetTouchStart=t.targetTouchStart.bind(C(t)),t.targetTouchEnd=t.targetTouchEnd.bind(C(t)),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&N(t,e)}(e,r.a.Component),B(e,null,[{key:"getDerivedStateFromProps",value:function(t){return b&&t.isOpen?{hasBeenShown:!0}:null}}]),B(e,[{key:"componentDidMount",value:function(){this.props.isOpen&&this.setState({isOpen:!0}),window.addEventListener("resize",this.listenResizeScroll),window.addEventListener("scroll",this.listenResizeScroll),window.addEventListener("touchstart",this.bodyTouchStart),window.addEventListener("touchEnd",this.bodyTouchEnd)}},{key:"componentDidUpdate",value:function(t,e){if(!this.state.hasBeenShown&&this.props.isOpen)return this.setState({hasBeenShown:!0}),setTimeout(this.showTip,0);!e.hasBeenShown&&this.state.hasBeenShown&&this.showTip()}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.listenResizeScroll),window.removeEventListener("scroll",this.listenResizeScroll),window.removeEventListener("touchstart",this.bodyTouchStart),window.removeEventListener("touchEnd",this.bodyTouchEnd),clearTimeout(this.debounceTimeout),clearTimeout(this.hoverTimeout)}},{key:"listenResizeScroll",value:function(){clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(this.handleResizeScroll,100),this.state.targetTouch&&this.setState({targetTouch:void 0})}},{key:"handleResizeScroll",value:function(){if(this.state.showTip){var t=5*Math.round(document.documentElement.clientWidth/5);this.setState({clientWidth:t})}}},{key:"targetTouchStart",value:function(){this.setState({targetTouch:!0})}},{key:"targetTouchEnd",value:function(){this.state.targetTouch&&this.toggleTip()}},{key:"bodyTouchEnd",value:function(){this.state.targetTouch&&this.setState({targetTouch:void 0})}},{key:"bodyTouchStart",value:function(t){this.target&&this.target.contains(t.target)||this.tip&&this.tip.contains(t.target)||this.props.isOpen||this.hideTip()}},{key:"toggleTip",value:function(){this.state.showTip?this.hideTip():this.showTip()}},{key:"showTip",value:function(){var t=this;if(!this.state.hasBeenShown)return this.setState({hasBeenShown:!0});this.setState({showTip:!0},function(){"function"==typeof t.props.onToggle&&t.props.onToggle(t.state.showTip)})}},{key:"hideTip",value:function(){var t=this;this.setState({hasHover:!1}),this.setState({showTip:!1},function(){"function"==typeof t.props.onToggle&&t.props.onToggle(t.state.showTip)})}},{key:"startHover",value:function(){this.state.ignoreShow||(this.setState({hasHover:!0}),clearTimeout(this.hoverTimeout),this.hoverTimeout=setTimeout(this.checkHover,this.props.hoverDelay))}},{key:"endHover",value:function(){this.setState({hasHover:!1}),clearTimeout(this.hoverTimeout),this.hoverTimeout=setTimeout(this.checkHover,this.props.mouseOutDelay||this.props.hoverDelay)}},{key:"checkHover",value:function(){this.state.hasHover?this.showTip():this.hideTip()}},{key:"render",value:function(){var t,e=this,o=this.props,n=o.arrow,i=o.arrowSize,a=o.background,s=o.className,u=o.children,c=o.color,l=o.content,f=o.direction,h=o.distance,p=o.eventOff,d=o.eventOn,b=o.eventToggle,m=o.forceDirection,y=o.isOpen,g=o.mouseOutDelay,w=o.padding,T=o.styles,S=o.tagName,O=o.tipContentHover,x=o.tipContentClassName,z=o.useDefaultStyles,E=o.useHover,k=null!=y,R=k?y:this.state.showTip,H={style:D({position:"relative"},T),ref:function(t){e.target=t},className:s},j={onClick:q};if(p&&(H[p]=this.hideTip),d&&(H[d]=this.showTip),b?H[b]=this.toggleTip:E&&!k&&(H.onMouseEnter=this.startHover,H.onMouseLeave=O||g?this.endHover:this.hideTip,H.onTouchStart=this.targetTouchStart,H.onTouchEnd=this.targetTouchEnd,O&&(j.onMouseEnter=this.startHover,j.onMouseLeave=this.endHover,j.onTouchStart=q)),this.state.hasBeenShown){var M=P(f,m,this.tip,this.target,D({},this.state,{showTip:R}),{background:z?"#333":a,arrow:n,arrowSize:i,distance:h}),W=D({},M.tip,{background:z?"#333":a,color:z?"#fff":c,padding:w,boxSizing:"border-box",zIndex:this.props.zIndex,position:"absolute",display:"inline-block"}),C=D({},M.arrow,{position:"absolute",width:"0px",height:"0px",zIndex:this.props.zIndex+1});t=r.a.createElement(v,null,r.a.createElement("div",_({},j,{className:void 0!==x?x:s}),r.a.createElement("span",{className:"react-tooltip-lite",style:W,ref:function(t){e.tip=t}},l),r.a.createElement("span",{className:"react-tooltip-lite-arrow react-tooltip-lite-".concat(M.realDirection,"-arrow"),style:C})))}return r.a.createElement(S,H,u,t)}}]),e}();I(U,"propTypes",{arrow:a.a.bool,arrowSize:a.a.number,background:a.a.string,children:a.a.node.isRequired,className:a.a.string,color:a.a.string,content:a.a.node.isRequired,direction:a.a.string,distance:a.a.number,eventOff:a.a.string,eventOn:a.a.string,eventToggle:a.a.string,forceDirection:a.a.bool,hoverDelay:a.a.number,isOpen:a.a.bool,mouseOutDelay:a.a.number,padding:a.a.string,styles:a.a.object,tagName:a.a.string,tipContentHover:a.a.bool,tipContentClassName:a.a.string,useDefaultStyles:a.a.bool,useHover:a.a.bool,zIndex:a.a.number,onToggle:a.a.func}),I(U,"defaultProps",{arrow:!0,arrowSize:10,background:"",className:"",color:"",direction:"up",distance:void 0,eventOff:void 0,eventOn:void 0,eventToggle:void 0,forceDirection:!1,hoverDelay:200,isOpen:void 0,mouseOutDelay:void 0,padding:"10px",styles:{},tagName:"div",tipContentHover:!1,tipContentClassName:void 0,useDefaultStyles:!1,useHover:!0,zIndex:1e3,onToggle:void 0});e.default=U}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","ReactDOM"],e):"object"==typeof exports?exports.ReactToolTipLite=e(require("React"),require("ReactDOM")):t.ReactToolTipLite=e(t.React,t.ReactDOM)}(window,function(t,e){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=3)}([function(t,e,o){t.exports=o(4)()},function(e,o){e.exports=t},function(t,o){t.exports=e},function(t,e,o){t.exports=o(8)},function(t,e,o){"use strict";var n=o(5),r=o(6),i=o(7);t.exports=function(){function t(t,e,o,n,a,s){s!==i&&r(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var o={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return o.checkPropTypes=n,o.PropTypes=o,o}},function(t,e,o){"use strict";function n(t){return function(){return t}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(t){return t},t.exports=r},function(t,e,o){"use strict";var n=function(t){};t.exports=function(t,e,o,r,i,a,s,u){if(n(e),!t){var c;if(void 0===e)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[o,r,i,a,s,u],f=0;(c=new Error(e.replace(/%s/g,function(){return l[f++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}}},function(t,e,o){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,o){"use strict";o.r(e);var n=o(1),r=o.n(n),i=o(0),a=o.n(i),s=o(2),u=o.n(s);function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function f(t,e){return!e||"object"!==c(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function p(t,e){return(p=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var d="function"==typeof u.a.createPortal,b="undefined"!=typeof window,m=function(t){function e(t){var o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),o=f(this,h(e).call(this,t)),b&&(o.container=document.createElement("div"),document.body.appendChild(o.container),o.renderLayer()),o}var o,n,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&p(t,e)}(e,r.a.Component),o=e,(n=[{key:"componentDidUpdate",value:function(){this.renderLayer()}},{key:"componentWillUnmount",value:function(){d||u.a.unmountComponentAtNode(this.container),document.body.removeChild(this.container)}},{key:"renderLayer",value:function(){d||u.a.unstable_renderSubtreeIntoContainer(this,this.props.children,this.container)}},{key:"render",value:function(){return d?u.a.createPortal(this.props.children,this.container):null}}])&&l(o.prototype,n),i&&l(o,i),e}();m.propTypes={children:a.a.node.isRequired};var v=m,y=5,g=10,w=3;function T(){return window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0}function S(){return window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0}function O(t){var e=t.arrow?t.arrowSize:w;return"number"==typeof t.distance?t.distance:e}function x(t,e,o,n){var r=e.getBoundingClientRect(),i=Math.min(r.left,document.documentElement.clientWidth-r.right);return t.offsetWidth+e.offsetWidth+o+n+i<document.documentElement.clientWidth}function E(t,e,o){var n=t.getBoundingClientRect(),r=n.bottom>window.innerHeight,i=n.top<0;if(i&&r)return!0;if(t.offsetHeight>e.offsetHeight){var a=t.offsetHeight/2,s=o.arrowSize+y,u=n.bottom-window.innerHeight,c=-n.top;return a-u>=s&&a-c>=s}return!r&&!i}function z(t,e,o){var n=S(),r=e.left-n>o,i=e.left+2*t.arrowSize<n+document.documentElement.clientWidth-o;return!r||!i}function k(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter(function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable}))),n.forEach(function(e){R(t,e,o[e])})}return t}function R(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function H(){return"undefined"!=typeof document?document.documentElement.clientWidth-2*g:1e3}function j(t,e,o,n,r){if(!t||!r.arrow)return{top:"0",left:"-10000000px"};var i=t.getBoundingClientRect(),a=Math.round(t.offsetHeight/2),s=Math.round(t.offsetWidth/2),u=T(),c=S(),l=O(r),f={};switch(o){case"right":return f.borderTop="".concat(r.arrowSize,"px solid transparent"),f.borderBottom="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderRight="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderRightWidth="".concat(r.arrowSize,"px"),f.borderRightStyle="solid"),k({},f,{top:n.showTip&&e?i.top+u+a-r.arrowSize:"-10000000px",left:i.right+c+l-r.arrowSize});case"left":return f.borderTop="".concat(r.arrowSize,"px solid transparent"),f.borderBottom="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderLeft="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderLeftWidth="".concat(r.arrowSize,"px"),f.borderLeftStyle="solid"),k({},f,{top:n.showTip&&e?i.top+u+a-r.arrowSize:"-10000000px",left:i.left+c-l-1});case"up":return f.borderLeft="".concat(r.arrowSize,"px solid transparent"),f.borderRight="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderTop="".concat(r.arrowSize,"px solid ").concat(r.background):(f.borderTopWidth="".concat(r.arrowSize,"px"),f.borderTopStyle="solid"),k({},f,{left:n.showTip&&e?i.left+c+s-r.arrowSize:"-10000000px",top:i.top+u-l});case"down":default:return f.borderLeft="".concat(r.arrowSize,"px solid transparent"),f.borderRight="".concat(r.arrowSize,"px solid transparent"),r.background?f.borderBottom="10px solid ".concat(r.background):(f.borderBottomWidth="".concat(r.arrowSize,"px"),f.borderBottomStyle="solid"),k({},f,{left:n.showTip&&e?i.left+c+s-r.arrowSize:"-10000000px",top:i.bottom+u+l-r.arrowSize})}}function P(t,e,o,n,r,i){var a=function(t){var e=t.split("-");return e.length>1?e[1]:"middle"}(t),s=t.split("-")[0],u=s;if(!e&&o){var c=i.arrow&&j(n,o,s,r,i);u=function t(e,o,n,r,i,a,s){if(!n)return e;var u=n.getBoundingClientRect(),c=O(r),l=o.offsetHeight+c+i,f=window.innerHeight-u.bottom>=l,h=u.top>=l;switch(e){case"right":return x(o,n,c,i)&&E(n,o,r)?document.documentElement.clientWidth-u.right<o.offsetWidth+c+i?"left":"right":t("up",o,n,c,i,a,!0);case"left":return x(o,n,c,i)&&E(n,o,r)?u.left<o.offsetWidth+c+i?"right":"left":t("up",o,n,c,i,a,!0);case"up":if(!s&&a&&z(r,a,i))return t("left",o,n,c,i,a,!0);if(!h){if(f)return"down";if(!s&&x(o,n,c,i))return t("right",o,n,c,i,a,!0)}return"up";case"down":default:if(!s&&a&&z(r,a,i))return t("right",o,n,c,i,a,!0);if(!f){if(h)return"up";if(!s&&x(o,n,c,i))return t("right",o,n,c,i,a,!0)}return"down"}}(s,o,n,i,g,c)}var l,f=H();if(o){var h=o.style.width?0:1;l=Math.min(o.offsetWidth,f)+h}return{tip:k({},"up"===u||"down"===u?function(t,e,o,n,r,i){var a,s=-1e7,u=o.showTip?void 0:"translateX(-10000000px)",c=O(i);if(t){var l=S(),f=e.getBoundingClientRect(),h=f.left+l,p=Math.round(e.offsetWidth/2),d=Math.min(H(),t.offsetWidth),b=h+p,m=b-i.arrowSize,v=b+i.arrowSize;if("start"===r)s=i.arrow?Math.min(m,h):h;else if("end"===r){var y=Math.max(v,h+e.offsetWidth),w=i.arrow?y:h+e.offsetWidth;s=Math.max(w-d,g+l)}else{var x=h+p-Math.round(d/2),E=g+l;s=Math.max(x,E)}var z=s+d-(l+document.documentElement.clientWidth-g);z>0&&(s-=z),a="up"===n?f.top+T()-(t.offsetHeight+c):f.bottom+T()+c}return{left:s,top:a,transform:u}}(o,n,r,u,a,i):function(t,e,o,n,r,i){var a=-1e7,s=0,u=o.showTip?void 0:"translateX(-10000000px)",c=O(i),l=i.arrow?y:0;if(t){var f=T(),h=S(),p=e.getBoundingClientRect(),d=p.top+f,b=Math.round(e.offsetHeight/2),m=d+b-i.arrowSize,v=p.top+f+b+i.arrowSize;if("start"===r)s=i.arrow?Math.min(d,m):d;else if("end"===r){var w=p.bottom+f-t.offsetHeight;s=i.arrow?Math.max(w,v-t.offsetHeight):w}else{var x=Math.max(d+b-Math.round(t.offsetHeight/2),g+f);s=Math.min(x,m-l)}var E=s-f+t.offsetHeight+g-window.innerHeight;E>0&&(s=Math.max(s-E,v+l-t.offsetHeight)),a="right"===n?p.right+c+h:p.left-c-t.offsetWidth+h}return{left:a,top:s,transform:u}}(o,n,r,u,a,i),{maxWidth:f,width:l}),arrow:j(n,o,u,r,i),realDirection:u}}function M(t){return(M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _(){return(_=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t}).apply(this,arguments)}function C(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter(function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable}))),n.forEach(function(e){I(t,e,o[e])})}return t}function D(t){return(D=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function W(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function L(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function B(t,e,o){return e&&L(t.prototype,e),o&&L(t,o),t}function N(t,e){return(N=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function I(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var q=function(t){return t.stopPropagation()},U=function(t){function e(){var t,o,n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),o=this,t=!(n=D(e).call(this))||"object"!==M(n)&&"function"!=typeof n?W(o):n,I(W(t),"debounceTimeout",!1),I(W(t),"hoverTimeout",!1),t.state={showTip:!1,hasHover:!1,ignoreShow:!1,hasBeenShown:!1},t.showTip=t.showTip.bind(W(t)),t.hideTip=t.hideTip.bind(W(t)),t.checkHover=t.checkHover.bind(W(t)),t.toggleTip=t.toggleTip.bind(W(t)),t.startHover=t.startHover.bind(W(t)),t.endHover=t.endHover.bind(W(t)),t.listenResizeScroll=t.listenResizeScroll.bind(W(t)),t.handleResizeScroll=t.handleResizeScroll.bind(W(t)),t.bodyTouchStart=t.bodyTouchStart.bind(W(t)),t.bodyTouchEnd=t.bodyTouchEnd.bind(W(t)),t.targetTouchStart=t.targetTouchStart.bind(W(t)),t.targetTouchEnd=t.targetTouchEnd.bind(W(t)),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&N(t,e)}(e,r.a.Component),B(e,null,[{key:"getDerivedStateFromProps",value:function(t){return b&&t.isOpen?{hasBeenShown:!0}:null}}]),B(e,[{key:"componentDidMount",value:function(){this.props.isOpen&&this.setState({isOpen:!0}),this.scrollParent=function(t){var e=getComputedStyle(t),o=window;if("fixed"!==e.position)for(var n=t.parentElement;n;){var r=getComputedStyle(n);/(auto|scroll)/.test(r.overflow+r.overflowY+r.overflowX)?(o=n,n=void 0):n=n.parentElement}return o}(this.target),window.addEventListener("resize",this.listenResizeScroll),this.scrollParent.addEventListener("scroll",this.listenResizeScroll),window.addEventListener("touchstart",this.bodyTouchStart),window.addEventListener("touchEnd",this.bodyTouchEnd)}},{key:"componentDidUpdate",value:function(t,e){if(!this.state.hasBeenShown&&this.props.isOpen)return this.setState({hasBeenShown:!0}),setTimeout(this.showTip,0);!e.hasBeenShown&&this.state.hasBeenShown&&this.showTip()}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.listenResizeScroll),this.scrollParent.removeEventListener("scroll",this.listenResizeScroll),window.removeEventListener("touchstart",this.bodyTouchStart),window.removeEventListener("touchEnd",this.bodyTouchEnd),clearTimeout(this.debounceTimeout),clearTimeout(this.hoverTimeout)}},{key:"listenResizeScroll",value:function(){clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(this.handleResizeScroll,100),this.state.targetTouch&&this.setState({targetTouch:void 0})}},{key:"handleResizeScroll",value:function(){if(this.state.showTip){var t=5*Math.round(document.documentElement.clientWidth/5);this.setState({clientWidth:t})}}},{key:"targetTouchStart",value:function(){this.setState({targetTouch:!0})}},{key:"targetTouchEnd",value:function(){this.state.targetTouch&&this.toggleTip()}},{key:"bodyTouchEnd",value:function(){this.state.targetTouch&&this.setState({targetTouch:void 0})}},{key:"bodyTouchStart",value:function(t){this.target&&this.target.contains(t.target)||this.tip&&this.tip.contains(t.target)||this.props.isOpen||this.hideTip()}},{key:"toggleTip",value:function(){this.state.showTip?this.hideTip():this.showTip()}},{key:"showTip",value:function(){var t=this;if(!this.state.hasBeenShown)return this.setState({hasBeenShown:!0});this.setState({showTip:!0},function(){"function"==typeof t.props.onToggle&&t.props.onToggle(t.state.showTip)})}},{key:"hideTip",value:function(){var t=this;this.setState({hasHover:!1}),this.setState({showTip:!1},function(){"function"==typeof t.props.onToggle&&t.props.onToggle(t.state.showTip)})}},{key:"startHover",value:function(){this.state.ignoreShow||(this.setState({hasHover:!0}),clearTimeout(this.hoverTimeout),this.hoverTimeout=setTimeout(this.checkHover,this.props.hoverDelay))}},{key:"endHover",value:function(){this.setState({hasHover:!1}),clearTimeout(this.hoverTimeout),this.hoverTimeout=setTimeout(this.checkHover,this.props.mouseOutDelay||this.props.hoverDelay)}},{key:"checkHover",value:function(){this.state.hasHover?this.showTip():this.hideTip()}},{key:"render",value:function(){var t,e=this,o=this.props,n=o.arrow,i=o.arrowSize,a=o.background,s=o.className,u=o.children,c=o.color,l=o.content,f=o.direction,h=o.distance,p=o.eventOff,d=o.eventOn,b=o.eventToggle,m=o.forceDirection,y=o.isOpen,g=o.mouseOutDelay,w=o.padding,T=o.styles,S=o.tagName,O=o.tipContentHover,x=o.tipContentClassName,E=o.useDefaultStyles,z=o.useHover,k=null!=y,R=k?y:this.state.showTip,H={style:C({position:"relative"},T),ref:function(t){e.target=t},className:s},j={onClick:q};if(p&&(H[p]=this.hideTip),d&&(H[d]=this.showTip),b?H[b]=this.toggleTip:z&&!k&&(H.onMouseEnter=this.startHover,H.onMouseLeave=O||g?this.endHover:this.hideTip,H.onTouchStart=this.targetTouchStart,H.onTouchEnd=this.targetTouchEnd,O&&(j.onMouseEnter=this.startHover,j.onMouseLeave=this.endHover,j.onTouchStart=q)),this.state.hasBeenShown){var M=P(f,m,this.tip,this.target,C({},this.state,{showTip:R}),{background:E?"#333":a,arrow:n,arrowSize:i,distance:h}),D=C({},M.tip,{background:E?"#333":a,color:E?"#fff":c,padding:w,boxSizing:"border-box",zIndex:this.props.zIndex,position:"absolute",display:"inline-block"}),W=C({},M.arrow,{position:"absolute",width:"0px",height:"0px",zIndex:this.props.zIndex+1});t=r.a.createElement(v,null,r.a.createElement("div",_({},j,{className:void 0!==x?x:s}),r.a.createElement("span",{className:"react-tooltip-lite",style:D,ref:function(t){e.tip=t}},l),r.a.createElement("span",{className:"react-tooltip-lite-arrow react-tooltip-lite-".concat(M.realDirection,"-arrow"),style:W})))}return r.a.createElement(S,H,u,t)}}]),e}();I(U,"propTypes",{arrow:a.a.bool,arrowSize:a.a.number,background:a.a.string,children:a.a.node.isRequired,className:a.a.string,color:a.a.string,content:a.a.node.isRequired,direction:a.a.string,distance:a.a.number,eventOff:a.a.string,eventOn:a.a.string,eventToggle:a.a.string,forceDirection:a.a.bool,hoverDelay:a.a.number,isOpen:a.a.bool,mouseOutDelay:a.a.number,padding:a.a.oneOfType([a.a.string,a.a.number]),styles:a.a.object,tagName:a.a.string,tipContentHover:a.a.bool,tipContentClassName:a.a.string,useDefaultStyles:a.a.bool,useHover:a.a.bool,zIndex:a.a.number,onToggle:a.a.func}),I(U,"defaultProps",{arrow:!0,arrowSize:10,background:"",className:"",color:"",direction:"up",distance:void 0,eventOff:void 0,eventOn:void 0,eventToggle:void 0,forceDirection:!1,hoverDelay:200,isOpen:void 0,mouseOutDelay:void 0,padding:"10px",styles:{},tagName:"div",tipContentHover:!1,tipContentClassName:void 0,useDefaultStyles:!1,useHover:!0,zIndex:1e3,onToggle:void 0});e.default=U}])}); |
@@ -206,4 +206,39 @@ "use strict"; | ||
}); | ||
it('should support onToggle prop'); | ||
it('should support zIndex prop'); | ||
it('should support onToggle prop', function () { | ||
var spy = jest.fn(); | ||
var _render9 = (0, _reactTestingLibrary.render)(_react["default"].createElement(_index["default"], { | ||
content: tipContent, | ||
onToggle: spy | ||
}, targetContent)), | ||
getByText = _render9.getByText; | ||
var target = getByText(targetContent); | ||
_reactTestingLibrary.fireEvent.mouseOver(target); | ||
jest.runAllTimers(); | ||
expect(spy).toHaveBeenCalledWith(true); | ||
_reactTestingLibrary.fireEvent.mouseOut(target); | ||
jest.runAllTimers(); | ||
expect(spy).toHaveBeenCalledWith(false); | ||
}); | ||
it('should support zIndex prop', function () { | ||
var _render10 = (0, _reactTestingLibrary.render)(_react["default"].createElement(_index["default"], { | ||
content: tipContent, | ||
zIndex: 5000 | ||
}, targetContent)), | ||
getByText = _render10.getByText; | ||
var target = getByText(targetContent); | ||
_reactTestingLibrary.fireEvent.mouseOver(target); | ||
jest.runAllTimers(); | ||
var tip = getByText(tipContent); | ||
var styles = window.getComputedStyle(tip); | ||
expect(styles['z-index']).toEqual('5000'); | ||
}); | ||
}); |
@@ -50,3 +50,3 @@ import React from 'react'; | ||
<div className="flex-spread"> | ||
<Tooltip content="By default the text is above the element" className="target" tipContentClassName="foo"> | ||
<Tooltip padding={20} content="By default the text is above the element" className="target" tipContentClassName="foo"> | ||
Target | ||
@@ -63,3 +63,3 @@ </Tooltip> | ||
<Tooltip onToggle={(isOpen) => { alert(`Is tooltip open ? \n Answer : ${isOpen ? 'Yes' : 'No'}`); }} content="alert shown" className="target" tipContentClassName=""> | ||
<Tooltip onToggle={(isOpen) => { console.log(`Is tooltip open ? \n Answer : ${isOpen ? 'Yes' : 'No'}`); }} content="alert shown" className="target" tipContentClassName=""> | ||
Hover Me | ||
@@ -363,2 +363,12 @@ </Tooltip> | ||
</section> | ||
<section> | ||
<h3>Internal scrollbars</h3> | ||
<div className="internal-scroll-container"> | ||
<div> | ||
<Tooltip content="hello" tagName="span"> | ||
Scroll on mobile tapping here | ||
</Tooltip> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
@@ -365,0 +375,0 @@ ); |
{ | ||
"name": "react-tooltip-lite", | ||
"version": "1.11.1", | ||
"version": "1.11.2", | ||
"description": "React tooltip, focused on simplicity and performance", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1850228
22
22033