98 lines
3.4 KiB
Plaintext
98 lines
3.4 KiB
Plaintext
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/index.ts
|
|
var src_exports = {};
|
|
__export(src_exports, {
|
|
useAriaLink: () => useAriaLink
|
|
});
|
|
module.exports = __toCommonJS(src_exports);
|
|
var import_utils = require("@react-aria/utils");
|
|
var import_shared_utils = require("@heroui/shared-utils");
|
|
var import_focus = require("@react-aria/focus");
|
|
var import_interactions = require("@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 = (0, import_utils.isIOS)() || (0, import_utils.isAndroid)();
|
|
if (deprecatedOnClick && typeof deprecatedOnClick === "function" && role !== "button") {
|
|
(0, import_shared_utils.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 } = (0, import_focus.useFocusable)(props, ref);
|
|
let { pressProps, isPressed } = (0, import_interactions.usePress)({
|
|
onPress: handlePress,
|
|
onPressStart,
|
|
onPressEnd,
|
|
isDisabled,
|
|
ref
|
|
});
|
|
let domProps = (0, import_utils.filterDOMProps)(otherProps, { labelable: true, isLink: elementType === "a" });
|
|
let interactionHandlers = (0, import_utils.mergeProps)(focusableProps, pressProps);
|
|
let router = (0, import_utils.useRouter)();
|
|
let routerLinkProps = (0, import_utils.useLinkProps)(props);
|
|
return {
|
|
isPressed,
|
|
linkProps: (0, import_utils.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() && (0, import_utils.shouldClientNavigate)(e.currentTarget, e) && props.href) {
|
|
e.preventDefault();
|
|
router.open(e.currentTarget, e, props.href, props.routerOptions);
|
|
}
|
|
}
|
|
})
|
|
};
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
useAriaLink
|
|
});
|