Files
NapCatQQ/.pnpm-store/v3/files/19/467390d7a5627db0b358a481718a52ce10e83c6202c2d7ac4a4cbdf787020d41e8dc9da71871687d370d24798a3e978a510dc2bb602f80ac11db16ee499ec9
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

90 lines
2.3 KiB
Plaintext

"use client";
// src/use-aria-popover.ts
import { useEffect } from "react";
import {
useOverlay,
useOverlayPosition
} from "@react-aria/overlays";
import {
ariaHideOutside,
toReactAriaPlacement,
ariaShouldCloseOnInteractOutside
} from "@heroui/aria-utils";
import { mergeProps } from "@react-aria/utils";
import { useSafeLayoutEffect } from "@heroui/use-safe-layout-effect";
function useReactAriaPopover(props, state) {
const {
triggerRef,
popoverRef,
showArrow,
offset = 7,
crossOffset = 0,
scrollRef,
shouldFlip,
boundaryElement,
isDismissable = true,
shouldCloseOnBlur = true,
shouldCloseOnScroll = true,
placement: placementProp = "top",
containerPadding,
shouldCloseOnInteractOutside,
isNonModal: isNonModalProp,
isKeyboardDismissDisabled,
updatePositionDeps = [],
...otherProps
} = props;
const isNonModal = isNonModalProp != null ? isNonModalProp : true;
const { overlayProps, underlayProps } = useOverlay(
{
isOpen: state.isOpen,
onClose: state.close,
shouldCloseOnBlur,
isDismissable,
isKeyboardDismissDisabled,
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside ? shouldCloseOnInteractOutside : (element) => ariaShouldCloseOnInteractOutside(element, triggerRef, state)
},
popoverRef
);
const {
overlayProps: positionProps,
arrowProps,
placement,
updatePosition
} = useOverlayPosition({
...otherProps,
shouldFlip,
crossOffset,
targetRef: triggerRef,
overlayRef: popoverRef,
isOpen: state.isOpen,
scrollRef,
boundaryElement,
containerPadding,
placement: toReactAriaPlacement(placementProp),
offset: showArrow ? offset + 3 : offset,
onClose: isNonModal && shouldCloseOnScroll ? state.close : () => {
}
});
useSafeLayoutEffect(() => {
if (!updatePositionDeps.length)
return;
updatePosition();
}, updatePositionDeps);
useEffect(() => {
if (state.isOpen && !isNonModal && popoverRef.current) {
return ariaHideOutside([popoverRef.current]);
}
}, [isNonModal, state.isOpen, popoverRef]);
return {
popoverProps: mergeProps(overlayProps, positionProps),
arrowProps,
underlayProps,
placement
};
}
export {
useReactAriaPopover
};