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

92 lines
2.5 KiB
Plaintext

// src/index.ts
import { warn } from "@heroui/shared-utils";
import { filterDOMProps, isAndroid, isIOS, mergeProps } from "@react-aria/utils";
import { useFocusable } from "@react-aria/focus";
import { usePress } from "@react-aria/interactions";
function useAriaButton(props, ref) {
let {
elementType = "button",
isDisabled,
onPress,
onPressStart,
onPressEnd,
onPressChange,
preventFocusOnPress,
allowFocusWhenDisabled,
onClick: deprecatedOnClick,
href,
target,
rel,
type = "button",
allowTextSelectionOnPress
} = props;
let additionalProps;
if (elementType === "button") {
additionalProps = {
type,
disabled: isDisabled
};
} else {
additionalProps = {
role: "button",
tabIndex: isDisabled ? void 0 : 0,
href: elementType === "a" && !isDisabled ? href : void 0,
target: elementType === "a" ? target : void 0,
type: elementType === "input" ? type : void 0,
disabled: elementType === "input" ? isDisabled : void 0,
"aria-disabled": !isDisabled || elementType === "input" ? void 0 : isDisabled,
rel: elementType === "a" ? rel : void 0
};
}
let isMobile = isIOS() || isAndroid();
if (deprecatedOnClick && typeof deprecatedOnClick === "function") {
warn(
"onClick is deprecated, please use onPress instead. See: https://github.com/heroui-inc/heroui/issues/4292",
"useButton"
);
}
const handlePress = (e) => {
if (isMobile) {
deprecatedOnClick == null ? void 0 : deprecatedOnClick(e);
}
onPress == null ? void 0 : onPress(e);
};
let { pressProps, isPressed } = usePress({
onPressStart,
onPressEnd,
onPressChange,
onPress: handlePress,
isDisabled,
preventFocusOnPress,
allowTextSelectionOnPress,
ref
});
let { focusableProps } = useFocusable(props, ref);
if (allowFocusWhenDisabled) {
focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;
}
let buttonProps = mergeProps(
focusableProps,
pressProps,
filterDOMProps(props, { labelable: true })
);
return {
isPressed,
buttonProps: mergeProps(additionalProps, buttonProps, {
"aria-haspopup": props["aria-haspopup"],
"aria-expanded": props["aria-expanded"],
"aria-controls": props["aria-controls"],
"aria-pressed": props["aria-pressed"],
onClick: (e) => {
if (type === "button" && isMobile) {
return;
}
deprecatedOnClick == null ? void 0 : deprecatedOnClick(e);
}
})
};
}
export {
useAriaButton
};