@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
28 lines • 1.15 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Utilities
*/
import * as React from "react";
/** Returns a stateful value that indicates if the component is targeted/hovered.
* @internal
*/
export const useTargeted = (ref) => {
const [targeted, setTargeted] = React.useState(false);
React.useEffect(() => {
const handleDocumentPointerMove = (e) => {
setTargeted(!!ref.current &&
!!e.target &&
e.target instanceof Node &&
ref.current.contains(e.target));
};
document.addEventListener("pointermove", handleDocumentPointerMove);
return () => {
document.removeEventListener("pointermove", handleDocumentPointerMove);
};
}, [ref]);
return targeted;
};
//# sourceMappingURL=useTargeted.js.map