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

81 lines
2.3 KiB
Plaintext

// src/index.ts
import {
filterDOMProps,
mergeProps,
useRouter,
shouldClientNavigate,
useLinkProps,
isAndroid,
isIOS
} from "@react-aria/utils";
import { warn } from "@heroui/shared-utils";
import { useFocusable } from "@react-aria/focus";
import { usePress } from "@react-aria/interactions";
function useAriaLink(props, ref) {
let {
elementType = "a",
onPress,
onPressStart,
onPressEnd,
onClick: deprecatedOnClick,
role,
isDisabled,
...otherProps
} = props;
let linkProps = {};
if (elementType !== "a") {
linkProps = {
role: "link",
tabIndex: !isDisabled ? 0 : void 0
};
}
let isMobile = isIOS() || isAndroid();
if (deprecatedOnClick && typeof deprecatedOnClick === "function" && role !== "button") {
warn(
"onClick is deprecated, please use onPress instead. See: https://github.com/heroui-inc/heroui/issues/4292",
"useLink"
);
}
const handlePress = (e) => {
if (isMobile) {
deprecatedOnClick == null ? void 0 : deprecatedOnClick(e);
}
onPress == null ? void 0 : onPress(e);
};
let { focusableProps } = useFocusable(props, ref);
let { pressProps, isPressed } = usePress({
onPress: handlePress,
onPressStart,
onPressEnd,
isDisabled,
ref
});
let domProps = filterDOMProps(otherProps, { labelable: true, isLink: elementType === "a" });
let interactionHandlers = mergeProps(focusableProps, pressProps);
let router = useRouter();
let routerLinkProps = useLinkProps(props);
return {
isPressed,
linkProps: mergeProps(domProps, routerLinkProps, {
...interactionHandlers,
...linkProps,
"aria-disabled": isDisabled || void 0,
"aria-current": props["aria-current"],
onClick: (e) => {
var _a;
(_a = pressProps.onClick) == null ? void 0 : _a.call(pressProps, e);
if (!isMobile && deprecatedOnClick) {
deprecatedOnClick(e);
}
if (!router.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && !e.isDefaultPrevented() && shouldClientNavigate(e.currentTarget, e) && props.href) {
e.preventDefault();
router.open(e.currentTarget, e, props.href, props.routerOptions);
}
}
})
};
}
export {
useAriaLink
};