UNPKG

matrix-react-sdk

Version:
104 lines (103 loc) 4.02 kB
import React, { RefObject, SyntheticEvent } from "react"; export interface IPosition { top?: number; bottom?: number; left?: number; right?: number; rightAligned?: boolean; bottomAligned?: boolean; } export declare enum ChevronFace { Top = "top", Bottom = "bottom", Left = "left", Right = "right", None = "none" } export interface MenuProps extends IPosition { menuWidth?: number; menuHeight?: number; chevronOffset?: number; chevronFace?: ChevronFace; menuPaddingTop?: number; menuPaddingBottom?: number; menuPaddingLeft?: number; menuPaddingRight?: number; zIndex?: number; } export interface IProps extends MenuProps { hasBackground?: boolean; managed?: boolean; wrapperClassName?: string; menuClassName?: string; mountAsChild?: boolean; focusLock?: boolean; closeOnInteraction?: boolean; onFinished(): void; windowResize?(): void; } interface IState { contextMenuElem?: HTMLDivElement; } export default class ContextMenu extends React.PureComponent<React.PropsWithChildren<IProps>, IState> { private readonly initialFocus; static defaultProps: { hasBackground: boolean; managed: boolean; }; constructor(props: IProps); componentDidMount(): void; componentWillUnmount(): void; private onModalOpen; private collectContextMenuRect; private onContextMenu; private onContextMenuPreventBubbling; private onFinished; private onClick; private onKeyDown; protected renderMenu(hasBackground?: boolean | undefined): JSX.Element; render(): React.ReactChild; } export type ToRightOf = { left: number; top: number; chevronOffset: number; }; export declare const toRightOf: (elementRect: Pick<DOMRect, "right" | "top" | "height">, chevronOffset?: number) => ToRightOf; export type ToLeftOf = { chevronOffset: number; right: number; top: number; }; export declare const toLeftOf: (elementRect: DOMRect, chevronOffset?: number) => ToLeftOf; /** * Placement method for <ContextMenu /> to position context menu of or right of elementRect * depending on which side has more space. */ export declare const toLeftOrRightOf: (elementRect: DOMRect, chevronOffset?: number) => ToRightOf | ToLeftOf; export declare const aboveLeftOf: (elementRect: Pick<DOMRect, "right" | "top" | "bottom">, chevronFace?: ChevronFace, vPadding?: number) => MenuProps; export declare const aboveRightOf: (elementRect: Pick<DOMRect, "left" | "top" | "bottom">, chevronFace?: ChevronFace, vPadding?: number) => MenuProps; export declare const alwaysMenuProps: (elementRect: Pick<DOMRect, "right" | "bottom" | "top">, chevronFace?: ChevronFace, vPadding?: number) => IPosition & { chevronFace: ChevronFace; }; export declare const alwaysAboveRightOf: (elementRect: Pick<DOMRect, "left" | "top">, chevronFace?: ChevronFace, vPadding?: number) => IPosition & { chevronFace: ChevronFace; }; type ContextMenuTuple<T> = [ boolean, RefObject<T>, (ev?: SyntheticEvent) => void, (ev?: SyntheticEvent) => void, (val: boolean) => void ]; export declare const useContextMenu: <T extends unknown = HTMLElement>(inputRef?: RefObject<T>) => ContextMenuTuple<T>; export declare function createMenu(ElementClass: typeof React.Component, props: Record<string, any>): { close: (...args: any[]) => void; }; export { ContextMenuButton } from "../../accessibility/context_menu/ContextMenuButton"; export { ContextMenuTooltipButton } from "../../accessibility/context_menu/ContextMenuTooltipButton"; export { MenuItem } from "../../accessibility/context_menu/MenuItem"; export { MenuItemCheckbox } from "../../accessibility/context_menu/MenuItemCheckbox"; export { MenuItemRadio } from "../../accessibility/context_menu/MenuItemRadio"; export { StyledMenuItemCheckbox } from "../../accessibility/context_menu/StyledMenuItemCheckbox"; export { StyledMenuItemRadio } from "../../accessibility/context_menu/StyledMenuItemRadio";