Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-popper-tooltip

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-popper-tooltip - npm Package Compare versions

Comparing version 2.11.0 to 2.11.1

494

dist/cjs/react-popper-tooltip.js

@@ -5,2 +5,5 @@ 'use strict';

var _extends = require('@babel/runtime/helpers/extends');
require('@babel/runtime/helpers/possibleConstructorReturn');
require('@babel/runtime/helpers/getPrototypeOf');
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
var React = require('react');

@@ -10,10 +13,26 @@ var reactDom = require('react-dom');

const TooltipContext = React.createContext({}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
var TooltipContext = React.createContext({}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args));
const noop = () => {// do nothing
var callAll = function callAll() {
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
fns[_key] = arguments[_key];
}
return function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return fns.forEach(function (fn) {
return fn && fn.apply(void 0, args);
});
};
};
const canUseDOM = () => !!(typeof window !== 'undefined' && window.document && window.document.createElement);
const setRef = (ref, node) => {
var noop = function noop() {// do nothing
};
var canUseDOM = function canUseDOM() {
return !!(typeof window !== 'undefined' && window.document && window.document.createElement);
};
var setRef = function setRef(ref, node) {
if (typeof ref === 'function') {

@@ -26,14 +45,22 @@ return ref(node);

class Tooltip extends React.Component {
constructor(...args) {
super(...args);
this.observer = void 0;
this.tooltipRef = void 0;
var Tooltip = /*#__PURE__*/function (_Component) {
_inheritsLoose(Tooltip, _Component);
this.handleOutsideClick = event => {
if (this.tooltipRef && !this.tooltipRef.contains(event.target)) {
const parentOutsideClickHandler = this.context.parentOutsideClickHandler;
const _this$props = this.props,
hideTooltip = _this$props.hideTooltip,
clearScheduled = _this$props.clearScheduled;
function Tooltip() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.observer = void 0;
_this.tooltipRef = void 0;
_this.handleOutsideClick = function (event) {
if (_this.tooltipRef && !_this.tooltipRef.contains(event.target)) {
var parentOutsideClickHandler = _this.context.parentOutsideClickHandler;
var _this$props = _this.props,
hideTooltip = _this$props.hideTooltip,
clearScheduled = _this$props.clearScheduled;
clearScheduled();

@@ -48,8 +75,8 @@ hideTooltip();

this.handleOutsideRightClick = event => {
if (this.tooltipRef && !this.tooltipRef.contains(event.target)) {
const parentOutsideRightClickHandler = this.context.parentOutsideRightClickHandler;
const _this$props2 = this.props,
hideTooltip = _this$props2.hideTooltip,
clearScheduled = _this$props2.clearScheduled;
_this.handleOutsideRightClick = function (event) {
if (_this.tooltipRef && !_this.tooltipRef.contains(event.target)) {
var parentOutsideRightClickHandler = _this.context.parentOutsideRightClickHandler;
var _this$props2 = _this.props,
hideTooltip = _this$props2.hideTooltip,
clearScheduled = _this$props2.clearScheduled;
clearScheduled();

@@ -64,46 +91,67 @@ hideTooltip();

this.addOutsideClickHandler = () => {
document.body.addEventListener('touchend', this.handleOutsideClick);
document.body.addEventListener('click', this.handleOutsideClick);
_this.addOutsideClickHandler = function () {
document.body.addEventListener('touchend', _this.handleOutsideClick);
document.body.addEventListener('click', _this.handleOutsideClick);
};
this.removeOutsideClickHandler = () => {
document.body.removeEventListener('touchend', this.handleOutsideClick);
document.body.removeEventListener('click', this.handleOutsideClick);
_this.removeOutsideClickHandler = function () {
document.body.removeEventListener('touchend', _this.handleOutsideClick);
document.body.removeEventListener('click', _this.handleOutsideClick);
};
this.addOutsideRightClickHandler = () => document.body.addEventListener('contextmenu', this.handleOutsideRightClick);
_this.addOutsideRightClickHandler = function () {
return document.body.addEventListener('contextmenu', _this.handleOutsideRightClick);
};
this.removeOutsideRightClickHandler = () => document.body.removeEventListener('contextmenu', this.handleOutsideRightClick);
_this.removeOutsideRightClickHandler = function () {
return document.body.removeEventListener('contextmenu', _this.handleOutsideRightClick);
};
this.getTooltipRef = node => {
this.tooltipRef = node;
setRef(this.props.innerRef, node);
_this.getTooltipRef = function (node) {
_this.tooltipRef = node;
setRef(_this.props.innerRef, node);
};
this.getArrowProps = (props = {}) => _extends({}, props, {
style: _extends({}, props.style, {}, this.props.arrowProps.style)
});
_this.getArrowProps = function (props) {
if (props === void 0) {
props = {};
}
this.getTooltipProps = (props = {}) => _extends({}, props, {}, this.isTriggeredBy('hover') && {
onMouseEnter: callAll(this.props.clearScheduled, props.onMouseEnter),
onMouseLeave: callAll(this.props.hideTooltip, props.onMouseLeave)
}, {
style: _extends({}, props.style, {}, this.props.style)
});
return _extends({}, props, {
style: _extends({}, props.style, {}, _this.props.arrowProps.style)
});
};
this.contextValue = {
isParentNoneTriggered: this.props.trigger === 'none',
addParentOutsideClickHandler: this.addOutsideClickHandler,
addParentOutsideRightClickHandler: this.addOutsideRightClickHandler,
parentOutsideClickHandler: this.handleOutsideClick,
parentOutsideRightClickHandler: this.handleOutsideRightClick,
removeParentOutsideClickHandler: this.removeOutsideClickHandler,
removeParentOutsideRightClickHandler: this.removeOutsideRightClickHandler
_this.getTooltipProps = function (props) {
if (props === void 0) {
props = {};
}
return _extends({}, props, {}, _this.isTriggeredBy('hover') && {
onMouseEnter: callAll(_this.props.clearScheduled, props.onMouseEnter),
onMouseLeave: callAll(_this.props.hideTooltip, props.onMouseLeave)
}, {
style: _extends({}, props.style, {}, _this.props.style)
});
};
_this.contextValue = {
isParentNoneTriggered: _this.props.trigger === 'none',
addParentOutsideClickHandler: _this.addOutsideClickHandler,
addParentOutsideRightClickHandler: _this.addOutsideRightClickHandler,
parentOutsideClickHandler: _this.handleOutsideClick,
parentOutsideRightClickHandler: _this.handleOutsideRightClick,
removeParentOutsideClickHandler: _this.removeOutsideClickHandler,
removeParentOutsideRightClickHandler: _this.removeOutsideRightClickHandler
};
return _this;
}
componentDidMount() {
const observer = this.observer = new MutationObserver(() => {
this.props.scheduleUpdate();
var _proto = Tooltip.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var observer = this.observer = new MutationObserver(function () {
_this2.props.scheduleUpdate();
});

@@ -113,5 +161,5 @@ observer.observe(this.tooltipRef, this.props.mutationObserverOptions);

if (this.isTriggeredBy('hover') || this.isTriggeredBy('click') || this.isTriggeredBy('right-click')) {
const _this$context = this.context,
removeParentOutsideClickHandler = _this$context.removeParentOutsideClickHandler,
removeParentOutsideRightClickHandler = _this$context.removeParentOutsideRightClickHandler;
var _this$context = this.context,
removeParentOutsideClickHandler = _this$context.removeParentOutsideClickHandler,
removeParentOutsideRightClickHandler = _this$context.removeParentOutsideRightClickHandler;
this.addOutsideClickHandler();

@@ -128,11 +176,11 @@ this.addOutsideRightClickHandler();

}
}
};
componentDidUpdate() {
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.props.closeOnOutOfBoundaries && this.props.outOfBoundaries) {
this.props.hideTooltip();
}
}
};
componentWillUnmount() {
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.observer) {

@@ -143,6 +191,6 @@ this.observer.disconnect();

if (this.isTriggeredBy('hover') || this.isTriggeredBy('click') || this.isTriggeredBy('right-click')) {
const _this$context2 = this.context,
isParentNoneTriggered = _this$context2.isParentNoneTriggered,
addParentOutsideClickHandler = _this$context2.addParentOutsideClickHandler,
addParentOutsideRightClickHandler = _this$context2.addParentOutsideRightClickHandler;
var _this$context2 = this.context,
isParentNoneTriggered = _this$context2.isParentNoneTriggered,
addParentOutsideClickHandler = _this$context2.addParentOutsideClickHandler,
addParentOutsideRightClickHandler = _this$context2.addParentOutsideRightClickHandler;
this.removeOutsideClickHandler();

@@ -161,9 +209,9 @@ this.removeOutsideRightClickHandler();

}
}
};
render() {
const _this$props3 = this.props,
arrowProps = _this$props3.arrowProps,
placement = _this$props3.placement,
tooltip = _this$props3.tooltip;
_proto.render = function render() {
var _this$props3 = this.props,
arrowProps = _this$props3.arrowProps,
placement = _this$props3.placement,
tooltip = _this$props3.tooltip;
return /*#__PURE__*/React.createElement(TooltipContext.Provider, {

@@ -175,17 +223,18 @@ value: this.contextValue

getTooltipProps: this.getTooltipProps,
placement,
placement: placement,
tooltipRef: this.getTooltipRef
}));
}
};
isTriggeredBy(event) {
const trigger = this.props.trigger;
_proto.isTriggeredBy = function isTriggeredBy(event) {
var trigger = this.props.trigger;
return trigger === event || Array.isArray(trigger) && trigger.includes(event);
}
};
}
return Tooltip;
}(React.Component);
Tooltip.contextType = TooltipContext;
const DEFAULT_MODIFIERS = {
var DEFAULT_MODIFIERS = {
preventOverflow: {

@@ -195,3 +244,3 @@ boundariesElement: 'viewport'

};
const DEFAULT_MUTATION_OBSERVER_CONFIG = {
var DEFAULT_MUTATION_OBSERVER_CONFIG = {
childList: true,

@@ -201,121 +250,149 @@ subtree: true

class TooltipTrigger extends React.Component {
constructor(...args) {
super(...args);
this.state = {
tooltipShown: this.props.defaultTooltipShown
var TooltipTrigger = /*#__PURE__*/function (_Component) {
_inheritsLoose(TooltipTrigger, _Component);
function TooltipTrigger() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.state = {
tooltipShown: _this.props.defaultTooltipShown
};
this.hideTimeout = void 0;
this.showTimeout = void 0;
this.popperOffset = void 0;
_this.hideTimeout = void 0;
_this.showTimeout = void 0;
_this.popperOffset = void 0;
this.setTooltipState = state => {
const cb = () => this.props.onVisibilityChange(state.tooltipShown);
_this.setTooltipState = function (state) {
var cb = function cb() {
return _this.props.onVisibilityChange(state.tooltipShown);
};
this.isControlled() ? cb() : this.setState(state, cb);
_this.isControlled() ? cb() : _this.setState(state, cb);
};
this.clearScheduled = () => {
clearTimeout(this.hideTimeout);
clearTimeout(this.showTimeout);
_this.clearScheduled = function () {
clearTimeout(_this.hideTimeout);
clearTimeout(_this.showTimeout);
};
this.showTooltip = ({
pageX,
pageY
}) => {
this.clearScheduled();
let state = {
_this.showTooltip = function (_ref) {
var pageX = _ref.pageX,
pageY = _ref.pageY;
_this.clearScheduled();
var state = {
tooltipShown: true
};
if (this.props.followCursor) {
if (_this.props.followCursor) {
state = _extends({}, state, {
pageX,
pageY
pageX: pageX,
pageY: pageY
});
}
this.showTimeout = window.setTimeout(() => this.setTooltipState(state), this.props.delayShow);
_this.showTimeout = window.setTimeout(function () {
return _this.setTooltipState(state);
}, _this.props.delayShow);
};
this.hideTooltip = () => {
this.clearScheduled();
this.hideTimeout = window.setTimeout(() => this.setTooltipState({
tooltipShown: false
}), this.props.delayHide);
_this.hideTooltip = function () {
_this.clearScheduled();
_this.hideTimeout = window.setTimeout(function () {
return _this.setTooltipState({
tooltipShown: false
});
}, _this.props.delayHide);
};
this.toggleTooltip = ({
pageX,
pageY
}) => {
const action = this.getState() ? 'hideTooltip' : 'showTooltip';
this[action]({
pageX,
pageY
_this.toggleTooltip = function (_ref2) {
var pageX = _ref2.pageX,
pageY = _ref2.pageY;
var action = _this.getState() ? 'hideTooltip' : 'showTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.clickToggle = event => {
_this.clickToggle = function (event) {
event.preventDefault();
const pageX = event.pageX,
pageY = event.pageY;
const action = this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
this[action]({
pageX,
pageY
var pageX = event.pageX,
pageY = event.pageY;
var action = _this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.contextMenuToggle = event => {
_this.contextMenuToggle = function (event) {
event.preventDefault();
const pageX = event.pageX,
pageY = event.pageY;
const action = this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
this[action]({
pageX,
pageY
var pageX = event.pageX,
pageY = event.pageY;
var action = _this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.getTriggerProps = (props = {}) => {
return _extends({}, props, {}, this.isTriggeredBy('click') && {
onClick: callAll(this.clickToggle, props.onClick),
onTouchEnd: callAll(this.clickToggle, props.onTouchEnd)
}, {}, this.isTriggeredBy('right-click') && {
onContextMenu: callAll(this.contextMenuToggle, props.onContextMenu)
}, {}, this.isTriggeredBy('hover') && _extends({
onMouseEnter: callAll(this.showTooltip, props.onMouseEnter),
onMouseLeave: callAll(this.hideTooltip, props.onMouseLeave)
}, this.props.followCursor && {
onMouseMove: callAll(this.showTooltip, props.onMouseMove)
}), {}, this.isTriggeredBy('focus') && {
onFocus: callAll(this.showTooltip, props.onFocus),
onBlur: callAll(this.hideTooltip, props.onBlur)
_this.getTriggerProps = function (props) {
if (props === void 0) {
props = {};
}
return _extends({}, props, {}, _this.isTriggeredBy('click') && {
onClick: callAll(_this.clickToggle, props.onClick),
onTouchEnd: callAll(_this.clickToggle, props.onTouchEnd)
}, {}, _this.isTriggeredBy('right-click') && {
onContextMenu: callAll(_this.contextMenuToggle, props.onContextMenu)
}, {}, _this.isTriggeredBy('hover') && _extends({
onMouseEnter: callAll(_this.showTooltip, props.onMouseEnter),
onMouseLeave: callAll(_this.hideTooltip, props.onMouseLeave)
}, _this.props.followCursor && {
onMouseMove: callAll(_this.showTooltip, props.onMouseMove)
}), {}, _this.isTriggeredBy('focus') && {
onFocus: callAll(_this.showTooltip, props.onFocus),
onBlur: callAll(_this.hideTooltip, props.onBlur)
});
};
return _this;
}
componentWillUnmount() {
var _proto = TooltipTrigger.prototype;
_proto.componentWillUnmount = function componentWillUnmount() {
this.clearScheduled();
}
};
render() {
const _this$props = this.props,
children = _this$props.children,
tooltip = _this$props.tooltip,
placement = _this$props.placement,
trigger = _this$props.trigger,
getTriggerRef = _this$props.getTriggerRef,
modifiers = _this$props.modifiers,
closeOnOutOfBoundaries = _this$props.closeOnOutOfBoundaries,
usePortal = _this$props.usePortal,
portalContainer = _this$props.portalContainer,
followCursor = _this$props.followCursor,
getTooltipRef = _this$props.getTooltipRef,
mutationObserverOptions = _this$props.mutationObserverOptions,
restProps = _objectWithoutPropertiesLoose(_this$props, ["children", "tooltip", "placement", "trigger", "getTriggerRef", "modifiers", "closeOnOutOfBoundaries", "usePortal", "portalContainer", "followCursor", "getTooltipRef", "mutationObserverOptions"]);
_proto.render = function render() {
var _this2 = this;
const popper = /*#__PURE__*/React.createElement(reactPopper.Popper, _extends({
var _this$props = this.props,
children = _this$props.children,
tooltip = _this$props.tooltip,
placement = _this$props.placement,
trigger = _this$props.trigger,
getTriggerRef = _this$props.getTriggerRef,
modifiers = _this$props.modifiers,
closeOnOutOfBoundaries = _this$props.closeOnOutOfBoundaries,
usePortal = _this$props.usePortal,
portalContainer = _this$props.portalContainer,
followCursor = _this$props.followCursor,
getTooltipRef = _this$props.getTooltipRef,
mutationObserverOptions = _this$props.mutationObserverOptions,
restProps = _objectWithoutPropertiesLoose(_this$props, ["children", "tooltip", "placement", "trigger", "getTriggerRef", "modifiers", "closeOnOutOfBoundaries", "usePortal", "portalContainer", "followCursor", "getTooltipRef", "mutationObserverOptions"]);
var popper = /*#__PURE__*/React.createElement(reactPopper.Popper, _extends({
innerRef: getTooltipRef,

@@ -326,4 +403,4 @@ placement: placement,

enabled: true,
fn: data => {
this.popperOffset = data.offsets.popper;
fn: function fn(data) {
_this2.popperOffset = data.offsets.popper;
return data;

@@ -334,36 +411,35 @@ },

}, {}, modifiers)
}, restProps), ({
ref,
style,
// tslint:disable-next-line
placement,
arrowProps,
outOfBoundaries,
scheduleUpdate
}) => {
if (followCursor && this.popperOffset) {
const _this$state = this.state,
pageX = _this$state.pageX,
pageY = _this$state.pageY;
const _this$popperOffset = this.popperOffset,
width = _this$popperOffset.width,
height = _this$popperOffset.height;
const x = pageX + width > window.scrollX + document.body.offsetWidth ? pageX - width : pageX;
const y = pageY + height > window.scrollY + document.body.offsetHeight ? pageY - height : pageY;
style.transform = `translate3d(${x}px, ${y}px, 0`;
}, restProps), function (_ref3) {
var ref = _ref3.ref,
style = _ref3.style,
placement = _ref3.placement,
arrowProps = _ref3.arrowProps,
outOfBoundaries = _ref3.outOfBoundaries,
scheduleUpdate = _ref3.scheduleUpdate;
if (followCursor && _this2.popperOffset) {
var _this2$state = _this2.state,
pageX = _this2$state.pageX,
pageY = _this2$state.pageY;
var _this2$popperOffset = _this2.popperOffset,
width = _this2$popperOffset.width,
height = _this2$popperOffset.height;
var x = pageX + width > window.scrollX + document.body.offsetWidth ? pageX - width : pageX;
var y = pageY + height > window.scrollY + document.body.offsetHeight ? pageY - height : pageY;
style.transform = "translate3d(" + x + "px, " + y + "px, 0";
}
return /*#__PURE__*/React.createElement(Tooltip, _extends({
arrowProps,
closeOnOutOfBoundaries,
outOfBoundaries,
placement,
scheduleUpdate,
style,
tooltip,
trigger,
mutationObserverOptions
arrowProps: arrowProps,
closeOnOutOfBoundaries: closeOnOutOfBoundaries,
outOfBoundaries: outOfBoundaries,
placement: placement,
scheduleUpdate: scheduleUpdate,
style: style,
tooltip: tooltip,
trigger: trigger,
mutationObserverOptions: mutationObserverOptions
}, {
clearScheduled: this.clearScheduled,
hideTooltip: this.hideTooltip,
clearScheduled: _this2.clearScheduled,
hideTooltip: _this2.hideTooltip,
innerRef: ref

@@ -374,24 +450,26 @@ }));

innerRef: getTriggerRef
}, ({
ref
}) => children({
getTriggerProps: this.getTriggerProps,
triggerRef: ref
})), this.getState() && (usePortal ? reactDom.createPortal(popper, portalContainer) : popper));
}
}, function (_ref4) {
var ref = _ref4.ref;
return children({
getTriggerProps: _this2.getTriggerProps,
triggerRef: ref
});
}), this.getState() && (usePortal ? reactDom.createPortal(popper, portalContainer) : popper));
};
isControlled() {
_proto.isControlled = function isControlled() {
return this.props.tooltipShown !== undefined;
}
};
getState() {
_proto.getState = function getState() {
return this.isControlled() ? this.props.tooltipShown : this.state.tooltipShown;
}
};
isTriggeredBy(event) {
const trigger = this.props.trigger;
_proto.isTriggeredBy = function isTriggeredBy(event) {
var trigger = this.props.trigger;
return trigger === event || Array.isArray(trigger) && trigger.includes(event);
}
};
}
return TooltipTrigger;
}(React.Component);

@@ -398,0 +476,0 @@ TooltipTrigger.defaultProps = {

import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
import _extends from '@babel/runtime/helpers/esm/extends';
import '@babel/runtime/helpers/esm/possibleConstructorReturn';
import '@babel/runtime/helpers/esm/getPrototypeOf';
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
import React, { Component } from 'react';

@@ -7,10 +10,26 @@ import { createPortal } from 'react-dom';

const TooltipContext = React.createContext({}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
var TooltipContext = React.createContext({}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args));
const noop = () => {// do nothing
var callAll = function callAll() {
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
fns[_key] = arguments[_key];
}
return function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return fns.forEach(function (fn) {
return fn && fn.apply(void 0, args);
});
};
};
const canUseDOM = () => !!(typeof window !== 'undefined' && window.document && window.document.createElement);
const setRef = (ref, node) => {
var noop = function noop() {// do nothing
};
var canUseDOM = function canUseDOM() {
return !!(typeof window !== 'undefined' && window.document && window.document.createElement);
};
var setRef = function setRef(ref, node) {
if (typeof ref === 'function') {

@@ -23,14 +42,22 @@ return ref(node);

class Tooltip extends Component {
constructor(...args) {
super(...args);
this.observer = void 0;
this.tooltipRef = void 0;
var Tooltip = /*#__PURE__*/function (_Component) {
_inheritsLoose(Tooltip, _Component);
this.handleOutsideClick = event => {
if (this.tooltipRef && !this.tooltipRef.contains(event.target)) {
const parentOutsideClickHandler = this.context.parentOutsideClickHandler;
const _this$props = this.props,
hideTooltip = _this$props.hideTooltip,
clearScheduled = _this$props.clearScheduled;
function Tooltip() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.observer = void 0;
_this.tooltipRef = void 0;
_this.handleOutsideClick = function (event) {
if (_this.tooltipRef && !_this.tooltipRef.contains(event.target)) {
var parentOutsideClickHandler = _this.context.parentOutsideClickHandler;
var _this$props = _this.props,
hideTooltip = _this$props.hideTooltip,
clearScheduled = _this$props.clearScheduled;
clearScheduled();

@@ -45,8 +72,8 @@ hideTooltip();

this.handleOutsideRightClick = event => {
if (this.tooltipRef && !this.tooltipRef.contains(event.target)) {
const parentOutsideRightClickHandler = this.context.parentOutsideRightClickHandler;
const _this$props2 = this.props,
hideTooltip = _this$props2.hideTooltip,
clearScheduled = _this$props2.clearScheduled;
_this.handleOutsideRightClick = function (event) {
if (_this.tooltipRef && !_this.tooltipRef.contains(event.target)) {
var parentOutsideRightClickHandler = _this.context.parentOutsideRightClickHandler;
var _this$props2 = _this.props,
hideTooltip = _this$props2.hideTooltip,
clearScheduled = _this$props2.clearScheduled;
clearScheduled();

@@ -61,46 +88,67 @@ hideTooltip();

this.addOutsideClickHandler = () => {
document.body.addEventListener('touchend', this.handleOutsideClick);
document.body.addEventListener('click', this.handleOutsideClick);
_this.addOutsideClickHandler = function () {
document.body.addEventListener('touchend', _this.handleOutsideClick);
document.body.addEventListener('click', _this.handleOutsideClick);
};
this.removeOutsideClickHandler = () => {
document.body.removeEventListener('touchend', this.handleOutsideClick);
document.body.removeEventListener('click', this.handleOutsideClick);
_this.removeOutsideClickHandler = function () {
document.body.removeEventListener('touchend', _this.handleOutsideClick);
document.body.removeEventListener('click', _this.handleOutsideClick);
};
this.addOutsideRightClickHandler = () => document.body.addEventListener('contextmenu', this.handleOutsideRightClick);
_this.addOutsideRightClickHandler = function () {
return document.body.addEventListener('contextmenu', _this.handleOutsideRightClick);
};
this.removeOutsideRightClickHandler = () => document.body.removeEventListener('contextmenu', this.handleOutsideRightClick);
_this.removeOutsideRightClickHandler = function () {
return document.body.removeEventListener('contextmenu', _this.handleOutsideRightClick);
};
this.getTooltipRef = node => {
this.tooltipRef = node;
setRef(this.props.innerRef, node);
_this.getTooltipRef = function (node) {
_this.tooltipRef = node;
setRef(_this.props.innerRef, node);
};
this.getArrowProps = (props = {}) => _extends({}, props, {
style: _extends({}, props.style, {}, this.props.arrowProps.style)
});
_this.getArrowProps = function (props) {
if (props === void 0) {
props = {};
}
this.getTooltipProps = (props = {}) => _extends({}, props, {}, this.isTriggeredBy('hover') && {
onMouseEnter: callAll(this.props.clearScheduled, props.onMouseEnter),
onMouseLeave: callAll(this.props.hideTooltip, props.onMouseLeave)
}, {
style: _extends({}, props.style, {}, this.props.style)
});
return _extends({}, props, {
style: _extends({}, props.style, {}, _this.props.arrowProps.style)
});
};
this.contextValue = {
isParentNoneTriggered: this.props.trigger === 'none',
addParentOutsideClickHandler: this.addOutsideClickHandler,
addParentOutsideRightClickHandler: this.addOutsideRightClickHandler,
parentOutsideClickHandler: this.handleOutsideClick,
parentOutsideRightClickHandler: this.handleOutsideRightClick,
removeParentOutsideClickHandler: this.removeOutsideClickHandler,
removeParentOutsideRightClickHandler: this.removeOutsideRightClickHandler
_this.getTooltipProps = function (props) {
if (props === void 0) {
props = {};
}
return _extends({}, props, {}, _this.isTriggeredBy('hover') && {
onMouseEnter: callAll(_this.props.clearScheduled, props.onMouseEnter),
onMouseLeave: callAll(_this.props.hideTooltip, props.onMouseLeave)
}, {
style: _extends({}, props.style, {}, _this.props.style)
});
};
_this.contextValue = {
isParentNoneTriggered: _this.props.trigger === 'none',
addParentOutsideClickHandler: _this.addOutsideClickHandler,
addParentOutsideRightClickHandler: _this.addOutsideRightClickHandler,
parentOutsideClickHandler: _this.handleOutsideClick,
parentOutsideRightClickHandler: _this.handleOutsideRightClick,
removeParentOutsideClickHandler: _this.removeOutsideClickHandler,
removeParentOutsideRightClickHandler: _this.removeOutsideRightClickHandler
};
return _this;
}
componentDidMount() {
const observer = this.observer = new MutationObserver(() => {
this.props.scheduleUpdate();
var _proto = Tooltip.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var observer = this.observer = new MutationObserver(function () {
_this2.props.scheduleUpdate();
});

@@ -110,5 +158,5 @@ observer.observe(this.tooltipRef, this.props.mutationObserverOptions);

if (this.isTriggeredBy('hover') || this.isTriggeredBy('click') || this.isTriggeredBy('right-click')) {
const _this$context = this.context,
removeParentOutsideClickHandler = _this$context.removeParentOutsideClickHandler,
removeParentOutsideRightClickHandler = _this$context.removeParentOutsideRightClickHandler;
var _this$context = this.context,
removeParentOutsideClickHandler = _this$context.removeParentOutsideClickHandler,
removeParentOutsideRightClickHandler = _this$context.removeParentOutsideRightClickHandler;
this.addOutsideClickHandler();

@@ -125,11 +173,11 @@ this.addOutsideRightClickHandler();

}
}
};
componentDidUpdate() {
_proto.componentDidUpdate = function componentDidUpdate() {
if (this.props.closeOnOutOfBoundaries && this.props.outOfBoundaries) {
this.props.hideTooltip();
}
}
};
componentWillUnmount() {
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.observer) {

@@ -140,6 +188,6 @@ this.observer.disconnect();

if (this.isTriggeredBy('hover') || this.isTriggeredBy('click') || this.isTriggeredBy('right-click')) {
const _this$context2 = this.context,
isParentNoneTriggered = _this$context2.isParentNoneTriggered,
addParentOutsideClickHandler = _this$context2.addParentOutsideClickHandler,
addParentOutsideRightClickHandler = _this$context2.addParentOutsideRightClickHandler;
var _this$context2 = this.context,
isParentNoneTriggered = _this$context2.isParentNoneTriggered,
addParentOutsideClickHandler = _this$context2.addParentOutsideClickHandler,
addParentOutsideRightClickHandler = _this$context2.addParentOutsideRightClickHandler;
this.removeOutsideClickHandler();

@@ -158,9 +206,9 @@ this.removeOutsideRightClickHandler();

}
}
};
render() {
const _this$props3 = this.props,
arrowProps = _this$props3.arrowProps,
placement = _this$props3.placement,
tooltip = _this$props3.tooltip;
_proto.render = function render() {
var _this$props3 = this.props,
arrowProps = _this$props3.arrowProps,
placement = _this$props3.placement,
tooltip = _this$props3.tooltip;
return /*#__PURE__*/React.createElement(TooltipContext.Provider, {

@@ -172,17 +220,18 @@ value: this.contextValue

getTooltipProps: this.getTooltipProps,
placement,
placement: placement,
tooltipRef: this.getTooltipRef
}));
}
};
isTriggeredBy(event) {
const trigger = this.props.trigger;
_proto.isTriggeredBy = function isTriggeredBy(event) {
var trigger = this.props.trigger;
return trigger === event || Array.isArray(trigger) && trigger.includes(event);
}
};
}
return Tooltip;
}(Component);
Tooltip.contextType = TooltipContext;
const DEFAULT_MODIFIERS = {
var DEFAULT_MODIFIERS = {
preventOverflow: {

@@ -192,3 +241,3 @@ boundariesElement: 'viewport'

};
const DEFAULT_MUTATION_OBSERVER_CONFIG = {
var DEFAULT_MUTATION_OBSERVER_CONFIG = {
childList: true,

@@ -198,121 +247,149 @@ subtree: true

class TooltipTrigger extends Component {
constructor(...args) {
super(...args);
this.state = {
tooltipShown: this.props.defaultTooltipShown
var TooltipTrigger = /*#__PURE__*/function (_Component) {
_inheritsLoose(TooltipTrigger, _Component);
function TooltipTrigger() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.state = {
tooltipShown: _this.props.defaultTooltipShown
};
this.hideTimeout = void 0;
this.showTimeout = void 0;
this.popperOffset = void 0;
_this.hideTimeout = void 0;
_this.showTimeout = void 0;
_this.popperOffset = void 0;
this.setTooltipState = state => {
const cb = () => this.props.onVisibilityChange(state.tooltipShown);
_this.setTooltipState = function (state) {
var cb = function cb() {
return _this.props.onVisibilityChange(state.tooltipShown);
};
this.isControlled() ? cb() : this.setState(state, cb);
_this.isControlled() ? cb() : _this.setState(state, cb);
};
this.clearScheduled = () => {
clearTimeout(this.hideTimeout);
clearTimeout(this.showTimeout);
_this.clearScheduled = function () {
clearTimeout(_this.hideTimeout);
clearTimeout(_this.showTimeout);
};
this.showTooltip = ({
pageX,
pageY
}) => {
this.clearScheduled();
let state = {
_this.showTooltip = function (_ref) {
var pageX = _ref.pageX,
pageY = _ref.pageY;
_this.clearScheduled();
var state = {
tooltipShown: true
};
if (this.props.followCursor) {
if (_this.props.followCursor) {
state = _extends({}, state, {
pageX,
pageY
pageX: pageX,
pageY: pageY
});
}
this.showTimeout = window.setTimeout(() => this.setTooltipState(state), this.props.delayShow);
_this.showTimeout = window.setTimeout(function () {
return _this.setTooltipState(state);
}, _this.props.delayShow);
};
this.hideTooltip = () => {
this.clearScheduled();
this.hideTimeout = window.setTimeout(() => this.setTooltipState({
tooltipShown: false
}), this.props.delayHide);
_this.hideTooltip = function () {
_this.clearScheduled();
_this.hideTimeout = window.setTimeout(function () {
return _this.setTooltipState({
tooltipShown: false
});
}, _this.props.delayHide);
};
this.toggleTooltip = ({
pageX,
pageY
}) => {
const action = this.getState() ? 'hideTooltip' : 'showTooltip';
this[action]({
pageX,
pageY
_this.toggleTooltip = function (_ref2) {
var pageX = _ref2.pageX,
pageY = _ref2.pageY;
var action = _this.getState() ? 'hideTooltip' : 'showTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.clickToggle = event => {
_this.clickToggle = function (event) {
event.preventDefault();
const pageX = event.pageX,
pageY = event.pageY;
const action = this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
this[action]({
pageX,
pageY
var pageX = event.pageX,
pageY = event.pageY;
var action = _this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.contextMenuToggle = event => {
_this.contextMenuToggle = function (event) {
event.preventDefault();
const pageX = event.pageX,
pageY = event.pageY;
const action = this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
this[action]({
pageX,
pageY
var pageX = event.pageX,
pageY = event.pageY;
var action = _this.props.followCursor ? 'showTooltip' : 'toggleTooltip';
_this[action]({
pageX: pageX,
pageY: pageY
});
};
this.getTriggerProps = (props = {}) => {
return _extends({}, props, {}, this.isTriggeredBy('click') && {
onClick: callAll(this.clickToggle, props.onClick),
onTouchEnd: callAll(this.clickToggle, props.onTouchEnd)
}, {}, this.isTriggeredBy('right-click') && {
onContextMenu: callAll(this.contextMenuToggle, props.onContextMenu)
}, {}, this.isTriggeredBy('hover') && _extends({
onMouseEnter: callAll(this.showTooltip, props.onMouseEnter),
onMouseLeave: callAll(this.hideTooltip, props.onMouseLeave)
}, this.props.followCursor && {
onMouseMove: callAll(this.showTooltip, props.onMouseMove)
}), {}, this.isTriggeredBy('focus') && {
onFocus: callAll(this.showTooltip, props.onFocus),
onBlur: callAll(this.hideTooltip, props.onBlur)
_this.getTriggerProps = function (props) {
if (props === void 0) {
props = {};
}
return _extends({}, props, {}, _this.isTriggeredBy('click') && {
onClick: callAll(_this.clickToggle, props.onClick),
onTouchEnd: callAll(_this.clickToggle, props.onTouchEnd)
}, {}, _this.isTriggeredBy('right-click') && {
onContextMenu: callAll(_this.contextMenuToggle, props.onContextMenu)
}, {}, _this.isTriggeredBy('hover') && _extends({
onMouseEnter: callAll(_this.showTooltip, props.onMouseEnter),
onMouseLeave: callAll(_this.hideTooltip, props.onMouseLeave)
}, _this.props.followCursor && {
onMouseMove: callAll(_this.showTooltip, props.onMouseMove)
}), {}, _this.isTriggeredBy('focus') && {
onFocus: callAll(_this.showTooltip, props.onFocus),
onBlur: callAll(_this.hideTooltip, props.onBlur)
});
};
return _this;
}
componentWillUnmount() {
var _proto = TooltipTrigger.prototype;
_proto.componentWillUnmount = function componentWillUnmount() {
this.clearScheduled();
}
};
render() {
const _this$props = this.props,
children = _this$props.children,
tooltip = _this$props.tooltip,
placement = _this$props.placement,
trigger = _this$props.trigger,
getTriggerRef = _this$props.getTriggerRef,
modifiers = _this$props.modifiers,
closeOnOutOfBoundaries = _this$props.closeOnOutOfBoundaries,
usePortal = _this$props.usePortal,
portalContainer = _this$props.portalContainer,
followCursor = _this$props.followCursor,
getTooltipRef = _this$props.getTooltipRef,
mutationObserverOptions = _this$props.mutationObserverOptions,
restProps = _objectWithoutPropertiesLoose(_this$props, ["children", "tooltip", "placement", "trigger", "getTriggerRef", "modifiers", "closeOnOutOfBoundaries", "usePortal", "portalContainer", "followCursor", "getTooltipRef", "mutationObserverOptions"]);
_proto.render = function render() {
var _this2 = this;
const popper = /*#__PURE__*/React.createElement(Popper, _extends({
var _this$props = this.props,
children = _this$props.children,
tooltip = _this$props.tooltip,
placement = _this$props.placement,
trigger = _this$props.trigger,
getTriggerRef = _this$props.getTriggerRef,
modifiers = _this$props.modifiers,
closeOnOutOfBoundaries = _this$props.closeOnOutOfBoundaries,
usePortal = _this$props.usePortal,
portalContainer = _this$props.portalContainer,
followCursor = _this$props.followCursor,
getTooltipRef = _this$props.getTooltipRef,
mutationObserverOptions = _this$props.mutationObserverOptions,
restProps = _objectWithoutPropertiesLoose(_this$props, ["children", "tooltip", "placement", "trigger", "getTriggerRef", "modifiers", "closeOnOutOfBoundaries", "usePortal", "portalContainer", "followCursor", "getTooltipRef", "mutationObserverOptions"]);
var popper = /*#__PURE__*/React.createElement(Popper, _extends({
innerRef: getTooltipRef,

@@ -323,4 +400,4 @@ placement: placement,

enabled: true,
fn: data => {
this.popperOffset = data.offsets.popper;
fn: function fn(data) {
_this2.popperOffset = data.offsets.popper;
return data;

@@ -331,36 +408,35 @@ },

}, {}, modifiers)
}, restProps), ({
ref,
style,
// tslint:disable-next-line
placement,
arrowProps,
outOfBoundaries,
scheduleUpdate
}) => {
if (followCursor && this.popperOffset) {
const _this$state = this.state,
pageX = _this$state.pageX,
pageY = _this$state.pageY;
const _this$popperOffset = this.popperOffset,
width = _this$popperOffset.width,
height = _this$popperOffset.height;
const x = pageX + width > window.scrollX + document.body.offsetWidth ? pageX - width : pageX;
const y = pageY + height > window.scrollY + document.body.offsetHeight ? pageY - height : pageY;
style.transform = `translate3d(${x}px, ${y}px, 0`;
}, restProps), function (_ref3) {
var ref = _ref3.ref,
style = _ref3.style,
placement = _ref3.placement,
arrowProps = _ref3.arrowProps,
outOfBoundaries = _ref3.outOfBoundaries,
scheduleUpdate = _ref3.scheduleUpdate;
if (followCursor && _this2.popperOffset) {
var _this2$state = _this2.state,
pageX = _this2$state.pageX,
pageY = _this2$state.pageY;
var _this2$popperOffset = _this2.popperOffset,
width = _this2$popperOffset.width,
height = _this2$popperOffset.height;
var x = pageX + width > window.scrollX + document.body.offsetWidth ? pageX - width : pageX;
var y = pageY + height > window.scrollY + document.body.offsetHeight ? pageY - height : pageY;
style.transform = "translate3d(" + x + "px, " + y + "px, 0";
}
return /*#__PURE__*/React.createElement(Tooltip, _extends({
arrowProps,
closeOnOutOfBoundaries,
outOfBoundaries,
placement,
scheduleUpdate,
style,
tooltip,
trigger,
mutationObserverOptions
arrowProps: arrowProps,
closeOnOutOfBoundaries: closeOnOutOfBoundaries,
outOfBoundaries: outOfBoundaries,
placement: placement,
scheduleUpdate: scheduleUpdate,
style: style,
tooltip: tooltip,
trigger: trigger,
mutationObserverOptions: mutationObserverOptions
}, {
clearScheduled: this.clearScheduled,
hideTooltip: this.hideTooltip,
clearScheduled: _this2.clearScheduled,
hideTooltip: _this2.hideTooltip,
innerRef: ref

@@ -371,24 +447,26 @@ }));

innerRef: getTriggerRef
}, ({
ref
}) => children({
getTriggerProps: this.getTriggerProps,
triggerRef: ref
})), this.getState() && (usePortal ? createPortal(popper, portalContainer) : popper));
}
}, function (_ref4) {
var ref = _ref4.ref;
return children({
getTriggerProps: _this2.getTriggerProps,
triggerRef: ref
});
}), this.getState() && (usePortal ? createPortal(popper, portalContainer) : popper));
};
isControlled() {
_proto.isControlled = function isControlled() {
return this.props.tooltipShown !== undefined;
}
};
getState() {
_proto.getState = function getState() {
return this.isControlled() ? this.props.tooltipShown : this.state.tooltipShown;
}
};
isTriggeredBy(event) {
const trigger = this.props.trigger;
_proto.isTriggeredBy = function isTriggeredBy(event) {
var trigger = this.props.trigger;
return trigger === event || Array.isArray(trigger) && trigger.includes(event);
}
};
}
return TooltipTrigger;
}(Component);

@@ -395,0 +473,0 @@ TooltipTrigger.defaultProps = {

{
"name": "react-popper-tooltip",
"version": "2.11.0",
"version": "2.11.1",
"description": "React tooltip library built around react-popper",

@@ -67,8 +67,8 @@ "homepage": "https://react-popper-tooltip.netlify.com",

"@babel/preset-typescript": "^7.9.0",
"@testing-library/react": "^10.0.1",
"@testing-library/react": "^10.0.2",
"@types/jest": "^25.1.4",
"@types/react": "^16.9.26",
"@types/react-dom": "^16.9.5",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"@types/react": "^16.9.31",
"@types/react-dom": "^16.9.6",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"docz": "^2.2.0",

@@ -80,8 +80,8 @@ "eslint": "^6.8.0",

"husky": "^4.2.3",
"jest": "^25.2.3",
"lint-staged": "^10.0.9",
"jest": "^25.2.4",
"lint-staged": "^10.1.1",
"prettier": "^2.0.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"rollup": "^2.2.0",
"rollup": "^2.3.2",
"rollup-plugin-babel": "^4.4.0",

@@ -88,0 +88,0 @@ "rollup-plugin-node-resolve": "^5.2.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc