UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

54 lines 2.82 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module ContextMenu */ import "./PopupContextMenu.scss"; import * as React from "react"; import { Popup } from "../popup/Popup.js"; import { ContextMenu } from "./ContextMenu.js"; import { RelativePosition } from "@itwin/appui-abstract"; import { ContextMenuDirection } from "./ContextMenuDirection.js"; /** Component that displays a ContextMenu within a Popup component, allowing the target element to be specified. * @public * @deprecated in 4.16.0. Use {@link https://itwinui.bentley.com/docs/dropdownmenu iTwinUI DropdownMenu} component instead. */ export function PopupContextMenu(props) { const { style, onSelect, onEsc, autoflip, edgeLimit, hotkeySelect, selectedIndex, children, ...popupProps } = props; const menuDirection = getContextMenuDirectionFromRelativePosition(popupProps.position); return (React.createElement(Popup, { ...popupProps, closeOnNestedPopupOutsideClick: true, showShadow: false, showArrow: false, moveFocus: true, style: { ...style, border: "none" } }, React.createElement(ContextMenu, { className: "core-contextMenu-popupContextMenu_menu", opened: true, onSelect: onSelect, onEsc: onEsc, autoflip: autoflip, edgeLimit: edgeLimit, hotkeySelect: hotkeySelect, selectedIndex: selectedIndex, direction: menuDirection }, children))); } function getContextMenuDirectionFromRelativePosition(relativePosition) { let menuDirection = ContextMenuDirection.Bottom; switch (relativePosition) { case RelativePosition.Top: menuDirection = ContextMenuDirection.Top; break; case RelativePosition.TopLeft: menuDirection = ContextMenuDirection.TopRight; break; case RelativePosition.TopRight: menuDirection = ContextMenuDirection.TopLeft; break; case RelativePosition.Left: menuDirection = ContextMenuDirection.Left; break; case RelativePosition.Right: menuDirection = ContextMenuDirection.Right; break; case RelativePosition.Bottom: menuDirection = ContextMenuDirection.Bottom; break; case RelativePosition.BottomLeft: menuDirection = ContextMenuDirection.BottomRight; break; case RelativePosition.BottomRight: menuDirection = ContextMenuDirection.BottomLeft; break; } return menuDirection; } //# sourceMappingURL=PopupContextMenu.js.map