reactjs-popup.esm.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. import React, { useEffect, useLayoutEffect, forwardRef, useState, useRef, useImperativeHandle } from 'react';
  2. import ReactDOM from 'react-dom';
  3. function _extends() {
  4. _extends = Object.assign || function (target) {
  5. for (var i = 1; i < arguments.length; i++) {
  6. var source = arguments[i];
  7. for (var key in source) {
  8. if (Object.prototype.hasOwnProperty.call(source, key)) {
  9. target[key] = source[key];
  10. }
  11. }
  12. }
  13. return target;
  14. };
  15. return _extends.apply(this, arguments);
  16. }
  17. var useOnEscape = function useOnEscape(handler, active) {
  18. if (active === void 0) {
  19. active = true;
  20. }
  21. useEffect(function () {
  22. if (!active) return;
  23. var listener = function listener(event) {
  24. // check if key is an Escape
  25. if (event.key === 'Escape') handler(event);
  26. };
  27. document.addEventListener('keyup', listener);
  28. return function () {
  29. if (!active) return;
  30. document.removeEventListener('keyup', listener);
  31. };
  32. }, [handler, active]);
  33. };
  34. var useRepositionOnResize = function useRepositionOnResize(handler, active) {
  35. if (active === void 0) {
  36. active = true;
  37. }
  38. useEffect(function () {
  39. if (!active) return;
  40. var listener = function listener() {
  41. handler();
  42. };
  43. window.addEventListener('resize', listener);
  44. return function () {
  45. if (!active) return;
  46. window.removeEventListener('resize', listener);
  47. };
  48. }, [handler, active]);
  49. };
  50. var useOnClickOutside = function useOnClickOutside(ref, handler, active) {
  51. if (active === void 0) {
  52. active = true;
  53. }
  54. useEffect(function () {
  55. if (!active) return;
  56. var listener = function listener(event) {
  57. // Do nothing if clicking ref's element or descendent elements
  58. var refs = Array.isArray(ref) ? ref : [ref];
  59. var contains = false;
  60. refs.forEach(function (r) {
  61. if (!r.current || r.current.contains(event.target)) {
  62. contains = true;
  63. return;
  64. }
  65. });
  66. event.stopPropagation();
  67. if (!contains) handler(event);
  68. };
  69. document.addEventListener('mousedown', listener);
  70. document.addEventListener('touchstart', listener);
  71. return function () {
  72. if (!active) return;
  73. document.removeEventListener('mousedown', listener);
  74. document.removeEventListener('touchstart', listener);
  75. };
  76. }, [ref, handler, active]);
  77. }; // Make sure that user is not able TAB out of the Modal content on Open
  78. var useTabbing = function useTabbing(contentRef, active) {
  79. if (active === void 0) {
  80. active = true;
  81. }
  82. useEffect(function () {
  83. if (!active) return;
  84. var listener = function listener(event) {
  85. // check if key is an Tab
  86. if (event.keyCode === 9) {
  87. var _contentRef$current;
  88. var els = contentRef === null || contentRef === void 0 ? void 0 : (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');
  89. var focusableEls = Array.prototype.slice.call(els);
  90. if (focusableEls.length === 1) {
  91. event.preventDefault();
  92. return;
  93. }
  94. var firstFocusableEl = focusableEls[0];
  95. var lastFocusableEl = focusableEls[focusableEls.length - 1];
  96. if (event.shiftKey && document.activeElement === firstFocusableEl) {
  97. event.preventDefault();
  98. lastFocusableEl.focus();
  99. } else if (document.activeElement === lastFocusableEl) {
  100. event.preventDefault();
  101. firstFocusableEl.focus();
  102. }
  103. }
  104. };
  105. document.addEventListener('keydown', listener);
  106. return function () {
  107. if (!active) return;
  108. document.removeEventListener('keydown', listener);
  109. };
  110. }, [contentRef, active]);
  111. };
  112. var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
  113. var Style = {
  114. popupContent: {
  115. tooltip: {
  116. position: 'absolute',
  117. zIndex: 999
  118. },
  119. modal: {
  120. position: 'relative',
  121. margin: 'auto'
  122. }
  123. },
  124. popupArrow: {
  125. height: '8px',
  126. width: '16px',
  127. position: 'absolute',
  128. background: 'transparent',
  129. color: '#FFF',
  130. zIndex: -1
  131. },
  132. overlay: {
  133. tooltip: {
  134. position: 'fixed',
  135. top: '0',
  136. bottom: '0',
  137. left: '0',
  138. right: '0',
  139. zIndex: 999
  140. },
  141. modal: {
  142. position: 'fixed',
  143. top: '0',
  144. bottom: '0',
  145. left: '0',
  146. right: '0',
  147. display: 'flex',
  148. zIndex: 999
  149. }
  150. }
  151. };
  152. var POSITION_TYPES = ['top left', 'top center', 'top right', 'right top', 'right center', 'right bottom', 'bottom left', 'bottom center', 'bottom right', 'left top', 'left center', 'left bottom'];
  153. var getCoordinatesForPosition = function getCoordinatesForPosition(triggerBounding, ContentBounding, position, //PopupPosition | PopupPosition[],
  154. arrow, _ref) {
  155. var offsetX = _ref.offsetX,
  156. offsetY = _ref.offsetY;
  157. var margin = arrow ? 8 : 0;
  158. var args = position.split(' '); // the step N 1 : center the popup content => ok
  159. var CenterTop = triggerBounding.top + triggerBounding.height / 2;
  160. var CenterLeft = triggerBounding.left + triggerBounding.width / 2;
  161. var height = ContentBounding.height,
  162. width = ContentBounding.width;
  163. var top = CenterTop - height / 2;
  164. var left = CenterLeft - width / 2;
  165. var transform = '';
  166. var arrowTop = '0%';
  167. var arrowLeft = '0%'; // the step N 2 : => ok
  168. switch (args[0]) {
  169. case 'top':
  170. top -= height / 2 + triggerBounding.height / 2 + margin;
  171. transform = "rotate(180deg) translateX(50%)";
  172. arrowTop = '100%';
  173. arrowLeft = '50%';
  174. break;
  175. case 'bottom':
  176. top += height / 2 + triggerBounding.height / 2 + margin;
  177. transform = "rotate(0deg) translateY(-100%) translateX(-50%)";
  178. arrowLeft = '50%';
  179. break;
  180. case 'left':
  181. left -= width / 2 + triggerBounding.width / 2 + margin;
  182. transform = " rotate(90deg) translateY(50%) translateX(-25%)";
  183. arrowLeft = '100%';
  184. arrowTop = '50%';
  185. break;
  186. case 'right':
  187. left += width / 2 + triggerBounding.width / 2 + margin;
  188. transform = "rotate(-90deg) translateY(-150%) translateX(25%)";
  189. arrowTop = '50%';
  190. break;
  191. }
  192. switch (args[1]) {
  193. case 'top':
  194. top = triggerBounding.top;
  195. arrowTop = triggerBounding.height / 2 + "px";
  196. break;
  197. case 'bottom':
  198. top = triggerBounding.top - height + triggerBounding.height;
  199. arrowTop = height - triggerBounding.height / 2 + "px";
  200. break;
  201. case 'left':
  202. left = triggerBounding.left;
  203. arrowLeft = triggerBounding.width / 2 + "px";
  204. break;
  205. case 'right':
  206. left = triggerBounding.left - width + triggerBounding.width;
  207. arrowLeft = width - triggerBounding.width / 2 + "px";
  208. break;
  209. }
  210. top = args[0] === 'top' ? top - offsetY : top + offsetY;
  211. left = args[0] === 'left' ? left - offsetX : left + offsetX;
  212. return {
  213. top: top,
  214. left: left,
  215. transform: transform,
  216. arrowLeft: arrowLeft,
  217. arrowTop: arrowTop
  218. };
  219. };
  220. var getTooltipBoundary = function getTooltipBoundary(keepTooltipInside) {
  221. // add viewport
  222. var boundingBox = {
  223. top: 0,
  224. left: 0,
  225. /* eslint-disable-next-line no-undef */
  226. width: window.innerWidth,
  227. /* eslint-disable-next-line no-undef */
  228. height: window.innerHeight
  229. };
  230. if (typeof keepTooltipInside === 'string') {
  231. /* eslint-disable-next-line no-undef */
  232. var selector = document.querySelector(keepTooltipInside);
  233. if (process.env.NODE_ENV !== 'production') {
  234. if (selector === null) throw new Error(keepTooltipInside + " selector does not exist : keepTooltipInside must be a valid html selector 'class' or 'Id' or a boolean value");
  235. }
  236. if (selector !== null) boundingBox = selector.getBoundingClientRect();
  237. }
  238. return boundingBox;
  239. };
  240. var calculatePosition = function calculatePosition(triggerBounding, ContentBounding, position, arrow, _ref2, keepTooltipInside) {
  241. var offsetX = _ref2.offsetX,
  242. offsetY = _ref2.offsetY;
  243. var bestCoords = {
  244. arrowLeft: '0%',
  245. arrowTop: '0%',
  246. left: 0,
  247. top: 0,
  248. transform: 'rotate(135deg)'
  249. };
  250. var i = 0;
  251. var wrapperBox = getTooltipBoundary(keepTooltipInside);
  252. var positions = Array.isArray(position) ? position : [position]; // keepTooltipInside would be activated if the keepTooltipInside exist or the position is Array
  253. if (keepTooltipInside || Array.isArray(position)) positions = [].concat(positions, POSITION_TYPES); // add viewPort for WarpperBox
  254. // wrapperBox.top = wrapperBox.top + window.scrollY;
  255. // wrapperBox.left = wrapperBox.left + window.scrollX;
  256. while (i < positions.length) {
  257. bestCoords = getCoordinatesForPosition(triggerBounding, ContentBounding, positions[i], arrow, {
  258. offsetX: offsetX,
  259. offsetY: offsetY
  260. });
  261. var contentBox = {
  262. top: bestCoords.top,
  263. left: bestCoords.left,
  264. width: ContentBounding.width,
  265. height: ContentBounding.height
  266. };
  267. if (contentBox.top <= wrapperBox.top || contentBox.left <= wrapperBox.left || contentBox.top + contentBox.height >= wrapperBox.top + wrapperBox.height || contentBox.left + contentBox.width >= wrapperBox.left + wrapperBox.width) {
  268. i++;
  269. } else {
  270. break;
  271. }
  272. }
  273. return bestCoords;
  274. };
  275. var popupIdCounter = 0;
  276. var getRootPopup = function getRootPopup() {
  277. var PopupRoot = document.getElementById('popup-root');
  278. if (PopupRoot === null) {
  279. PopupRoot = document.createElement('div');
  280. PopupRoot.setAttribute('id', 'popup-root');
  281. document.body.appendChild(PopupRoot);
  282. }
  283. return PopupRoot;
  284. };
  285. var Popup = /*#__PURE__*/forwardRef(function (_ref, ref) {
  286. var _ref$trigger = _ref.trigger,
  287. trigger = _ref$trigger === void 0 ? null : _ref$trigger,
  288. _ref$onOpen = _ref.onOpen,
  289. onOpen = _ref$onOpen === void 0 ? function () {} : _ref$onOpen,
  290. _ref$onClose = _ref.onClose,
  291. onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
  292. _ref$defaultOpen = _ref.defaultOpen,
  293. defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
  294. _ref$open = _ref.open,
  295. open = _ref$open === void 0 ? undefined : _ref$open,
  296. _ref$disabled = _ref.disabled,
  297. disabled = _ref$disabled === void 0 ? false : _ref$disabled,
  298. _ref$nested = _ref.nested,
  299. nested = _ref$nested === void 0 ? false : _ref$nested,
  300. _ref$closeOnDocumentC = _ref.closeOnDocumentClick,
  301. closeOnDocumentClick = _ref$closeOnDocumentC === void 0 ? true : _ref$closeOnDocumentC,
  302. _ref$repositionOnResi = _ref.repositionOnResize,
  303. repositionOnResize = _ref$repositionOnResi === void 0 ? true : _ref$repositionOnResi,
  304. _ref$closeOnEscape = _ref.closeOnEscape,
  305. closeOnEscape = _ref$closeOnEscape === void 0 ? true : _ref$closeOnEscape,
  306. _ref$on = _ref.on,
  307. on = _ref$on === void 0 ? ['click'] : _ref$on,
  308. _ref$contentStyle = _ref.contentStyle,
  309. contentStyle = _ref$contentStyle === void 0 ? {} : _ref$contentStyle,
  310. _ref$arrowStyle = _ref.arrowStyle,
  311. arrowStyle = _ref$arrowStyle === void 0 ? {} : _ref$arrowStyle,
  312. _ref$overlayStyle = _ref.overlayStyle,
  313. overlayStyle = _ref$overlayStyle === void 0 ? {} : _ref$overlayStyle,
  314. _ref$className = _ref.className,
  315. className = _ref$className === void 0 ? '' : _ref$className,
  316. _ref$position = _ref.position,
  317. position = _ref$position === void 0 ? 'bottom center' : _ref$position,
  318. _ref$modal = _ref.modal,
  319. modal = _ref$modal === void 0 ? false : _ref$modal,
  320. _ref$lockScroll = _ref.lockScroll,
  321. lockScroll = _ref$lockScroll === void 0 ? false : _ref$lockScroll,
  322. _ref$arrow = _ref.arrow,
  323. arrow = _ref$arrow === void 0 ? true : _ref$arrow,
  324. _ref$offsetX = _ref.offsetX,
  325. offsetX = _ref$offsetX === void 0 ? 0 : _ref$offsetX,
  326. _ref$offsetY = _ref.offsetY,
  327. offsetY = _ref$offsetY === void 0 ? 0 : _ref$offsetY,
  328. _ref$mouseEnterDelay = _ref.mouseEnterDelay,
  329. mouseEnterDelay = _ref$mouseEnterDelay === void 0 ? 100 : _ref$mouseEnterDelay,
  330. _ref$mouseLeaveDelay = _ref.mouseLeaveDelay,
  331. mouseLeaveDelay = _ref$mouseLeaveDelay === void 0 ? 100 : _ref$mouseLeaveDelay,
  332. _ref$keepTooltipInsid = _ref.keepTooltipInside,
  333. keepTooltipInside = _ref$keepTooltipInsid === void 0 ? false : _ref$keepTooltipInsid,
  334. children = _ref.children;
  335. var _useState = useState(open || defaultOpen),
  336. isOpen = _useState[0],
  337. setIsOpen = _useState[1];
  338. var triggerRef = useRef(null);
  339. var contentRef = useRef(null);
  340. var arrowRef = useRef(null);
  341. var focusedElBeforeOpen = useRef(null);
  342. var popupId = useRef("popup-" + ++popupIdCounter);
  343. var isModal = modal ? true : !trigger;
  344. var timeOut = useRef(0);
  345. useIsomorphicLayoutEffect(function () {
  346. if (isOpen) {
  347. focusedElBeforeOpen.current = document.activeElement;
  348. setPosition();
  349. focusContentOnOpen(); // for accessibility
  350. lockScrolll();
  351. } else {
  352. resetScroll();
  353. }
  354. return function () {
  355. clearTimeout(timeOut.current);
  356. };
  357. }, [isOpen]); // for uncontrolled popup we need to sync isOpen with open prop
  358. useEffect(function () {
  359. if (typeof open === 'boolean') {
  360. if (open) openPopup();else closePopup();
  361. }
  362. }, [open, disabled]);
  363. var openPopup = function openPopup(event) {
  364. if (isOpen || disabled) return;
  365. setIsOpen(true);
  366. setTimeout(function () {
  367. return onOpen(event);
  368. }, 0);
  369. };
  370. var closePopup = function closePopup(event) {
  371. var _focusedElBeforeOpen$;
  372. if (!isOpen || disabled) return;
  373. setIsOpen(false);
  374. if (isModal) (_focusedElBeforeOpen$ = focusedElBeforeOpen.current) === null || _focusedElBeforeOpen$ === void 0 ? void 0 : _focusedElBeforeOpen$.focus();
  375. setTimeout(function () {
  376. return onClose(event);
  377. }, 0);
  378. };
  379. var togglePopup = function togglePopup(event) {
  380. event === null || event === void 0 ? void 0 : event.stopPropagation();
  381. if (!isOpen) openPopup(event);else closePopup(event);
  382. };
  383. var onMouseEnter = function onMouseEnter(event) {
  384. clearTimeout(timeOut.current);
  385. timeOut.current = setTimeout(function () {
  386. return openPopup(event);
  387. }, mouseEnterDelay);
  388. };
  389. var onContextMenu = function onContextMenu(event) {
  390. event === null || event === void 0 ? void 0 : event.preventDefault();
  391. togglePopup();
  392. };
  393. var onMouseLeave = function onMouseLeave(event) {
  394. clearTimeout(timeOut.current);
  395. timeOut.current = setTimeout(function () {
  396. return closePopup(event);
  397. }, mouseLeaveDelay);
  398. };
  399. var lockScrolll = function lockScrolll() {
  400. if (isModal && lockScroll) document.getElementsByTagName('body')[0].style.overflow = 'hidden'; // migrate to document.body
  401. };
  402. var resetScroll = function resetScroll() {
  403. if (isModal && lockScroll) document.getElementsByTagName('body')[0].style.overflow = 'auto';
  404. };
  405. var focusContentOnOpen = function focusContentOnOpen() {
  406. var _contentRef$current;
  407. var focusableEls = contentRef === null || contentRef === void 0 ? void 0 : (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');
  408. var firstEl = Array.prototype.slice.call(focusableEls)[0];
  409. firstEl === null || firstEl === void 0 ? void 0 : firstEl.focus();
  410. };
  411. useImperativeHandle(ref, function () {
  412. return {
  413. open: function open() {
  414. openPopup();
  415. },
  416. close: function close() {
  417. closePopup();
  418. },
  419. toggle: function toggle() {
  420. togglePopup();
  421. }
  422. };
  423. }); // set Position
  424. var setPosition = function setPosition() {
  425. if (isModal || !isOpen) return;
  426. if (!(triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current) || !(triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current) || !(contentRef === null || contentRef === void 0 ? void 0 : contentRef.current)) return; /// show error as one of ref is undefined
  427. var trigger = triggerRef.current.getBoundingClientRect();
  428. var content = contentRef.current.getBoundingClientRect();
  429. var cords = calculatePosition(trigger, content, position, arrow, {
  430. offsetX: offsetX,
  431. offsetY: offsetY
  432. }, keepTooltipInside);
  433. contentRef.current.style.top = cords.top + window.scrollY + "px";
  434. contentRef.current.style.left = cords.left + window.scrollX + "px";
  435. if (arrow && !!arrowRef.current) {
  436. var _arrowStyle$top, _arrowStyle$left;
  437. arrowRef.current.style.transform = cords.transform;
  438. arrowRef.current.style.setProperty('-ms-transform', cords.transform);
  439. arrowRef.current.style.setProperty('-webkit-transform', cords.transform);
  440. arrowRef.current.style.top = ((_arrowStyle$top = arrowStyle.top) === null || _arrowStyle$top === void 0 ? void 0 : _arrowStyle$top.toString()) || cords.arrowTop;
  441. arrowRef.current.style.left = ((_arrowStyle$left = arrowStyle.left) === null || _arrowStyle$left === void 0 ? void 0 : _arrowStyle$left.toString()) || cords.arrowLeft;
  442. }
  443. }; // hooks
  444. useOnEscape(closePopup, closeOnEscape); // can be optimized if we disabled for hover
  445. useTabbing(contentRef, isOpen && isModal);
  446. useRepositionOnResize(setPosition, repositionOnResize);
  447. useOnClickOutside(!!trigger ? [contentRef, triggerRef] : [contentRef], closePopup, closeOnDocumentClick && !nested); // we need to add a ne
  448. // render the trigger element and add events
  449. var renderTrigger = function renderTrigger() {
  450. var triggerProps = {
  451. key: 'T',
  452. ref: triggerRef,
  453. 'aria-describedby': popupId.current
  454. };
  455. var onAsArray = Array.isArray(on) ? on : [on];
  456. for (var i = 0, len = onAsArray.length; i < len; i++) {
  457. switch (onAsArray[i]) {
  458. case 'click':
  459. triggerProps.onClick = togglePopup;
  460. break;
  461. case 'right-click':
  462. triggerProps.onContextMenu = onContextMenu;
  463. break;
  464. case 'hover':
  465. triggerProps.onMouseEnter = onMouseEnter;
  466. triggerProps.onMouseLeave = onMouseLeave;
  467. break;
  468. case 'focus':
  469. triggerProps.onFocus = onMouseEnter;
  470. triggerProps.onBlur = onMouseLeave;
  471. break;
  472. }
  473. }
  474. if (typeof trigger === 'function') {
  475. var comp = trigger(isOpen);
  476. return !!trigger && React.cloneElement(comp, triggerProps);
  477. }
  478. return !!trigger && React.cloneElement(trigger, triggerProps);
  479. };
  480. var addWarperAction = function addWarperAction() {
  481. var popupContentStyle = isModal ? Style.popupContent.modal : Style.popupContent.tooltip;
  482. var childrenElementProps = {
  483. className: "popup-content " + (className !== '' ? className.split(' ').map(function (c) {
  484. return c + "-content";
  485. }).join(' ') : ''),
  486. style: _extends({}, popupContentStyle, contentStyle, {
  487. pointerEvents: 'auto'
  488. }),
  489. ref: contentRef,
  490. onClick: function onClick(e) {
  491. e.stopPropagation();
  492. }
  493. };
  494. if (!modal && on.indexOf('hover') >= 0) {
  495. childrenElementProps.onMouseEnter = onMouseEnter;
  496. childrenElementProps.onMouseLeave = onMouseLeave;
  497. }
  498. return childrenElementProps;
  499. };
  500. var renderContent = function renderContent() {
  501. return React.createElement("div", Object.assign({}, addWarperAction(), {
  502. key: "C",
  503. role: isModal ? 'dialog' : 'tooltip',
  504. id: popupId.current
  505. }), arrow && !isModal && React.createElement("div", {
  506. ref: arrowRef,
  507. style: Style.popupArrow
  508. }, React.createElement("svg", {
  509. "data-testid": "arrow",
  510. className: "popup-arrow " + (className !== '' ? className.split(' ').map(function (c) {
  511. return c + "-arrow";
  512. }).join(' ') : ''),
  513. viewBox: "0 0 32 16",
  514. style: _extends({
  515. position: 'absolute'
  516. }, arrowStyle)
  517. }, React.createElement("path", {
  518. d: "M16 0l16 16H0z",
  519. fill: "currentcolor"
  520. }))), children && typeof children === 'function' ? children(closePopup, isOpen) : children);
  521. };
  522. var overlay = !(on.indexOf('hover') >= 0);
  523. var ovStyle = isModal ? Style.overlay.modal : Style.overlay.tooltip;
  524. var content = [overlay && React.createElement("div", {
  525. key: "O",
  526. "data-testid": "overlay",
  527. "data-popup": isModal ? 'modal' : 'tooltip',
  528. className: "popup-overlay " + (className !== '' ? className.split(' ').map(function (c) {
  529. return c + "-overlay";
  530. }).join(' ') : ''),
  531. style: _extends({}, ovStyle, overlayStyle, {
  532. pointerEvents: closeOnDocumentClick && nested || isModal ? 'auto' : 'none'
  533. }),
  534. onClick: closeOnDocumentClick && nested ? closePopup : undefined,
  535. tabIndex: -1
  536. }, isModal && renderContent()), !isModal && renderContent()];
  537. return React.createElement(React.Fragment, null, renderTrigger(), isOpen && ReactDOM.createPortal(content, getRootPopup()));
  538. });
  539. export default Popup;
  540. export { Popup };
  541. //# sourceMappingURL=reactjs-popup.esm.js.map