1 |
|
2 | import { Props } from "@blueprintjs/core";
|
3 | import { ItemListRenderer } from "./itemListRenderer";
|
4 | import { ItemRenderer } from "./itemRenderer";
|
5 | import { CreateNewItem } from "./listItemsUtils";
|
6 | import { ItemListPredicate, ItemPredicate } from "./predicate";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export declare type ItemsEqualComparator<T> = (itemA: T, itemB: T) => boolean;
|
13 |
|
14 |
|
15 |
|
16 | export declare type ItemsEqualProp<T> = ItemsEqualComparator<T> | keyof T;
|
17 |
|
18 | export declare type IListItemsProps<T> = ListItemsProps<T>;
|
19 |
|
20 | export interface ListItemsProps<T> extends Props {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | activeItem?: T | CreateNewItem | null;
|
28 |
|
29 | items: T[];
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | itemsEqual?: ItemsEqualProp<T>;
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 | itemDisabled?: keyof T | ((item: T, index: number) => boolean);
|
50 | /**
|
51 | * Customize querying of entire `items` array. Return new list of items.
|
52 | * This method can reorder, add, or remove items at will.
|
53 | * (Supports filter algorithms that operate on the entire set, rather than individual items.)
|
54 | *
|
55 | * If `itemPredicate` is also defined, this prop takes priority and the other will be ignored.
|
56 | */
|
57 | itemListPredicate?: ItemListPredicate<T>;
|
58 | /**
|
59 | * Customize querying of individual items.
|
60 | *
|
61 | * __Filtering a list of items.__ This function is invoked to filter the
|
62 | * list of items as a query is typed. Return `true` to keep the item, or
|
63 | * `false` to hide. This method is invoked once for each item, so it should
|
64 | * be performant. For more complex queries, use `itemListPredicate` to
|
65 | * operate once on the entire array. For the purposes of filtering the list,
|
66 | * this prop is ignored if `itemListPredicate` is also defined.
|
67 | *
|
68 | * __Matching a pasted value to an item.__ This function is also invoked to
|
69 | * match a pasted value to an existing item if possible. In this case, the
|
70 | * function will receive `exactMatch=true`, and the function should return
|
71 | * true only if the item _exactly_ matches the query. For the purposes of
|
72 | * matching pasted values, this prop will be invoked even if
|
73 | * `itemListPredicate` is defined.
|
74 | */
|
75 | itemPredicate?: ItemPredicate<T>;
|
76 | /**
|
77 | * Custom renderer for an item in the dropdown list. Receives a boolean indicating whether
|
78 | * this item is active (selected by keyboard arrows) and an `onClick` event handler that
|
79 | * should be attached to the returned element.
|
80 | */
|
81 | itemRenderer: ItemRenderer<T>;
|
82 | /**
|
83 | * Custom renderer for the contents of the dropdown.
|
84 | *
|
85 | * The default implementation invokes `itemRenderer` for each item that passes the predicate
|
86 | * and wraps them all in a `Menu` element. If the query is empty then `initialContent` is returned,
|
87 | * and if there are no items that match the predicate then `noResults` is returned.
|
88 | */
|
89 | itemListRenderer?: ItemListRenderer<T>;
|
90 | /**
|
91 | * React content to render when query is empty.
|
92 | * If omitted, all items will be rendered (or result of `itemListPredicate` with empty query).
|
93 | * If explicit `null`, nothing will be rendered when query is empty.
|
94 | *
|
95 | * This prop is ignored if a custom `itemListRenderer` is supplied.
|
96 | */
|
97 | initialContent?: React.ReactNode | null;
|
98 | /**
|
99 | * React content to render when filtering items returns zero results.
|
100 | * If omitted, nothing will be rendered in this case.
|
101 | *
|
102 | * This prop is ignored if a custom `itemListRenderer` is supplied.
|
103 | *
|
104 | * NOTE: if passing a `MenuItem`, ensure it has `roleStructure="listoption"` prop.
|
105 | */
|
106 | noResults?: React.ReactNode;
|
107 | /**
|
108 | * Invoked when user interaction should change the active item: arrow keys
|
109 | * move it up/down in the list, selecting an item makes it active, and
|
110 | * changing the query may reset it to the first item in the list if it no
|
111 | * longer matches the filter.
|
112 | *
|
113 | * If the "Create Item" option is displayed and currently active, then
|
114 | * `isCreateNewItem` will be `true` and `activeItem` will be `null`. In this
|
115 | * case, you should provide a valid `CreateNewItem` object to the
|
116 | * `activeItem` _prop_ in order for the "Create Item" option to appear as
|
117 | * active.
|
118 | *
|
119 | * __Note:__ You can instantiate a `CreateNewItem` object using the
|
120 | * `getCreateNewItem()` utility exported from this package.
|
121 | */
|
122 | onActiveItemChange?: (activeItem: T | null, isCreateNewItem: boolean) => void;
|
123 | |
124 |
|
125 |
|
126 |
|
127 | onItemSelect: (item: T, event?: React.SyntheticEvent<HTMLElement>) => void;
|
128 | |
129 |
|
130 |
|
131 | onItemsPaste?: (items: T[]) => void;
|
132 | |
133 |
|
134 |
|
135 | onQueryChange?: (query: string, event?: React.ChangeEvent<HTMLInputElement>) => void;
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | createNewItemFromQuery?: (query: string) => T | T[];
|
143 | |
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | createNewItemRenderer?: (query: string, active: boolean, handleClick: React.MouseEventHandler<HTMLElement>) => JSX.Element | undefined;
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | createNewItemPosition?: "first" | "last";
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | resetOnQuery?: boolean;
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | resetOnSelect?: boolean;
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | scrollToActiveItem?: boolean;
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 | query?: string;
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | export declare function executeItemsEqual<T>(itemsEqualProp: ItemsEqualProp<T> | undefined, itemA: T | null | undefined, itemB: T | null | undefined): boolean;
|