import * as React from "react"; import { IProps } from "reui-core"; import { IListItemsProps } from "../../common"; export interface IQueryListProps extends IListItemsProps { /** * Callback invoked when user presses a key, after processing `QueryList`'s own key events * (up/down to navigate active item). This callback is passed to `renderer` and (along with * `onKeyUp`) can be attached to arbitrary content elements to support keyboard selection. */ onKeyDown?: React.KeyboardEventHandler; /** * Callback invoked when user releases a key, after processing `QueryList`'s own key events * (enter to select active item). This callback is passed to `renderer` and (along with * `onKeyDown`) can be attached to arbitrary content elements to support keyboard selection. */ onKeyUp?: React.KeyboardEventHandler; /** * Customize rendering of the component. * Receives an object with props that should be applied to elements as necessary. */ renderer: (listProps: IQueryListRendererProps) => JSX.Element; } /** * An object describing how to render a `QueryList`. * A `QueryList` `renderer` receives this object as its sole argument. */ export interface IQueryListRendererProps extends IQueryListState, IProps { /** * Selection handler that should be invoked when a new item has been chosen, * perhaps because the user clicked it. */ handleItemSelect: (item: T, event?: React.SyntheticEvent) => void; /** * Keyboard handler for up/down arrow keys to shift the active item. * Attach this handler to any element that should support this interaction. */ handleKeyDown: React.KeyboardEventHandler; /** * Keyboard handler for enter key to select the active item. * Attach this handler to any element that should support this interaction. */ handleKeyUp: React.KeyboardEventHandler; /** * Change handler for query string. Attach this to an input element to allow * `QueryList` to control the query. */ handleQueryChange: React.ChangeEventHandler; /** Rendered elements returned from `itemListRenderer` prop. */ itemList: React.ReactNode; } export interface IQueryListState { /** The currently focused item (for keyboard interactions). */ activeItem: T | null; /** The original `items` array filtered by `itemListPredicate` or `itemPredicate`. */ filteredItems: T[]; /** The current query string. */ query: string; } export declare class QueryList extends React.Component, IQueryListState> { static displayName: string; static ofType(): new (props: IQueryListProps) => QueryList; private itemsParentRef?; private refHandlers; /** * flag indicating that we should check whether selected item is in viewport after rendering, * typically because of keyboard change. */ private shouldCheckActiveItemInViewport; constructor(props: IQueryListProps, context?: any); render(): JSX.Element; componentWillReceiveProps(nextProps: IQueryListProps): void; componentDidUpdate(prevProps: IQueryListProps): void; scrollActiveItemIntoView(): void; setQuery(query: string, resetActiveItem?: boolean): void; /** default `itemListRenderer` implementation */ private renderItemList; /** wrapper around `itemRenderer` to inject props */ private renderItem; private getActiveElement(); private getActiveIndex(); private getItemsParentPadding(); private handleItemSelect; private handleKeyDown; private handleKeyUp; private handleQueryChange; /** * Get the next enabled item, moving in the given direction from the start * index. An `undefined` return value means no suitable item was found. * @param direction amount to move in each iteration, typically +/-1 */ private getNextActiveItem(direction, startIndex?); private setActiveItem(activeItem); private setFirstActiveItem(); } /** * Get the next enabled item, moving in the given direction from the start * index. An `undefined` return value means no suitable item was found. * @param items the list of items * @param isItemDisabled callback to determine if a given item is disabled * @param direction amount to move in each iteration, typically +/-1 * @param startIndex which index to begin moving from */ export declare function getFirstEnabledItem(items: T[], itemDisabled?: keyof T | ((item: T, index: number) => boolean), direction?: number, startIndex?: number): T | null;