@onewelcome/react-lib-components 1.9.0 → 1.9.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.
- package/dist/Notifications/BaseModal/BaseModal.d.ts +1 -1
- package/dist/_BaseStyling_/BaseStyling.d.ts +1 -0
- package/dist/hooks/useGetDomRoot.d.ts +3 -0
- package/dist/react-lib-components.cjs.development.js +55 -18
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +56 -19
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/ContextMenu/ContextMenu.tsx +18 -3
- package/src/Notifications/BaseModal/BaseModal.tsx +48 -41
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +7 -4
- package/src/Tooltip/Tooltip.tsx +9 -3
- package/src/_BaseStyling_/BaseStyling.tsx +2 -0
- package/src/hooks/useGetDomRoot.ts +40 -0
- package/src/hooks/usePosition.ts +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect, Fragment,
|
|
1
|
+
import React, { useState, useRef, useEffect, Fragment, createRef, useCallback, useLayoutEffect, createContext, useContext, useReducer, useMemo } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
|
|
4
4
|
function _extends() {
|
|
@@ -39,6 +39,7 @@ var BaseStyling = function BaseStyling(_ref) {
|
|
|
39
39
|
colorPrimary700: "#020B59",
|
|
40
40
|
colorPrimary900: "#01041E",
|
|
41
41
|
colorBlueGrey25: "#F7F7F9",
|
|
42
|
+
colorBlueGrey50: "#EEEFF3",
|
|
42
43
|
colorBlueGrey100: "#DEDEE6",
|
|
43
44
|
colorBlueGrey200: "#BCBECE",
|
|
44
45
|
colorBlueGrey400: "#797D9C",
|
|
@@ -604,8 +605,8 @@ var usePosition = function usePosition(providedConfigObject) {
|
|
|
604
605
|
});
|
|
605
606
|
};
|
|
606
607
|
var calculatePosition = useDebouncedCallback(function () {
|
|
607
|
-
var _configObject$relativ;
|
|
608
|
-
if (!((_configObject$relativ = configObject.relativeElement) != null && _configObject$relativ.current)) return;
|
|
608
|
+
var _configObject$relativ, _configObject$element;
|
|
609
|
+
if (!((_configObject$relativ = configObject.relativeElement) != null && _configObject$relativ.current) || !((_configObject$element = configObject.elementToBePositioned) != null && _configObject$element.current)) return;
|
|
609
610
|
var relativeElRect = configObject.relativeElement.current.getBoundingClientRect();
|
|
610
611
|
var elementToBePositionedDimensions = {
|
|
611
612
|
height: configObject.elementToBePositioned.current.offsetHeight,
|
|
@@ -719,6 +720,27 @@ var useBodyClick = function useBodyClick(checkFunction, callbackFunction, depend
|
|
|
719
720
|
}, [dependingStateVariable]);
|
|
720
721
|
};
|
|
721
722
|
|
|
723
|
+
var useGetDomRoot = function useGetDomRoot(passedDomRoot, relativeElement) {
|
|
724
|
+
var _useState = useState(document.body),
|
|
725
|
+
root = _useState[0],
|
|
726
|
+
setRoot = _useState[1];
|
|
727
|
+
useEffect(function () {
|
|
728
|
+
if (relativeElement && relativeElement.current && !passedDomRoot) {
|
|
729
|
+
var closestBaseStylingWrapper = relativeElement.current.closest(".basestyling-wrapper");
|
|
730
|
+
if (closestBaseStylingWrapper) {
|
|
731
|
+
setRoot(closestBaseStylingWrapper);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
} else if (passedDomRoot) {
|
|
735
|
+
setRoot(passedDomRoot);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
}, [relativeElement]);
|
|
739
|
+
return {
|
|
740
|
+
root: root
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
|
|
722
744
|
var _excluded$U = ["trigger", "children", "decorativeElement", "id", "show", "onShow", "onClose", "placement", "offset", "transformOrigin", "debounceAmount", "domRoot", "popoverProps"];
|
|
723
745
|
var ContextMenuComponent = function ContextMenuComponent(_ref, ref) {
|
|
724
746
|
var trigger = _ref.trigger,
|
|
@@ -747,11 +769,11 @@ var ContextMenuComponent = function ContextMenuComponent(_ref, ref) {
|
|
|
747
769
|
vertical: "top"
|
|
748
770
|
} : _ref$transformOrigin,
|
|
749
771
|
debounceAmount = _ref.debounceAmount,
|
|
750
|
-
|
|
751
|
-
domRoot = _ref$domRoot === void 0 ? document.body : _ref$domRoot,
|
|
772
|
+
domRoot = _ref.domRoot,
|
|
752
773
|
popoverProps = _ref.popoverProps,
|
|
753
774
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$U);
|
|
754
775
|
var anchorEl = useRef(null);
|
|
776
|
+
var wrappingDivRef = ref || createRef();
|
|
755
777
|
var _useState = useState(show),
|
|
756
778
|
showContextMenu = _useState[0],
|
|
757
779
|
setShowContextMenu = _useState[1];
|
|
@@ -769,6 +791,8 @@ var ContextMenuComponent = function ContextMenuComponent(_ref, ref) {
|
|
|
769
791
|
setShouldClick = _useState5[1]; /** We need this, because whenever we use the arrow keys to select the contextmenu item, and we focus the currently selected item it fires the "click" listener in ContextMenuItem component. Instead, we only want this to fire if we press "enter" or "spacebar" so we set this to true whenever that is the case, and back to false when it has been executed. */
|
|
770
792
|
var _useState6 = useState(React.Children.count(children)),
|
|
771
793
|
childrenCount = _useState6[0];
|
|
794
|
+
var _useGetDomRoot = useGetDomRoot(domRoot, wrappingDivRef),
|
|
795
|
+
root = _useGetDomRoot.root;
|
|
772
796
|
if (!id) {
|
|
773
797
|
throw new Error("You need to provide an ID to the context menu");
|
|
774
798
|
}
|
|
@@ -866,8 +890,11 @@ var ContextMenuComponent = function ContextMenuComponent(_ref, ref) {
|
|
|
866
890
|
var onOutOfViewHandler = useCallback(function () {
|
|
867
891
|
setShowContextMenu(false);
|
|
868
892
|
}, []);
|
|
893
|
+
if (!root) {
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
869
896
|
return React.createElement("div", _extends({}, rest, {
|
|
870
|
-
ref:
|
|
897
|
+
ref: wrappingDivRef,
|
|
871
898
|
onKeyDown: onArrowNavigation,
|
|
872
899
|
className: modules_846e6042["context-menu"]
|
|
873
900
|
}), renderTrigger(), createPortal(React.createElement(Popover, _extends({}, popoverProps, {
|
|
@@ -885,7 +912,7 @@ var ContextMenuComponent = function ContextMenuComponent(_ref, ref) {
|
|
|
885
912
|
id: id + "-menu",
|
|
886
913
|
"aria-describedby": id,
|
|
887
914
|
role: "menu"
|
|
888
|
-
}, renderChildren())),
|
|
915
|
+
}, renderChildren())), root));
|
|
889
916
|
};
|
|
890
917
|
var ContextMenu = /*#__PURE__*/React.forwardRef(ContextMenuComponent);
|
|
891
918
|
|
|
@@ -1463,8 +1490,7 @@ var TooltipComponent = function TooltipComponent(_ref, ref) {
|
|
|
1463
1490
|
offset = _ref$offset === void 0 ? defaultPosition.offset : _ref$offset,
|
|
1464
1491
|
_ref$transformOrigin = _ref.transformOrigin,
|
|
1465
1492
|
transformOrigin = _ref$transformOrigin === void 0 ? defaultPosition.transformOrigin : _ref$transformOrigin,
|
|
1466
|
-
|
|
1467
|
-
domRoot = _ref$domRoot === void 0 ? document.body : _ref$domRoot,
|
|
1493
|
+
domRoot = _ref.domRoot,
|
|
1468
1494
|
label = _ref.label,
|
|
1469
1495
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$K);
|
|
1470
1496
|
var _useState = useState(generateID()),
|
|
@@ -1472,6 +1498,9 @@ var TooltipComponent = function TooltipComponent(_ref, ref) {
|
|
|
1472
1498
|
var _useState2 = useState(false),
|
|
1473
1499
|
visible = _useState2[0],
|
|
1474
1500
|
setVisible = _useState2[1];
|
|
1501
|
+
var wrappingDivRef = ref || createRef();
|
|
1502
|
+
var _useGetDomRoot = useGetDomRoot(domRoot, wrappingDivRef),
|
|
1503
|
+
root = _useGetDomRoot.root;
|
|
1475
1504
|
var relativeElement = useRef(null);
|
|
1476
1505
|
var elementToBePositioned = useRef(null);
|
|
1477
1506
|
var _usePosition = usePosition({
|
|
@@ -1528,7 +1557,7 @@ var TooltipComponent = function TooltipComponent(_ref, ref) {
|
|
|
1528
1557
|
}, label);
|
|
1529
1558
|
};
|
|
1530
1559
|
return React.createElement("div", _extends({}, rest, {
|
|
1531
|
-
ref:
|
|
1560
|
+
ref: wrappingDivRef,
|
|
1532
1561
|
className: modules_16974fb0.wrapper + " " + (className != null ? className : "")
|
|
1533
1562
|
}), renderChildren(), React.createElement("div", {
|
|
1534
1563
|
className: "" + modules_16974fb0["tooltip-wrapper"]
|
|
@@ -1554,7 +1583,7 @@ var TooltipComponent = function TooltipComponent(_ref, ref) {
|
|
|
1554
1583
|
"aria-hidden": !visible,
|
|
1555
1584
|
id: identifier,
|
|
1556
1585
|
className: modules_16974fb0.tooltip + " " + (visible ? modules_16974fb0.visible : "")
|
|
1557
|
-
}, children),
|
|
1586
|
+
}, children), root)));
|
|
1558
1587
|
};
|
|
1559
1588
|
var Tooltip = /*#__PURE__*/React.forwardRef(TooltipComponent);
|
|
1560
1589
|
|
|
@@ -2454,10 +2483,12 @@ var BaseModalComponent = function BaseModalComponent(_ref, ref) {
|
|
|
2454
2483
|
_ref$forceContainerOp = _ref.forceContainerOpen,
|
|
2455
2484
|
forceContainerOpen = _ref$forceContainerOp === void 0 ? false : _ref$forceContainerOp,
|
|
2456
2485
|
zIndex = _ref.zIndex,
|
|
2457
|
-
|
|
2458
|
-
domRoot = _ref$domRoot === void 0 ? document.body : _ref$domRoot,
|
|
2486
|
+
domRoot = _ref.domRoot,
|
|
2459
2487
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$B);
|
|
2460
2488
|
useSetBodyScroll(open);
|
|
2489
|
+
var wrappingDivRef = useRef(null);
|
|
2490
|
+
var _useGetDomRoot = useGetDomRoot(domRoot, wrappingDivRef),
|
|
2491
|
+
root = _useGetDomRoot.root;
|
|
2461
2492
|
var handleEscKeyPress = function handleEscKeyPress(event) {
|
|
2462
2493
|
if (!disableEscapeKeyDown && event.key === "Escape") {
|
|
2463
2494
|
event.stopPropagation();
|
|
@@ -2467,7 +2498,9 @@ var BaseModalComponent = function BaseModalComponent(_ref, ref) {
|
|
|
2467
2498
|
var handleBackdropClick = function handleBackdropClick() {
|
|
2468
2499
|
return !disableBackdrop && onClose && onClose();
|
|
2469
2500
|
};
|
|
2470
|
-
return
|
|
2501
|
+
return React.createElement("div", {
|
|
2502
|
+
ref: wrappingDivRef
|
|
2503
|
+
}, createPortal(React.createElement("div", _extends({}, rest, {
|
|
2471
2504
|
ref: ref,
|
|
2472
2505
|
id: id,
|
|
2473
2506
|
className: modules_cf1b230e["modal"] + " " + (open ? modules_cf1b230e["visible"] : "") + " " + className,
|
|
@@ -2497,7 +2530,7 @@ var BaseModalComponent = function BaseModalComponent(_ref, ref) {
|
|
|
2497
2530
|
zIndex: zIndex && zIndex + 1
|
|
2498
2531
|
},
|
|
2499
2532
|
className: modules_cf1b230e["container"] + " " + ((_containerProps$class2 = containerProps == null ? void 0 : containerProps.className) != null ? _containerProps$class2 : "")
|
|
2500
|
-
}), children)),
|
|
2533
|
+
}), children)), root));
|
|
2501
2534
|
};
|
|
2502
2535
|
var BaseModal = /*#__PURE__*/React.forwardRef(BaseModalComponent);
|
|
2503
2536
|
|
|
@@ -3067,13 +3100,15 @@ var SnackbarProvider = function SnackbarProvider(_temp) {
|
|
|
3067
3100
|
} : _ref$autoHideDuration,
|
|
3068
3101
|
_ref$stackSize = _ref.stackSize,
|
|
3069
3102
|
stackSize = _ref$stackSize === void 0 ? 3 : _ref$stackSize,
|
|
3070
|
-
|
|
3071
|
-
domRoot = _ref$domRoot === void 0 ? document.body : _ref$domRoot,
|
|
3103
|
+
domRoot = _ref.domRoot,
|
|
3072
3104
|
children = _ref.children,
|
|
3073
3105
|
className = _ref.className;
|
|
3074
3106
|
var _useState = useState([]),
|
|
3075
3107
|
snackbars = _useState[0],
|
|
3076
3108
|
setSnackbars = _useState[1];
|
|
3109
|
+
var wrappingDivRef = useRef(null);
|
|
3110
|
+
var _useGetDomRoot = useGetDomRoot(domRoot, wrappingDivRef),
|
|
3111
|
+
root = _useGetDomRoot.root;
|
|
3077
3112
|
var addSnackbar = function addSnackbar(item) {
|
|
3078
3113
|
setSnackbars(function (items) {
|
|
3079
3114
|
return [].concat(items, [item]);
|
|
@@ -3151,7 +3186,7 @@ var SnackbarProvider = function SnackbarProvider(_temp) {
|
|
|
3151
3186
|
var snackbarPortal = createPortal(React.createElement(SnackbarContainer, {
|
|
3152
3187
|
placement: placement,
|
|
3153
3188
|
className: className
|
|
3154
|
-
}, snackbarList),
|
|
3189
|
+
}, snackbarList), root);
|
|
3155
3190
|
return React.createElement(SnackbarContextProvider, {
|
|
3156
3191
|
initialState: {
|
|
3157
3192
|
enqueueSnackbar: enqueueSnackbar,
|
|
@@ -3160,7 +3195,9 @@ var SnackbarProvider = function SnackbarProvider(_temp) {
|
|
|
3160
3195
|
setSnackbarHeight: setSnackbarHeight,
|
|
3161
3196
|
snackbars: snackbars
|
|
3162
3197
|
}
|
|
3163
|
-
}, children,
|
|
3198
|
+
}, children, React.createElement("div", {
|
|
3199
|
+
ref: wrappingDivRef
|
|
3200
|
+
}, snackbarPortal));
|
|
3164
3201
|
};
|
|
3165
3202
|
|
|
3166
3203
|
var css$p = ".Checkbox_module_checkboxWrapper__0342c60f{position:relative}.Checkbox_module_checkboxWrapper__0342c60f+.Checkbox_module_checkboxWrapper__0342c60f{margin-top:1.25rem}.Checkbox_module_checkboxContainer__0342c60f{align-items:center;display:flex}.Checkbox_module_checkboxContainer__0342c60f label{display:inline-block;font-family:var(--font-family);font-size:var(--font-size);margin-left:.5rem;user-select:none}.Checkbox_module_checkboxList__0342c60f{list-style:none;margin:1.25rem 0 0 1.75rem;padding:0}.Checkbox_module_checkboxList__0342c60f li+li{margin-top:1.25rem}.Checkbox_module_nativeInput__0342c60f{height:1.25rem;left:0;margin:0;opacity:0;position:absolute;top:0;width:1.25rem}.Checkbox_module_nativeInput__0342c60f:checked+*{color:var(--color-primary)}.Checkbox_module_nativeInput__0342c60f:focus-visible+*{border-radius:2px;outline:1px solid var(--color-focus);outline-offset:1px}.Checkbox_module_nativeInput__0342c60f.Checkbox_module_error__0342c60f:focus-visible+*{outline-color:var(--color-error)}.Checkbox_module_input__0342c60f{font-size:1.25rem;pointer-events:none}.Checkbox_module_disabled__0342c60f{color:var(--disabled)}";
|