UNPKG

@makeen.io/material-ui-kit

Version:
23 lines 1.4 kB
import _extends from "@babel/runtime/helpers/extends";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";import React, { useEffect, useRef, useState } from "react"; import Tooltip from "@material-ui/core/Tooltip"; export default (function (_ref) {var children = _ref.children,props = _objectWithoutProperties(_ref, ["children"]);var _useState = useState(false),_useState2 = _slicedToArray(_useState, 2),isTooltipVisible = _useState2[0],setTooltipState = _useState2[1]; var ref = useRef(null); useEffect(function () { if (ref.current) {var _ref$current$getBound = ref.current.getBoundingClientRect(),top = _ref$current$getBound.top,right = _ref$current$getBound.right,bottom = _ref$current$getBound.bottom,left = _ref$current$getBound.left; var handler = function handler(e) { if (e.x > left && e.x < right && e.y > top && e.y < bottom) { setTooltipState(true); } else { setTooltipState(false); } }; window.addEventListener("mousemove", handler); return function () {return window.removeEventListener("mousemove", handler);}; } }, []); return /*#__PURE__*/React.createElement(Tooltip, _extends({ open: isTooltipVisible }, props), children(ref)); }); //# sourceMappingURL=ControlledTooltip.js.map