iguazio.dashboard-react-controls 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export default PopUpDialog;
|
|
2
|
-
declare function PopUpDialog({ children, className, closePopUp, customPosition, headerIsHidden, headerText,
|
|
2
|
+
declare function PopUpDialog({ children, className, closePopUp, customPosition, headerIsHidden, headerText, isOpen, onResolve, style, tooltipText }: {
|
|
3
3
|
children: any;
|
|
4
4
|
className?: string;
|
|
5
|
-
closePopUp?:
|
|
5
|
+
closePopUp?: any;
|
|
6
6
|
customPosition?: {};
|
|
7
7
|
headerIsHidden?: boolean;
|
|
8
8
|
headerText?: string;
|
|
9
|
-
|
|
9
|
+
isOpen?: boolean;
|
|
10
|
+
onResolve?: any;
|
|
10
11
|
style?: {};
|
|
11
12
|
tooltipText?: string;
|
|
12
13
|
}, ref: any): import("react").ReactPortal;
|
|
@@ -17,8 +18,10 @@ declare namespace PopUpDialog {
|
|
|
17
18
|
export let className: any;
|
|
18
19
|
export let closePopUp: any;
|
|
19
20
|
export { POP_UP_CUSTOM_POSITION as customPosition };
|
|
21
|
+
export let isOpen: any;
|
|
20
22
|
export let headerIsHidden: any;
|
|
21
23
|
export let headerText: any;
|
|
24
|
+
export let onResolve: any;
|
|
22
25
|
export let showPopUpDialog: any;
|
|
23
26
|
export let style: any;
|
|
24
27
|
export let tooltipText: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopUpDialog.d.ts","sourceRoot":"","sources":["../../../src/lib/components/PopUpDialog/PopUpDialog.jsx"],"names":[],"mappings":";AA+BA
|
|
1
|
+
{"version":3,"file":"PopUpDialog.d.ts","sourceRoot":"","sources":["../../../src/lib/components/PopUpDialog/PopUpDialog.jsx"],"names":[],"mappings":";AA+BA;;;;;;;;;;;0CAkJC;;;;;;;;;;;;;;;;;uCAvJsC,aAAa"}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as p, jsxs as U } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as H, useCallback as x, useLayoutEffect as I, useEffect as $, forwardRef as B } from "react";
|
|
3
3
|
import l from "prop-types";
|
|
4
|
-
import
|
|
5
|
-
import { createPortal as
|
|
6
|
-
import { throttle as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { POP_UP_CUSTOM_POSITION as
|
|
11
|
-
import
|
|
4
|
+
import D from "classnames";
|
|
5
|
+
import { createPortal as F } from "react-dom";
|
|
6
|
+
import { throttle as L } from "lodash";
|
|
7
|
+
import j from "../RoundedIcon/RoundedIcon.mjs";
|
|
8
|
+
import M from "../Tooltip/Tooltip.mjs";
|
|
9
|
+
import k from "../TooltipTemplate/TextTooltipTemplate.mjs";
|
|
10
|
+
import { POP_UP_CUSTOM_POSITION as W } from "../../types.mjs";
|
|
11
|
+
import q from "../../images/close.svg.mjs";
|
|
12
12
|
/* empty css */
|
|
13
|
-
let
|
|
14
|
-
children:
|
|
15
|
-
className:
|
|
16
|
-
closePopUp: f =
|
|
17
|
-
},
|
|
13
|
+
let m = ({
|
|
14
|
+
children: E,
|
|
15
|
+
className: R = "",
|
|
16
|
+
closePopUp: f = null,
|
|
18
17
|
customPosition: i = {},
|
|
19
|
-
headerIsHidden:
|
|
18
|
+
headerIsHidden: T = !1,
|
|
20
19
|
headerText: w = "",
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
isOpen: v = !0,
|
|
21
|
+
onResolve: b = null,
|
|
22
|
+
style: u = {},
|
|
23
23
|
tooltipText: y = ""
|
|
24
24
|
}, o) => {
|
|
25
|
-
const
|
|
26
|
-
o ?? (o =
|
|
27
|
-
const
|
|
28
|
-
|
|
25
|
+
const N = H(null);
|
|
26
|
+
o ?? (o = N);
|
|
27
|
+
const S = D(
|
|
28
|
+
R,
|
|
29
29
|
"pop-up-dialog__overlay",
|
|
30
30
|
i.element && "custom-position"
|
|
31
|
-
), z =
|
|
32
|
-
f && f(),
|
|
33
|
-
}, [f]),
|
|
31
|
+
), z = x(() => {
|
|
32
|
+
f && f(), b && b();
|
|
33
|
+
}, [f, b]), h = x(() => {
|
|
34
34
|
var r;
|
|
35
35
|
if ((r = i == null ? void 0 : i.element) != null && r.current && (o != null && o.current)) {
|
|
36
|
-
const e = i.element.current.getBoundingClientRect(), t = o.current.getBoundingClientRect(), [
|
|
37
|
-
let
|
|
38
|
-
|
|
36
|
+
const e = i.element.current.getBoundingClientRect(), t = o.current.getBoundingClientRect(), [_, O] = i.position.split("-"), n = 15, a = 5, g = e.right >= t.width + n, d = window.innerWidth - e.left >= t.width + n, C = e.top > t.height + n + a, P = e.bottom + t.height + n + a <= window.innerHeight;
|
|
37
|
+
let s = O === "left" ? e.right - t.width : e.left, c;
|
|
38
|
+
_ === "top" ? c = C ? e.top - t.height - a : n : c = P ? e.bottom + a : window.innerHeight - t.height - n, i.autoVerticalPosition && (_ === "top" ? !C && P && (c = e.bottom + a) : C && !P && (c = e.top - t.height - a)), i.autoHorizontalPosition && (_ === "left" ? !g && d ? s = e.left : !g && !d && (s = n) : g && !d ? s = e.right - t.width : !g && !d && (s = window.innerWidth - t.width - n)), o.current.style.top = `${c}px`, u.left && !(i.autoHorizontalPosition && d) ? o.current.style.left = `calc(${s}px + ${u.left})` : o.current.style.left = `${s}px`;
|
|
39
39
|
}
|
|
40
|
-
}, [i,
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
}, [
|
|
40
|
+
}, [i, u.left, o]);
|
|
41
|
+
return I(() => {
|
|
42
|
+
h();
|
|
43
|
+
}, [h]), $(() => {
|
|
44
44
|
if (v) {
|
|
45
|
-
const r =
|
|
45
|
+
const r = L(h, 100, {
|
|
46
46
|
trailing: !0,
|
|
47
47
|
leading: !0
|
|
48
48
|
}), e = new ResizeObserver(r), t = o.current;
|
|
@@ -50,41 +50,43 @@ let h = ({
|
|
|
50
50
|
e.unobserve(t), window.removeEventListener("resize", r);
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
}, [
|
|
54
|
-
/* @__PURE__ */
|
|
55
|
-
!
|
|
56
|
-
w && /* @__PURE__ */
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
|
|
53
|
+
}, [h, o, v]), v ? F(
|
|
54
|
+
/* @__PURE__ */ p("div", { ref: o, className: S, style: u, children: /* @__PURE__ */ U("div", { "data-testid": "pop-up-dialog", className: "pop-up-dialog", children: [
|
|
55
|
+
!T && /* @__PURE__ */ U("div", { className: "pop-up-dialog__header", children: [
|
|
56
|
+
w && /* @__PURE__ */ p("div", { "data-testid": "pop-up-dialog-header", className: "pop-up-dialog__header-text", children: /* @__PURE__ */ p(M, { template: /* @__PURE__ */ p(k, { text: y || w }), children: /* @__PURE__ */ p("span", { children: w }) }) }),
|
|
57
|
+
/* @__PURE__ */ p(
|
|
58
|
+
j,
|
|
59
59
|
{
|
|
60
60
|
className: "pop-up-dialog__btn_close",
|
|
61
61
|
onClick: z,
|
|
62
62
|
tooltipText: "Close",
|
|
63
63
|
"data-testid": "pop-up-close-btn",
|
|
64
|
-
children: /* @__PURE__ */
|
|
64
|
+
children: /* @__PURE__ */ p(q, {})
|
|
65
65
|
}
|
|
66
66
|
)
|
|
67
67
|
] }),
|
|
68
|
-
|
|
68
|
+
E
|
|
69
69
|
] }) }),
|
|
70
70
|
document.getElementById("overlay_container")
|
|
71
71
|
) : null;
|
|
72
72
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
m = B(m);
|
|
74
|
+
m.displayName = "PopUpDialog";
|
|
75
|
+
m.propTypes = {
|
|
76
76
|
children: l.node.isRequired,
|
|
77
77
|
className: l.string,
|
|
78
78
|
closePopUp: l.func,
|
|
79
|
-
customPosition:
|
|
79
|
+
customPosition: W,
|
|
80
|
+
isOpen: l.bool,
|
|
80
81
|
headerIsHidden: l.bool,
|
|
81
82
|
headerText: l.string,
|
|
83
|
+
onResolve: l.func,
|
|
82
84
|
showPopUpDialog: l.bool,
|
|
83
85
|
style: l.object,
|
|
84
86
|
tooltipText: l.string
|
|
85
87
|
};
|
|
86
|
-
const
|
|
88
|
+
const ie = m;
|
|
87
89
|
export {
|
|
88
|
-
|
|
90
|
+
ie as default
|
|
89
91
|
};
|
|
90
92
|
//# sourceMappingURL=PopUpDialog.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopUpDialog.mjs","sources":["../../../src/lib/components/PopUpDialog/PopUpDialog.jsx"],"sourcesContent":["/*\nCopyright 2022 Iguazio Systems Ltd.\nLicensed under the Apache License, Version 2.0 (the \"License\") with\nan addition restriction as set forth herein. You may not use this\nfile except in compliance with the License. You may obtain a copy of\nthe License at http://www.apache.org/licenses/LICENSE-2.0.\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied. See the License for the specific language governing\npermissions and limitations under the License.\nIn addition, you may not use the software for any purposes that are\nillegal under applicable law, and the grant of the foregoing license\nunder the Apache 2.0 license is conditioned upon your compliance with\nsuch restriction.\n*/\nimport React, { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport PropTypes from 'prop-types'\nimport classnames from 'classnames'\nimport { createPortal } from 'react-dom'\nimport { throttle } from 'lodash'\n\nimport RoundedIcon from '../RoundedIcon/RoundedIcon'\nimport Tooltip from '../Tooltip/Tooltip'\nimport TextTooltipTemplate from '../TooltipTemplate/TextTooltipTemplate'\n\nimport { POP_UP_CUSTOM_POSITION } from '../../types'\nimport CloseIcon from '../../images/close.svg?react'\n\nimport './popUpDialog.scss'\n\nlet PopUpDialog = (\n {\n children,\n className = '',\n closePopUp = () => {},\n customPosition = {},\n headerIsHidden = false,\n headerText = '',\n showPopUpDialog = true,\n style = {},\n tooltipText = ''\n },\n ref\n) => {\n const [showPopUp, setShowPopUp] = useState(showPopUpDialog ?? true)\n const popUpOverlayRef = useRef(null)\n ref ??= popUpOverlayRef\n const popUpClassNames = classnames(\n className,\n 'pop-up-dialog__overlay',\n customPosition.element && 'custom-position'\n )\n\n const handleClosePopUp = useCallback(() => {\n closePopUp && closePopUp()\n setShowPopUp(false)\n }, [closePopUp])\n\n const calculateCustomPopUpPosition = useCallback(() => {\n if (customPosition?.element?.current && ref?.current) {\n const elementRect = customPosition.element.current.getBoundingClientRect()\n const popUpRect = ref.current.getBoundingClientRect()\n const [verticalPosition, horizontalPosition] = customPosition.position.split('-')\n const popupMargin = 15\n const elementMargin = 5\n const isEnoughSpaceFromLeft = elementRect.right >= popUpRect.width + popupMargin\n const isEnoughSpaceFromRight =\n window.innerWidth - elementRect.left >= popUpRect.width + popupMargin\n const isEnoughSpaceFromTop = elementRect.top > popUpRect.height + popupMargin + elementMargin\n const isEnoughSpaceFromBottom =\n elementRect.bottom + popUpRect.height + popupMargin + elementMargin <= window.innerHeight\n let leftPosition =\n horizontalPosition === 'left' ? elementRect.right - popUpRect.width : elementRect.left\n\n let topPosition\n\n if (verticalPosition === 'top') {\n topPosition = isEnoughSpaceFromTop\n ? elementRect.top - popUpRect.height - elementMargin\n : popupMargin\n } else {\n topPosition = isEnoughSpaceFromBottom\n ? elementRect.bottom + elementMargin\n : window.innerHeight - popUpRect.height - popupMargin\n }\n\n if (customPosition.autoVerticalPosition) {\n if (verticalPosition === 'top') {\n if (!isEnoughSpaceFromTop && isEnoughSpaceFromBottom) {\n topPosition = elementRect.bottom + elementMargin\n }\n } else {\n if (isEnoughSpaceFromTop && !isEnoughSpaceFromBottom) {\n topPosition = elementRect.top - popUpRect.height - elementMargin\n }\n }\n }\n\n if (customPosition.autoHorizontalPosition) {\n if (verticalPosition === 'left') {\n if (!isEnoughSpaceFromLeft && isEnoughSpaceFromRight) {\n leftPosition = elementRect.left\n } else if (!isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = popupMargin\n }\n } else {\n if (isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = elementRect.right - popUpRect.width\n } else if (!isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = window.innerWidth - popUpRect.width - popupMargin\n }\n }\n }\n\n ref.current.style.top = `${topPosition}px`\n\n if (style.left && !(customPosition.autoHorizontalPosition && isEnoughSpaceFromRight)) {\n ref.current.style.left = `calc(${leftPosition}px + ${style.left})`\n } else {\n ref.current.style.left = `${leftPosition}px`\n }\n }\n }, [customPosition, style.left, ref])\n\n useLayoutEffect(() => {\n calculateCustomPopUpPosition()\n }, [calculateCustomPopUpPosition])\n\n useEffect(() => {\n if (showPopUp) {\n const throttledCalculatedCustomPopUpPosition = throttle(calculateCustomPopUpPosition, 100, {\n trailing: true,\n leading: true\n })\n const popupObserver = new ResizeObserver(throttledCalculatedCustomPopUpPosition)\n const popupElement = ref.current\n\n popupObserver.observe(popupElement)\n window.addEventListener('resize', throttledCalculatedCustomPopUpPosition)\n\n return () => {\n popupObserver.unobserve(popupElement)\n window.removeEventListener('resize', throttledCalculatedCustomPopUpPosition)\n }\n }\n }, [calculateCustomPopUpPosition, ref, showPopUp])\n\n return showPopUp\n ? createPortal(\n <div ref={ref} className={popUpClassNames} style={style}>\n <div data-testid=\"pop-up-dialog\" className=\"pop-up-dialog\">\n {!headerIsHidden && (\n <div className=\"pop-up-dialog__header\">\n {headerText && (\n <div data-testid=\"pop-up-dialog-header\" className=\"pop-up-dialog__header-text\">\n <Tooltip template={<TextTooltipTemplate text={tooltipText || headerText} />}>\n <span>{headerText}</span>\n </Tooltip>\n </div>\n )}\n <RoundedIcon\n className=\"pop-up-dialog__btn_close\"\n onClick={handleClosePopUp}\n tooltipText=\"Close\"\n data-testid=\"pop-up-close-btn\"\n >\n <CloseIcon />\n </RoundedIcon>\n </div>\n )}\n {children}\n </div>\n </div>,\n document.getElementById('overlay_container')\n )\n : null\n}\n\nPopUpDialog = forwardRef(PopUpDialog)\n\nPopUpDialog.displayName = 'PopUpDialog'\n\nPopUpDialog.propTypes = {\n children: PropTypes.node.isRequired,\n className: PropTypes.string,\n closePopUp: PropTypes.func,\n customPosition: POP_UP_CUSTOM_POSITION,\n headerIsHidden: PropTypes.bool,\n headerText: PropTypes.string,\n showPopUpDialog: PropTypes.bool,\n style: PropTypes.object,\n tooltipText: PropTypes.string\n}\n\nexport default PopUpDialog\n"],"names":["PopUpDialog","children","className","closePopUp","customPosition","headerIsHidden","headerText","showPopUpDialog","style","tooltipText","ref","showPopUp","setShowPopUp","useState","popUpOverlayRef","useRef","popUpClassNames","classnames","handleClosePopUp","useCallback","calculateCustomPopUpPosition","_a","elementRect","popUpRect","verticalPosition","horizontalPosition","popupMargin","elementMargin","isEnoughSpaceFromLeft","isEnoughSpaceFromRight","isEnoughSpaceFromTop","isEnoughSpaceFromBottom","leftPosition","topPosition","useLayoutEffect","useEffect","throttledCalculatedCustomPopUpPosition","throttle","popupObserver","popupElement","createPortal","jsx","jsxs","Tooltip","TextTooltipTemplate","RoundedIcon","CloseIcon","forwardRef","PropTypes","POP_UP_CUSTOM_POSITION","PopUpDialog$1"],"mappings":";;;;;;;;;;;;AA+BA,IAAIA,IAAc,CAChB;AAAA,EACE,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,YAAAC,IAAa,MAAM;AAAA,EAAC;AAAA,EACpB,gBAAAC,IAAiB,CAAC;AAAA,EAClB,gBAAAC,IAAiB;AAAA,EACjB,YAAAC,IAAa;AAAA,EACb,iBAAAC,IAAkB;AAAA,EAClB,OAAAC,IAAQ,CAAC;AAAA,EACT,aAAAC,IAAc;AAChB,GACAC,MACG;AACH,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAASN,KAAmB,EAAI,GAC5DO,IAAkBC,EAAO,IAAI;AAC3B,EAAAL,UAAAI;AACR,QAAME,IAAkBC;AAAA,IACtBf;AAAA,IACA;AAAA,IACAE,EAAe,WAAW;AAAA,EAC5B,GAEMc,IAAmBC,EAAY,MAAM;AACzC,I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AAAA,YACZ,eAAY;AAAA,YAEZ,4BAAC4B,GAAU,CAAA,CAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACb,GACF;AAAA,MAED7C;AAAA,IAAA,EAAA,CACH,EACF,CAAA;AAAA,IACA,SAAS,eAAe,mBAAmB;AAAA,EAAA,IAE7C;AACN;AAEAD,IAAc+C,EAAW/C,CAAW;AAEpCA,EAAY,cAAc;AAE1BA,EAAY,YAAY;AAAA,EACtB,UAAUgD,EAAU,KAAK;AAAA,EACzB,WAAWA,EAAU;AAAA,EACrB,YAAYA,EAAU;AAAA,EACtB,gBAAgBC;AAAA,EAChB,gBAAgBD,EAAU;AAAA,EAC1B,YAAYA,EAAU;AAAA,EACtB,iBAAiBA,EAAU;AAAA,EAC3B,OAAOA,EAAU;AAAA,EACjB,aAAaA,EAAU;AACzB;AAEA,MAAAE,KAAelD;"}
|
|
1
|
+
{"version":3,"file":"PopUpDialog.mjs","sources":["../../../src/lib/components/PopUpDialog/PopUpDialog.jsx"],"sourcesContent":["/*\nCopyright 2022 Iguazio Systems Ltd.\nLicensed under the Apache License, Version 2.0 (the \"License\") with\nan addition restriction as set forth herein. You may not use this\nfile except in compliance with the License. You may obtain a copy of\nthe License at http://www.apache.org/licenses/LICENSE-2.0.\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied. See the License for the specific language governing\npermissions and limitations under the License.\nIn addition, you may not use the software for any purposes that are\nillegal under applicable law, and the grant of the foregoing license\nunder the Apache 2.0 license is conditioned upon your compliance with\nsuch restriction.\n*/\nimport React, { forwardRef, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport PropTypes from 'prop-types'\nimport classnames from 'classnames'\nimport { createPortal } from 'react-dom'\nimport { throttle } from 'lodash'\n\nimport RoundedIcon from '../RoundedIcon/RoundedIcon'\nimport Tooltip from '../Tooltip/Tooltip'\nimport TextTooltipTemplate from '../TooltipTemplate/TextTooltipTemplate'\n\nimport { POP_UP_CUSTOM_POSITION } from '../../types'\nimport CloseIcon from '../../images/close.svg?react'\n\nimport './popUpDialog.scss'\n\nlet PopUpDialog = (\n {\n children,\n className = '',\n closePopUp = null,\n customPosition = {},\n headerIsHidden = false,\n headerText = '',\n isOpen = true,\n onResolve = null,\n style = {},\n tooltipText = ''\n },\n ref\n) => {\n const popUpOverlayRef = useRef(null)\n ref ??= popUpOverlayRef\n const popUpClassNames = classnames(\n className,\n 'pop-up-dialog__overlay',\n customPosition.element && 'custom-position'\n )\n\n const handleClosePopUp = useCallback(() => {\n closePopUp && closePopUp()\n onResolve && onResolve()\n }, [closePopUp, onResolve])\n\n const calculateCustomPopUpPosition = useCallback(() => {\n if (customPosition?.element?.current && ref?.current) {\n const elementRect = customPosition.element.current.getBoundingClientRect()\n const popUpRect = ref.current.getBoundingClientRect()\n const [verticalPosition, horizontalPosition] = customPosition.position.split('-')\n const popupMargin = 15\n const elementMargin = 5\n const isEnoughSpaceFromLeft = elementRect.right >= popUpRect.width + popupMargin\n const isEnoughSpaceFromRight =\n window.innerWidth - elementRect.left >= popUpRect.width + popupMargin\n const isEnoughSpaceFromTop = elementRect.top > popUpRect.height + popupMargin + elementMargin\n const isEnoughSpaceFromBottom =\n elementRect.bottom + popUpRect.height + popupMargin + elementMargin <= window.innerHeight\n let leftPosition =\n horizontalPosition === 'left' ? elementRect.right - popUpRect.width : elementRect.left\n\n let topPosition\n\n if (verticalPosition === 'top') {\n topPosition = isEnoughSpaceFromTop\n ? elementRect.top - popUpRect.height - elementMargin\n : popupMargin\n } else {\n topPosition = isEnoughSpaceFromBottom\n ? elementRect.bottom + elementMargin\n : window.innerHeight - popUpRect.height - popupMargin\n }\n\n if (customPosition.autoVerticalPosition) {\n if (verticalPosition === 'top') {\n if (!isEnoughSpaceFromTop && isEnoughSpaceFromBottom) {\n topPosition = elementRect.bottom + elementMargin\n }\n } else {\n if (isEnoughSpaceFromTop && !isEnoughSpaceFromBottom) {\n topPosition = elementRect.top - popUpRect.height - elementMargin\n }\n }\n }\n\n if (customPosition.autoHorizontalPosition) {\n if (verticalPosition === 'left') {\n if (!isEnoughSpaceFromLeft && isEnoughSpaceFromRight) {\n leftPosition = elementRect.left\n } else if (!isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = popupMargin\n }\n } else {\n if (isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = elementRect.right - popUpRect.width\n } else if (!isEnoughSpaceFromLeft && !isEnoughSpaceFromRight) {\n leftPosition = window.innerWidth - popUpRect.width - popupMargin\n }\n }\n }\n\n ref.current.style.top = `${topPosition}px`\n\n if (style.left && !(customPosition.autoHorizontalPosition && isEnoughSpaceFromRight)) {\n ref.current.style.left = `calc(${leftPosition}px + ${style.left})`\n } else {\n ref.current.style.left = `${leftPosition}px`\n }\n }\n }, [customPosition, style.left, ref])\n\n useLayoutEffect(() => {\n calculateCustomPopUpPosition()\n }, [calculateCustomPopUpPosition])\n\n useEffect(() => {\n if (isOpen) {\n const throttledCalculatedCustomPopUpPosition = throttle(calculateCustomPopUpPosition, 100, {\n trailing: true,\n leading: true\n })\n const popupObserver = new ResizeObserver(throttledCalculatedCustomPopUpPosition)\n const popupElement = ref.current\n\n popupObserver.observe(popupElement)\n window.addEventListener('resize', throttledCalculatedCustomPopUpPosition)\n\n return () => {\n popupObserver.unobserve(popupElement)\n window.removeEventListener('resize', throttledCalculatedCustomPopUpPosition)\n }\n }\n }, [calculateCustomPopUpPosition, ref, isOpen])\n\n return isOpen\n ? createPortal(\n <div ref={ref} className={popUpClassNames} style={style}>\n <div data-testid=\"pop-up-dialog\" className=\"pop-up-dialog\">\n {!headerIsHidden && (\n <div className=\"pop-up-dialog__header\">\n {headerText && (\n <div data-testid=\"pop-up-dialog-header\" className=\"pop-up-dialog__header-text\">\n <Tooltip template={<TextTooltipTemplate text={tooltipText || headerText} />}>\n <span>{headerText}</span>\n </Tooltip>\n </div>\n )}\n <RoundedIcon\n className=\"pop-up-dialog__btn_close\"\n onClick={handleClosePopUp}\n tooltipText=\"Close\"\n data-testid=\"pop-up-close-btn\"\n >\n <CloseIcon />\n </RoundedIcon>\n </div>\n )}\n {children}\n </div>\n </div>,\n document.getElementById('overlay_container')\n )\n : null\n}\n\nPopUpDialog = forwardRef(PopUpDialog)\n\nPopUpDialog.displayName = 'PopUpDialog'\n\nPopUpDialog.propTypes = {\n children: PropTypes.node.isRequired,\n className: PropTypes.string,\n closePopUp: PropTypes.func,\n customPosition: POP_UP_CUSTOM_POSITION,\n isOpen: PropTypes.bool,\n headerIsHidden: PropTypes.bool,\n headerText: PropTypes.string,\n onResolve: PropTypes.func,\n showPopUpDialog: PropTypes.bool,\n style: PropTypes.object,\n tooltipText: PropTypes.string\n}\n\nexport default PopUpDialog\n"],"names":["PopUpDialog","children","className","closePopUp","customPosition","headerIsHidden","headerText","isOpen","onResolve","style","tooltipText","ref","popUpOverlayRef","useRef","popUpClassNames","classnames","handleClosePopUp","useCallback","calculateCustomPopUpPosition","_a","elementRect","popUpRect","verticalPosition","horizontalPosition","popupMargin","elementMargin","isEnoughSpaceFromLeft","isEnoughSpaceFromRight","isEnoughSpaceFromTop","isEnoughSpaceFromBottom","leftPosition","topPosition","useLayoutEffect","useEffect","throttledCalculatedCustomPopUpPosition","throttle","popupObserver","popupElement","createPortal","jsx","jsxs","Tooltip","TextTooltipTemplate","RoundedIcon","CloseIcon","forwardRef","PropTypes","POP_UP_CUSTOM_POSITION","PopUpDialog$1"],"mappings":";;;;;;;;;;;;AA+BA,IAAIA,IAAc,CAChB;AAAA,EACE,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,YAAAC,IAAa;AAAA,EACb,gBAAAC,IAAiB,CAAC;AAAA,EAClB,gBAAAC,IAAiB;AAAA,EACjB,YAAAC,IAAa;AAAA,EACb,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAAA,EACZ,OAAAC,IAAQ,CAAC;AAAA,EACT,a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AAA,4BAAWC,GAAoB,EAAA,MAAMhC,KAAeJ,EAAY,CAAA,GACvE,4BAAC,QAAM,EAAA,UAAAA,GAAW,GACpB,EACF,CAAA;AAAA,QAEF,gBAAAiC;AAAA,UAACI;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,SAAS3B;AAAA,YACT,aAAY;AAAA,YACZ,eAAY;AAAA,YAEZ,4BAAC4B,GAAU,CAAA,CAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACb,GACF;AAAA,MAED3C;AAAA,IAAA,EAAA,CACH,EACF,CAAA;AAAA,IACA,SAAS,eAAe,mBAAmB;AAAA,EAAA,IAE7C;AACN;AAEAD,IAAc6C,EAAW7C,CAAW;AAEpCA,EAAY,cAAc;AAE1BA,EAAY,YAAY;AAAA,EACtB,UAAU8C,EAAU,KAAK;AAAA,EACzB,WAAWA,EAAU;AAAA,EACrB,YAAYA,EAAU;AAAA,EACtB,gBAAgBC;AAAA,EAChB,QAAQD,EAAU;AAAA,EAClB,gBAAgBA,EAAU;AAAA,EAC1B,YAAYA,EAAU;AAAA,EACtB,WAAWA,EAAU;AAAA,EACrB,iBAAiBA,EAAU;AAAA,EAC3B,OAAOA,EAAU;AAAA,EACjB,aAAaA,EAAU;AACzB;AAEA,MAAAE,KAAehD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iguazio.dashboard-react-controls",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Collection of resources (such as CSS styles, fonts and images) and ReactJS 17.x components to share among different Iguazio React repos.",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.mjs",
|