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