widenarrow-ui 1.1.102 → 1.1.105
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/lib/components/DropDown/DropDown.types.d.ts +1 -0
- package/lib/components/DropDown/useHandleClickOutside.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +45 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +45 -28
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DropDown/DropDown.stories.tsx +1 -10
- package/src/components/DropDown/DropDown.tsx +59 -52
- package/src/components/DropDown/DropDown.types.ts +1 -0
- package/src/components/DropDown/useHandleClickOutside.ts +19 -4
|
@@ -2,5 +2,5 @@ import { RefObject } from 'react';
|
|
|
2
2
|
type UseHandleClickOutsideReturn = {
|
|
3
3
|
ref: RefObject<HTMLDivElement>;
|
|
4
4
|
};
|
|
5
|
-
export default function useHandleClickOutside(callback: (...args: unknown[]) => void): UseHandleClickOutsideReturn;
|
|
5
|
+
export default function useHandleClickOutside(callback: (...args: unknown[]) => void, portalRef?: RefObject<HTMLDivElement>): UseHandleClickOutsideReturn;
|
|
6
6
|
export {};
|
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -710,7 +710,7 @@ var AppColors;
|
|
|
710
710
|
var styles$s = {"body":"ToolTip-module_EfvT16","container":"ToolTip-module_rxb-Ce","withEllipsis":"ToolTip-module_vea-tI"};
|
|
711
711
|
|
|
712
712
|
var s$s = classNames.bind(styles$s);
|
|
713
|
-
var htmlRootNode = document.getElementById('root');
|
|
713
|
+
var htmlRootNode$1 = document.getElementById('root');
|
|
714
714
|
/**
|
|
715
715
|
* @desc This components extends the react-tooltip library.
|
|
716
716
|
* Full api documentation here: https://github.com/wwayne/react-tooltip
|
|
@@ -731,8 +731,8 @@ var ToolTip = function (_a) {
|
|
|
731
731
|
var toolTipMarkup = (jsxs(Tooltip, { className: s$s('container', (_b = {},
|
|
732
732
|
_b[toolTipClassName] = toolTipClassName,
|
|
733
733
|
_b)), id: uniq, place: is(String, placement) ? placement : 'top', variant: is(String, variant) ? variant : 'dark', offset: offset || 8, delayShow: delayShow || 150, closeOnScroll: true, children: [text ? jsx("span", { children: text }) : null, component || null] }));
|
|
734
|
-
if (displayInPortal || !!htmlRootNode) {
|
|
735
|
-
return (jsxs(Fragment, { children: [jsx("div", { "data-tooltip-id": uniq, className: s$s((_c = {}, _c[className] = className, _c.withEllipsis = withEllipsis, _c)), children: children }), createPortal(toolTipMarkup, htmlRootNode)] }));
|
|
734
|
+
if (displayInPortal || !!htmlRootNode$1) {
|
|
735
|
+
return (jsxs(Fragment, { children: [jsx("div", { "data-tooltip-id": uniq, className: s$s((_c = {}, _c[className] = className, _c.withEllipsis = withEllipsis, _c)), children: children }), createPortal(toolTipMarkup, htmlRootNode$1)] }));
|
|
736
736
|
}
|
|
737
737
|
return (jsxs(Fragment, { children: [jsx("div", { "data-tooltip-id": uniq, className: s$s((_d = {}, _d[className] = className, _d.withEllipsis = withEllipsis, _d)), children: children }), toolTipMarkup] }));
|
|
738
738
|
};
|
|
@@ -2674,33 +2674,46 @@ var RadioButton = function (_a) {
|
|
|
2674
2674
|
return toolTip ? (jsx(ToolTip, { className: s$k('toolTip'), text: toolTip, children: getRadioButton() })) : (getRadioButton());
|
|
2675
2675
|
};
|
|
2676
2676
|
|
|
2677
|
-
function useHandleClickOutside(callback) {
|
|
2677
|
+
function useHandleClickOutside(callback, portalRef) {
|
|
2678
2678
|
var ref = useRef(null);
|
|
2679
2679
|
useEffect(function () {
|
|
2680
2680
|
var handleClickOutside = function (event) {
|
|
2681
|
-
|
|
2682
|
-
|
|
2681
|
+
var target = event.target;
|
|
2682
|
+
var isOutsideContainer = ref.current && !ref.current.contains(target);
|
|
2683
|
+
var isOutsidePortal = (portalRef === null || portalRef === void 0 ? void 0 : portalRef.current) && !portalRef.current.contains(target);
|
|
2684
|
+
// If we have a portal ref, check if click is outside both container and portal
|
|
2685
|
+
// If no portal ref, just check if click is outside container
|
|
2686
|
+
if (portalRef === null || portalRef === void 0 ? void 0 : portalRef.current) {
|
|
2687
|
+
if (isOutsideContainer && isOutsidePortal) {
|
|
2688
|
+
callback();
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
else {
|
|
2692
|
+
if (isOutsideContainer) {
|
|
2693
|
+
callback();
|
|
2694
|
+
}
|
|
2683
2695
|
}
|
|
2684
2696
|
};
|
|
2685
2697
|
document.addEventListener('click', handleClickOutside, true);
|
|
2686
2698
|
return function () {
|
|
2687
2699
|
document.removeEventListener('click', handleClickOutside, true);
|
|
2688
2700
|
};
|
|
2689
|
-
}, [callback]);
|
|
2701
|
+
}, [callback, portalRef]);
|
|
2690
2702
|
return { ref: ref };
|
|
2691
2703
|
}
|
|
2692
2704
|
|
|
2693
2705
|
var styles$j = {"body":"DropDown-module_s-41xK","container":"DropDown-module_ms9Bnm","dropDownContainer":"DropDown-module_1bVmMF","arrow":"DropDown-module_b3hGdC","arrow_topIsDark":"DropDown-module_R8bNg1","opacityIn":"DropDown-module_nxu56-","headingContainer":"DropDown-module_d9ELNG","heading":"DropDown-module_h3xW01","childrenContainer":"DropDown-module_SegKtJ","childrenContainer_left":"DropDown-module_6BCK8k","slideInRight":"DropDown-module_si25YW","childrenContainer_top":"DropDown-module_FyuZ2X","slideInBottom":"DropDown-module_kkRcRV","childrenContainer_right":"DropDown-module_I06m6q","slideInLeft":"DropDown-module_0LyhMh","childrenContainer_bottom":"DropDown-module_8k0-k4","slideInTop":"DropDown-module_Q28lTs","list":"DropDown-module_OPwMsl","list_noHeader":"DropDown-module_RMfcZD","list_noFooter":"DropDown-module_EuuqD-","list_noHeaderOrFooter":"DropDown-module_3teSz6","list_withVisibleOverflow":"DropDown-module_Rvc2NZ","children":"DropDown-module_O5fSBy","children_noHeader":"DropDown-module_LQizIT","children_noFooter":"DropDown-module_HtsACa","children_noHeaderOrFooter":"DropDown-module_ho5wUS","spinner":"DropDown-module_hsbQPA","spinner_noHeader":"DropDown-module_T6lMJg","spinner_noFooter":"DropDown-module_-Tojji","footer":"DropDown-module_C-TdDM"};
|
|
2694
2706
|
|
|
2695
2707
|
var s$j = classNames.bind(styles$j);
|
|
2708
|
+
var htmlRootNode = document.getElementById('root');
|
|
2696
2709
|
var DropDown = function (_a) {
|
|
2697
|
-
var _b, _c, _d
|
|
2698
|
-
var title = _a.title,
|
|
2699
|
-
var
|
|
2700
|
-
var
|
|
2701
|
-
var
|
|
2702
|
-
var
|
|
2703
|
-
var
|
|
2710
|
+
var _b, _c, _d;
|
|
2711
|
+
var title = _a.title, _e = _a.offset, offset = _e === void 0 ? { horizontal: 8, vertical: 12 } : _e, arrowPadding = _a.arrowPadding, _f = _a.placement, placement = _f === void 0 ? 'auto' : _f, _g = _a.strategy, strategy = _g === void 0 ? 'absolute' : _g, className = _a.className, buttonComponent = _a.buttonComponent, triggerComponent = _a.triggerComponent, _h = _a.buttonCallbackName, buttonCallbackName = _h === void 0 ? 'onClickCallback' : _h, footerComponent = _a.footerComponent, onCloseCallback = _a.onCloseCallback, onOpenCallback = _a.onOpenCallback, children = _a.children, dropDownClassName = _a.dropDownClassName, childrenClassName = _a.childrenClassName, loading = _a.loading, _j = _a.withArrow, withArrow = _j === void 0 ? true : _j, _k = _a.childrenIsList, childrenIsList = _k === void 0 ? true : _k, isOpen = _a.isOpen, _l = _a.closeOnEscape, closeOnEscape = _l === void 0 ? true : _l, rotateIconByDegree = _a.rotateIconByDegree, rotateLeftIconByDegree = _a.rotateLeftIconByDegree, rotateMiddleIconByDegree = _a.rotateMiddleIconByDegree, rotateRightIconByDegree = _a.rotateRightIconByDegree, withVisibleOverflow = _a.withVisibleOverflow, withPortal = _a.withPortal;
|
|
2712
|
+
var _m = useState(false), _isOpen = _m[0], _setIsOpen = _m[1];
|
|
2713
|
+
var _o = useState(null), referenceElement = _o[0], setReferenceElement = _o[1];
|
|
2714
|
+
var _p = useState(null), popperElement = _p[0], setPopperElement = _p[1];
|
|
2715
|
+
var _q = useState(null), arrowElement = _q[0], setArrowElement = _q[1];
|
|
2716
|
+
var _r = useState(false), hasBeenOpened = _r[0], setHasBeenOpened = _r[1];
|
|
2704
2717
|
var isOpenState = is(Boolean, isOpen) ? isOpen : _isOpen;
|
|
2705
2718
|
var horizontal = offset.horizontal, vertical = offset.vertical;
|
|
2706
2719
|
var escFunction = function (event) {
|
|
@@ -2726,14 +2739,14 @@ var DropDown = function (_a) {
|
|
|
2726
2739
|
},
|
|
2727
2740
|
// eslint-disable-next-line
|
|
2728
2741
|
[closeOnEscape, hasBeenOpened]);
|
|
2729
|
-
var
|
|
2742
|
+
var _s = usePopper(referenceElement, popperElement, {
|
|
2730
2743
|
placement: placement,
|
|
2731
2744
|
strategy: strategy,
|
|
2732
2745
|
modifiers: [
|
|
2733
2746
|
{ name: 'arrow', enabled: withArrow, options: { element: arrowElement, padding: arrowPadding || 16 } },
|
|
2734
2747
|
{ name: 'offset', enabled: true, options: { offset: [horizontal, vertical] } }
|
|
2735
2748
|
]
|
|
2736
|
-
}), styles =
|
|
2749
|
+
}), styles = _s.styles, attributes = _s.attributes;
|
|
2737
2750
|
var onClose = function () {
|
|
2738
2751
|
if (isOpenState) {
|
|
2739
2752
|
is(Function, onCloseCallback) && onCloseCallback();
|
|
@@ -2756,7 +2769,7 @@ var DropDown = function (_a) {
|
|
|
2756
2769
|
onClose();
|
|
2757
2770
|
};
|
|
2758
2771
|
// Close the DropDown if we click outside the DropDown
|
|
2759
|
-
var containerRef = useHandleClickOutside(onClose).ref;
|
|
2772
|
+
var containerRef = useHandleClickOutside(onClose, withPortal ? { current: popperElement } : undefined).ref;
|
|
2760
2773
|
// If a child has an onClickCallback, we want to close the DropDown when it is clicked.
|
|
2761
2774
|
var cloneChildWithCloseCallback = function (child) {
|
|
2762
2775
|
if (isValidElement(child) &&
|
|
@@ -2838,23 +2851,27 @@ var DropDown = function (_a) {
|
|
|
2838
2851
|
_b[rotateMiddleIconByDegree ? 'rotateMiddleIconByDegree' : ''] = _isOpen ? rotateMiddleIconByDegree : 0,
|
|
2839
2852
|
_b[rotateRightIconByDegree ? 'rotateRightIconByDegree' : ''] = _isOpen ? rotateRightIconByDegree : 0,
|
|
2840
2853
|
_b);
|
|
2854
|
+
var dropDownMarkup = function () {
|
|
2855
|
+
var _a, _b;
|
|
2856
|
+
return isOpenState ? (jsxs("div", __assign({ className: s$j('dropDownContainer', (_a = {},
|
|
2857
|
+
_a[dropDownClassName] = dropDownClassName,
|
|
2858
|
+
_a)), ref: setPopperElement, style: styles.popper }, attributes.popper, { children: [withArrow && (jsx("div", { ref: setArrowElement, className: s$j('arrow', {
|
|
2859
|
+
arrow_topIsDark: title
|
|
2860
|
+
}), style: styles.arrow })), jsxs("div", { className: s$j('childrenContainer', (_b = {},
|
|
2861
|
+
_b["childrenContainer_".concat(getAnimationOrigin(attributes))] = getAnimationOrigin(attributes),
|
|
2862
|
+
_b)), children: [title && (jsx("header", { className: s$j('headingContainer'), children: jsx(Heading, { className: s$j('heading'), type: 'h6', marginBottom: '0', color: ColorTypes.WHITE, textAlign: 'left', children: title }) })), jsxs("div", { className: s$j('children', {
|
|
2863
|
+
children_noFooter: !footerComponent && title,
|
|
2864
|
+
children_noHeader: !title && footerComponent,
|
|
2865
|
+
children_noHeaderOrFooter: !title && !footerComponent
|
|
2866
|
+
}), children: [loading ? jsx(SolidSpinner, { type: HierarchyTypes.PRIMARY, absoluteCenter: true }) : null, getChildrenListMarkup()] }), footerComponent ? jsx("div", { className: s$j('footer'), children: footerComponent }) : null] })] }))) : null;
|
|
2867
|
+
};
|
|
2841
2868
|
return (jsxs("div", { ref: containerRef, className: s$j('container', (_c = {},
|
|
2842
2869
|
_c[className] = className,
|
|
2843
2870
|
_c)), children: [triggerComponent ? (jsx(Box, { displayFlex: true, alignItems: 'center', ref: setReferenceElement, children: isValidElement(triggerComponent)
|
|
2844
2871
|
? cloneElement(triggerComponent, __assign({}, pickAttributes(buttonAttributes)))
|
|
2845
2872
|
: null })) : null, buttonComponent ? (jsx(Box, { displayFlex: true, alignItems: 'center', ref: setReferenceElement, children: isValidElement(buttonComponent)
|
|
2846
2873
|
? cloneElement(buttonComponent, __assign((_d = {}, _d[buttonCallbackName] = function (e) { return onClickButton(e); }, _d), pickAttributes(buttonAttributes)))
|
|
2847
|
-
: null })) : null,
|
|
2848
|
-
_e[dropDownClassName] = dropDownClassName,
|
|
2849
|
-
_e)), ref: setPopperElement, style: styles.popper }, attributes.popper, { children: [withArrow && (jsx("div", { ref: setArrowElement, className: s$j('arrow', {
|
|
2850
|
-
arrow_topIsDark: title
|
|
2851
|
-
}), style: styles.arrow })), jsxs("div", { className: s$j('childrenContainer', (_f = {},
|
|
2852
|
-
_f["childrenContainer_".concat(getAnimationOrigin(attributes))] = getAnimationOrigin(attributes),
|
|
2853
|
-
_f)), children: [title && (jsx("header", { className: s$j('headingContainer'), children: jsx(Heading, { className: s$j('heading'), type: 'h6', marginBottom: '0', color: ColorTypes.WHITE, textAlign: 'left', children: title }) })), jsxs("div", { className: s$j('children', {
|
|
2854
|
-
children_noFooter: !footerComponent && title,
|
|
2855
|
-
children_noHeader: !title && footerComponent,
|
|
2856
|
-
children_noHeaderOrFooter: !title && !footerComponent
|
|
2857
|
-
}), children: [loading ? jsx(SolidSpinner, { type: HierarchyTypes.PRIMARY, absoluteCenter: true }) : null, getChildrenListMarkup()] }), footerComponent ? jsx("div", { className: s$j('footer'), children: footerComponent }) : null] })] }))) : null] }));
|
|
2874
|
+
: null })) : null, withPortal ? createPortal(dropDownMarkup(), htmlRootNode) : dropDownMarkup()] }));
|
|
2858
2875
|
};
|
|
2859
2876
|
|
|
2860
2877
|
var styles$i = {"body":"DropDownItem-module_UqDzTt","container":"DropDownItem-module_SLjW0W","container_disabled":"DropDownItem-module_n4Ei9p","innerContainer":"DropDownItem-module_yTPeWz","button":"DropDownItem-module_mxcLFJ","button_clickable":"DropDownItem-module_OZsG-E","text":"DropDownItem-module_jUNg9b","button_small":"DropDownItem-module_t-DbXt","button_medium":"DropDownItem-module_RC2tFi","button_large":"DropDownItem-module_cRR335","icon_placeholder":"DropDownItem-module_rnlTmr","icon_small":"DropDownItem-module_IP7eDy","icon_medium":"DropDownItem-module_zAzvAS","icon_large":"DropDownItem-module_evC7qy","icon_left":"DropDownItem-module_qT-IaM","icon_right":"DropDownItem-module_F1274l","text_active":"DropDownItem-module_WKiUMc","text_disabled":"DropDownItem-module_GMkCiF","text_activeDisabled":"DropDownItem-module_vwOfg5"};
|