@itwin/measure-tools-react
Version:
Frontend framework and tools for measurements
36 lines • 1.56 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/* eslint-disable deprecation/deprecation */
import * as React from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { Toolbar } from "@itwin/appui-react";
export const PopupToolbar = ({ items, onClose }) => {
const [isClosing, setIsClosing] = useState(false);
const ref = useRef(null);
const handleMouseWheel = useCallback(() => {
if (!isClosing && onClose) {
onClose();
setIsClosing(true);
}
}, [isClosing, onClose]);
const handleClick = useCallback(() => {
if (!isClosing && onClose) {
onClose();
setIsClosing(true);
}
}, [isClosing, onClose]);
useEffect(() => {
document.addEventListener("click", handleClick);
document.addEventListener("wheel", handleMouseWheel);
return () => {
document.removeEventListener("click", handleClick);
document.removeEventListener("wheel", handleMouseWheel);
setIsClosing(false);
};
}, [handleMouseWheel, handleClick]);
return React.createElement("div", { ref: ref },
React.createElement(Toolbar, { items: items }));
};
//# sourceMappingURL=PopupToolbar.js.map