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