UNPKG

2.4 kBTypeScriptView Raw
1/// <reference types="react" />
2import { IRef } from "@blueprintjs/core";
3import { ICreateNewItem } from "./listItemsUtils";
4/**
5 * An object describing how to render the list of items.
6 * An `itemListRenderer` receives this object as its sole argument.
7 */
8export interface IItemListRendererProps<T> {
9 /**
10 * The currently focused item (for keyboard interactions), or `null` to
11 * indicate that no item is active.
12 */
13 activeItem: T | ICreateNewItem | null;
14 /**
15 * Array of items filtered by `itemListPredicate` or `itemPredicate`.
16 * See `items` for the full list of items.
17 *
18 * Use `renderFilteredItems()` utility function from this library to
19 * map each item in this array through `renderItem`, with support for
20 * optional `noResults` and `initialContent` states.
21 */
22 filteredItems: T[];
23 /**
24 * Array of all items in the list.
25 * See `filteredItems` for a filtered array based on `query` and predicate props.
26 */
27 items: T[];
28 /**
29 * The current query string.
30 */
31 query: string;
32 /**
33 * A ref handler that should be attached to the parent HTML element of the menu items.
34 * This is required for the active item to scroll into view automatically.
35 */
36 itemsParentRef: IRef<HTMLUListElement>;
37 /**
38 * Call this function to render an item.
39 * This retrieves the modifiers for the item and delegates actual rendering
40 * to the owner component's `itemRenderer` prop.
41 */
42 renderItem: (item: T, index: number) => JSX.Element | null;
43 /**
44 * Call this function to render the "create new item" view component.
45 *
46 * @returns null when creating a new item is not available, and undefined if the createNewItemRenderer returns undefined
47 */
48 renderCreateItem: () => JSX.Element | null | undefined;
49}
50/** Type alias for a function that renders the list of items. */
51export declare type ItemListRenderer<T> = (itemListProps: IItemListRendererProps<T>) => JSX.Element | null;
52/**
53 * `ItemListRenderer` helper method for rendering each item in `filteredItems`,
54 * with optional support for `noResults` (when filtered items is empty)
55 * and `initialContent` (when query is empty).
56 */
57export declare function renderFilteredItems(props: IItemListRendererProps<any>, noResults?: React.ReactNode, initialContent?: React.ReactNode | null): React.ReactNode;