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

119 lines
4.4 KiB
Plaintext

var $jCY2B$reactariainteractions = require("@react-aria/interactions");
var $jCY2B$reactariautils = require("@react-aria/utils");
var $jCY2B$react = require("react");
var $jCY2B$reactariafocus = require("@react-aria/focus");
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "useTooltipTrigger", () => $f017bbc46d58d42a$export$a6da6c504e4bba8b);
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
let { isDisabled: isDisabled, trigger: trigger } = props;
let tooltipId = (0, $jCY2B$reactariautils.useId)();
let isHovered = (0, $jCY2B$react.useRef)(false);
let isFocused = (0, $jCY2B$react.useRef)(false);
let handleShow = ()=>{
if (isHovered.current || isFocused.current) state.open(isFocused.current);
};
let handleHide = (immediate)=>{
if (!isHovered.current && !isFocused.current) state.close(immediate);
};
(0, $jCY2B$react.useEffect)(()=>{
let onKeyDown = (e)=>{
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
// dismiss tooltip on esc key press
{
if (e.key === 'Escape') {
e.stopPropagation();
state.close(true);
}
}
};
if (state.isOpen) {
document.addEventListener('keydown', onKeyDown, true);
return ()=>{
document.removeEventListener('keydown', onKeyDown, true);
};
}
}, [
ref,
state
]);
let onHoverStart = ()=>{
if (trigger === 'focus') return;
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
// interactions for example, hover will end. When hover is restored after that element disappears,
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
// is the result of moving the mouse.
if ((0, $jCY2B$reactariainteractions.getInteractionModality)() === 'pointer') isHovered.current = true;
else isHovered.current = false;
handleShow();
};
let onHoverEnd = ()=>{
if (trigger === 'focus') return;
// no matter how the trigger is left, we should close the tooltip
isFocused.current = false;
isHovered.current = false;
handleHide();
};
let onPressStart = ()=>{
// no matter how the trigger is pressed, we should close the tooltip
isFocused.current = false;
isHovered.current = false;
handleHide(true);
};
let onFocus = ()=>{
let isVisible = (0, $jCY2B$reactariainteractions.isFocusVisible)();
if (isVisible) {
isFocused.current = true;
handleShow();
}
};
let onBlur = ()=>{
isFocused.current = false;
isHovered.current = false;
handleHide(true);
};
let { hoverProps: hoverProps } = (0, $jCY2B$reactariainteractions.useHover)({
isDisabled: isDisabled,
onHoverStart: onHoverStart,
onHoverEnd: onHoverEnd
});
let { focusableProps: focusableProps } = (0, $jCY2B$reactariafocus.useFocusable)({
isDisabled: isDisabled,
onFocus: onFocus,
onBlur: onBlur
}, ref);
return {
triggerProps: {
'aria-describedby': state.isOpen ? tooltipId : undefined,
...(0, $jCY2B$reactariautils.mergeProps)(focusableProps, hoverProps, {
onPointerDown: onPressStart,
onKeyDown: onPressStart
})
},
tooltipProps: {
id: tooltipId
}
};
}
//# sourceMappingURL=useTooltipTrigger.main.js.map