@chekinapp/ui 0.0.30 → 0.0.31

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/index.d.cts CHANGED
@@ -2564,7 +2564,15 @@ declare function useModalControls(initState?: boolean, { disabled }?: {
2564
2564
  setIsOpen: React$1.Dispatch<React$1.SetStateAction<boolean>>;
2565
2565
  };
2566
2566
 
2567
- declare function useOutsideClick<T extends Element>(elementRef: RefObject<T> | null, onOutsideClick: ((event?: Event) => void) | null, nested?: string[] | string): void;
2567
+ type OutsideClickHandler = (event: Event) => void;
2568
+ type UseOutsideClickProps<T extends Element> = {
2569
+ elementRef: RefObject<T> | null;
2570
+ onOutsideClick: OutsideClickHandler | null;
2571
+ triggerRef?: RefObject<Element> | null;
2572
+ isDisabled?: boolean;
2573
+ nested?: string[] | string;
2574
+ };
2575
+ declare function useOutsideClick<T extends Element>({ elementRef, onOutsideClick, triggerRef, isDisabled, nested, }: UseOutsideClickProps<T>): void;
2568
2576
 
2569
2577
  declare function useScreenResize(maxWidth: string): {
2570
2578
  isMatch: boolean;
package/dist/index.d.ts CHANGED
@@ -2564,7 +2564,15 @@ declare function useModalControls(initState?: boolean, { disabled }?: {
2564
2564
  setIsOpen: React$1.Dispatch<React$1.SetStateAction<boolean>>;
2565
2565
  };
2566
2566
 
2567
- declare function useOutsideClick<T extends Element>(elementRef: RefObject<T> | null, onOutsideClick: ((event?: Event) => void) | null, nested?: string[] | string): void;
2567
+ type OutsideClickHandler = (event: Event) => void;
2568
+ type UseOutsideClickProps<T extends Element> = {
2569
+ elementRef: RefObject<T> | null;
2570
+ onOutsideClick: OutsideClickHandler | null;
2571
+ triggerRef?: RefObject<Element> | null;
2572
+ isDisabled?: boolean;
2573
+ nested?: string[] | string;
2574
+ };
2575
+ declare function useOutsideClick<T extends Element>({ elementRef, onOutsideClick, triggerRef, isDisabled, nested, }: UseOutsideClickProps<T>): void;
2568
2576
 
2569
2577
  declare function useScreenResize(maxWidth: string): {
2570
2578
  isMatch: boolean;
package/dist/index.js CHANGED
@@ -2169,18 +2169,25 @@ function useModalControls(initState = false, { disabled } = {}) {
2169
2169
 
2170
2170
  // src/hooks/use-outside-click.ts
2171
2171
  import { useCallback as useCallback5, useEffect as useEffect8, useRef as useRef5 } from "react";
2172
- function useOutsideClick(elementRef, onOutsideClick, nested) {
2172
+ function useOutsideClick({
2173
+ elementRef,
2174
+ onOutsideClick,
2175
+ triggerRef,
2176
+ isDisabled,
2177
+ nested
2178
+ }) {
2173
2179
  const handleOutsideClick = useRef5(onOutsideClick);
2174
2180
  handleOutsideClick.current = onOutsideClick;
2175
2181
  const checkNestedElements = useCallback5(
2176
- (event) => {
2182
+ (event, ownerDocument) => {
2177
2183
  const checkIsElementClickedBySelector = (selector) => {
2178
- const nestedElement = getDocument().querySelector(selector);
2184
+ const nestedElement = ownerDocument.querySelector(selector);
2179
2185
  return nestedElement?.contains(event.target);
2180
2186
  };
2181
2187
  const checkDataAttribute = () => {
2182
2188
  const target = event.target;
2183
- if (!target || !(target instanceof HTMLElement)) {
2189
+ const HTMLElementConstructor = ownerDocument.defaultView?.HTMLElement ?? HTMLElement;
2190
+ if (!target || !(target instanceof HTMLElementConstructor)) {
2184
2191
  return false;
2185
2192
  }
2186
2193
  let current = target;
@@ -2204,19 +2211,29 @@ function useOutsideClick(elementRef, onOutsideClick, nested) {
2204
2211
  [nested]
2205
2212
  );
2206
2213
  useEffect8(() => {
2214
+ if (isDisabled || !handleOutsideClick.current) {
2215
+ return;
2216
+ }
2217
+ const ownerDocument = elementRef?.current?.ownerDocument ?? triggerRef?.current?.ownerDocument ?? getDocument();
2207
2218
  function handleClickOutside(event) {
2208
- const isNestedElement = checkNestedElements(event);
2209
- if (elementRef?.current && !elementRef.current.contains(event.target) && !isNestedElement) {
2219
+ const target = event.target;
2220
+ const NodeConstructor = ownerDocument.defaultView?.Node ?? Node;
2221
+ if (!target || !(target instanceof NodeConstructor)) {
2222
+ return;
2223
+ }
2224
+ const targetNode = target;
2225
+ const isNestedElement = checkNestedElements(event, ownerDocument);
2226
+ if (elementRef?.current && !elementRef.current.contains(targetNode) && !triggerRef?.current?.contains(targetNode) && !isNestedElement) {
2210
2227
  handleOutsideClick.current?.(event);
2211
2228
  }
2212
2229
  }
2213
- getDocument().addEventListener("mousedown", handleClickOutside, true);
2214
- getDocument().addEventListener("touchstart", handleClickOutside, true);
2230
+ ownerDocument.addEventListener("mousedown", handleClickOutside, true);
2231
+ ownerDocument.addEventListener("touchstart", handleClickOutside, true);
2215
2232
  return () => {
2216
- getDocument().removeEventListener("mousedown", handleClickOutside, true);
2217
- getDocument().removeEventListener("touchstart", handleClickOutside, true);
2233
+ ownerDocument.removeEventListener("mousedown", handleClickOutside, true);
2234
+ ownerDocument.removeEventListener("touchstart", handleClickOutside, true);
2218
2235
  };
2219
- }, [checkNestedElements, elementRef]);
2236
+ }, [checkNestedElements, elementRef, isDisabled, triggerRef]);
2220
2237
  }
2221
2238
 
2222
2239
  // src/hooks/use-screen-resize.ts
@@ -11000,7 +11017,11 @@ var AirbnbSelect = React38.forwardRef(function AirbnbSelect2({
11000
11017
  const combinedRef = useCombinedRef(ref, desktopTriggerRef);
11001
11018
  const activeMobileIndex = getOptionIndex(options, pendingValue);
11002
11019
  const valueLabel = value ? getValueLabel?.(value) ?? String(value.label) : void 0;
11003
- useOutsideClick(containerRef, isOpen && !isMobile ? () => setIsOpen(false) : null);
11020
+ useOutsideClick({
11021
+ elementRef: containerRef,
11022
+ onOutsideClick: () => setIsOpen(false),
11023
+ isDisabled: !isOpen || isMobile
11024
+ });
11004
11025
  React38.useEffect(() => {
11005
11026
  if (isBlocked) {
11006
11027
  setIsOpen(false);
@@ -11500,7 +11521,11 @@ var SearchableSelectInternal = ({
11500
11521
  const triggerError = error ?? invalid;
11501
11522
  const describedBy = error && !hideErrorMessage ? errorId : void 0;
11502
11523
  const activeOptionId = highlightedIndex >= 0 ? getOptionId(reactId, highlightedIndex) : void 0;
11503
- useOutsideClick(containerRef, open && !isMobile ? () => closeSelect() : null);
11524
+ useOutsideClick({
11525
+ elementRef: containerRef,
11526
+ onOutsideClick: () => closeSelect(),
11527
+ isDisabled: !open || isMobile
11528
+ });
11504
11529
  const handleOnOpenChange = useEvent(onOpenChange);
11505
11530
  const setSelectOpen = useCallback25(
11506
11531
  (nextOpen, options2) => {