import React from 'react'; import { MenuListProps } from './MenuList'; import { AnchorPos, PopperProps, PositionStrategy } from '../Popper'; import type { MenuItemProps } from './MenuItem'; export type AnchorElement = E; export type Children = (data: { item: T; index: number; }, itemProps: MenuItemProps) => React.ReactNode; export interface MenuProps { /** * List of items */ readonly items: readonly T[]; /** * Current value\ * If `Menu` component has `multiple` property then value must be an array of items\ * **Note**: Value can be null only when `multiple` property has been `false` */ readonly value: Value; /** * Function to which an object with data will be passed\ * The first of argument - is an object with item and item index\ * The second argument - is an item properties (onKeyDown, onClick, etc.)\ * \ * Example: * ```tsx * * {({ item }, itemProps) => ( * * {item.name} * * )} * * ``` */ readonly children: Children; /** * Menu open state */ readonly isOpen: boolean; /** * An HTML element. It's used to set the position of the menu. * \ * **Default**: `null` */ readonly anchorElement: AnchorElement | null; /** * A function that extract key for each item\ * (for details: [React List and keys](https://react.dev/learn/rendering-lists))\ * \ * Example: * ```tsx * item.id} // <-- Just use the user ID * items={[ * {id: '1', name: 'Olezhka Rukobludenko'}, * {id: '2', name: 'Feodosiya Trahovna'}, * ]} * /> * ``` */ /** * Close list if click outside the list and anchor element\ * \ * **Default**: `true` */ readonly closeOutsideClick?: boolean; /** * Allow the multiple selection * \ * **Default**: `false` */ readonly multiple?: Multiple; /** * Autofocus list after menu open\ * Dependent of `onEndReached` property\ * \ * **Default**: `true` */ readonly autofocus?: boolean; /** * Anchor position\ * \ * Default: `bottom` */ readonly anchorPos?: AnchorPos; readonly alternativePlacements?: readonly AnchorPos[]; readonly onAnchorPosChanged?: (anchorPos: AnchorPos) => void; /** * When enabled, the popper will automatically try to find the best placement * if the preferred placement doesn't fit in the viewport. * The component will iterate through possible placements until it finds one that fits. * * **Default**: `true` * ``` */ readonly autoFlip?: boolean; /** * Additional offset (in pixels) from the anchor element. * Positive values move the popper away from the anchor, negative values move it closer. * * @default `0` * ``` */ readonly offset?: number; /** * The positioning strategy to use. * - `'fixed'`: Positions relative to the viewport. Works reliably in all cases. * - `'absolute'`: Positions relative to the nearest positioned ancestor. * When using 'absolute', make sure a parent element has `position: relative`. * * **Default**: `'`absolute`'` * ``` */ readonly positionStrategy?: PositionStrategy; /** * Minimum distance (in pixels) that the popper must maintain from the viewport edges. * Used to prevent the popper from being positioned too close to the screen boundaries. * The popper will try to flip to another placement if it cannot maintain this margin. * * **Default**: `8` * ``` */ readonly viewportMargin?: number; /** * Should menu will be closed when item selected\ * \ * **Default**: if **multiple** is true then `false` otherwise - `true` */ readonly closeOnSelect?: boolean; /** * Popper z-index\ * \ * **Default**: theme.zIndex.modal */ readonly zIndex?: number; /** * Overridable components map */ readonly overrides?: MenuOverrides; /** * A function that determines which of the elements is currently selected\ * Example: * ```tsx * item.id === value.id} * > * ... * * ``` */ readonly getOptionSelected?: GetOptionSelected; /** * Called when item selected */ readonly onSelectItem?: OnSelectItem; /** * The function that will be called at the moment when you want to close the menu */ readonly onRequestClose?: OnRequestClose; /** * List menu maximum width (px, em, etc.)\ * Using pixels: * ```tsx * * ``` * Using em: * ```tsx * * ``` * Using pixels: * ```tsx * * ``` */ readonly maxWidth?: number | string; } export interface MenuOverrides { /** * Element wrapper */ readonly List?: React.ComponentType>; /** * Popper wrapper */ readonly Popper?: React.ComponentType>; } export type MenuRef = { /** * Focus on list */ focus: () => void; /** * Scroll list to specified element index */ scrollToIndex: (index: number) => void; /** * Scroll list to first of selected item */ scrollToFirstSelected: () => void; /** * Select specified item by index */ selectItem: (index: number) => void; /** * Highlight specified item by index */ highlightIndex: (index: number) => void; /** * Highlight the previous item relative to the currently highlighted one */ highlightPrevItem: () => void; /** * Highlight the next item relative to the currently highlighted one */ highlightNextItem: () => void; /** * Highlight the first item in list */ highlightFirstItem: () => void; /** * Highlight the last item in list */ highlightLastItem: () => void; /** * Select highlighted item in list */ selectHighlightedItem: () => void; /** * Returns the list HTML container */ getListElement: () => HTMLDivElement | null; }; export type Value = Multiple extends undefined ? T | null : readonly T[]; export type GetOptionSelected = (payload: { readonly item: T; readonly value: T; }) => boolean; export type OnSelectItem = (value: Multiple extends undefined ? T : readonly T[]) => void; export type OnRequestClose = (event?: React.KeyboardEvent | React.MouseEvent | KeyboardEvent | MouseEvent) => void; declare const _default: (props: MenuProps & { ref?: React.Ref | undefined; }) => JSX.Element; export default _default;