1 | import * as React from 'react';
|
2 | import { SxProps } from '@mui/system';
|
3 | import { OverridableStringUnion } from '@mui/types';
|
4 | import { IconButtonProps, InternalStandardProps as StandardProps, Theme } from '@mui/material';
|
5 | import { ChipProps, ChipTypeMap } from '@mui/material/Chip';
|
6 | import { PaperProps } from '@mui/material/Paper';
|
7 | import { PopperProps } from '@mui/material/Popper';
|
8 | import useAutocomplete, {
|
9 | AutocompleteChangeDetails,
|
10 | AutocompleteChangeReason,
|
11 | AutocompleteCloseReason,
|
12 | AutocompleteInputChangeReason,
|
13 | AutocompleteValue,
|
14 | createFilterOptions,
|
15 | UseAutocompleteProps,
|
16 | AutocompleteFreeSoloValueMapping,
|
17 | } from '../useAutocomplete';
|
18 | import { AutocompleteClasses } from './autocompleteClasses';
|
19 | import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
|
20 |
|
21 | export interface AutocompletePaperSlotPropsOverrides {}
|
22 | export interface AutocompletePopperSlotPropsOverrides {}
|
23 |
|
24 | export {
|
25 | AutocompleteChangeDetails,
|
26 | AutocompleteChangeReason,
|
27 | AutocompleteCloseReason,
|
28 | AutocompleteInputChangeReason,
|
29 | AutocompleteValue,
|
30 | createFilterOptions,
|
31 | };
|
32 |
|
33 | export type AutocompleteOwnerState<
|
34 | Value,
|
35 | Multiple extends boolean | undefined,
|
36 | DisableClearable extends boolean | undefined,
|
37 | FreeSolo extends boolean | undefined,
|
38 | ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
|
39 | > = AutocompleteProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent> & {
|
40 | disablePortal: boolean;
|
41 | expanded: boolean;
|
42 | focused: boolean;
|
43 | fullWidth: boolean;
|
44 | getOptionLabel: (option: Value | AutocompleteFreeSoloValueMapping<FreeSolo>) => string;
|
45 | hasClearIcon: boolean;
|
46 | hasPopupIcon: boolean;
|
47 | inputFocused: boolean;
|
48 | popupOpen: boolean;
|
49 | size: OverridableStringUnion<'small' | 'medium', AutocompletePropsSizeOverrides>;
|
50 | };
|
51 |
|
52 | export type AutocompleteRenderGetTagProps = ({ index }: { index: number }) => {
|
53 | key: number;
|
54 | className: string;
|
55 | disabled: boolean;
|
56 | 'data-tag-index': number;
|
57 | tabIndex: -1;
|
58 | onDelete: (event: any) => void;
|
59 | };
|
60 |
|
61 | export interface AutocompleteRenderOptionState {
|
62 | inputValue: string;
|
63 | index: number;
|
64 | selected: boolean;
|
65 | }
|
66 |
|
67 | export interface AutocompleteRenderGroupParams {
|
68 | key: string;
|
69 | group: string;
|
70 | children?: React.ReactNode;
|
71 | }
|
72 |
|
73 | export interface AutocompleteRenderInputParams {
|
74 | id: string;
|
75 | disabled: boolean;
|
76 | fullWidth: boolean;
|
77 | size: 'small' | undefined;
|
78 | InputLabelProps: ReturnType<ReturnType<typeof useAutocomplete>['getInputLabelProps']>;
|
79 | InputProps: {
|
80 | ref: React.Ref<any>;
|
81 | className: string;
|
82 | startAdornment: React.ReactNode;
|
83 | endAdornment: React.ReactNode;
|
84 | onMouseDown: React.MouseEventHandler;
|
85 | };
|
86 | inputProps: ReturnType<ReturnType<typeof useAutocomplete>['getInputProps']>;
|
87 | }
|
88 |
|
89 | export interface AutocompletePropsSizeOverrides {}
|
90 |
|
91 | export interface AutocompleteSlots {
|
92 | |
93 |
|
94 |
|
95 |
|
96 | listbox: React.JSXElementConstructor<React.HTMLAttributes<HTMLElement>>;
|
97 | |
98 |
|
99 |
|
100 |
|
101 | paper: React.JSXElementConstructor<PaperProps & AutocompletePaperSlotPropsOverrides>;
|
102 | |
103 |
|
104 |
|
105 |
|
106 | popper: React.JSXElementConstructor<PopperProps & AutocompletePopperSlotPropsOverrides>;
|
107 | }
|
108 |
|
109 | export type AutocompleteSlotsAndSlotProps<
|
110 | Value,
|
111 | Multiple extends boolean | undefined,
|
112 | DisableClearable extends boolean | undefined,
|
113 | FreeSolo extends boolean | undefined,
|
114 | ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
|
115 | > = CreateSlotsAndSlotProps<
|
116 | AutocompleteSlots,
|
117 | {
|
118 | chip: SlotProps<
|
119 | React.ElementType<Partial<ChipProps<ChipComponent>>>,
|
120 | {},
|
121 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
122 | >;
|
123 | clearIndicator: SlotProps<
|
124 | React.ElementType<Partial<IconButtonProps>>,
|
125 | {},
|
126 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
127 | >;
|
128 | |
129 |
|
130 |
|
131 | listbox: SlotProps<
|
132 | React.ElementType<
|
133 | ReturnType<ReturnType<typeof useAutocomplete>['getListboxProps']> & {
|
134 | sx?: SxProps<Theme>;
|
135 | ref?: React.Ref<Element>;
|
136 | }
|
137 | >,
|
138 | {},
|
139 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
140 | >;
|
141 | paper: SlotProps<
|
142 | React.ElementType<Partial<PaperProps>>,
|
143 | AutocompletePaperSlotPropsOverrides,
|
144 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
145 | >;
|
146 | popper: SlotProps<
|
147 | React.ElementType<Partial<PopperProps>>,
|
148 | AutocompletePopperSlotPropsOverrides,
|
149 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
150 | >;
|
151 | popupIndicator: SlotProps<
|
152 | React.ElementType<Partial<IconButtonProps>>,
|
153 | {},
|
154 | AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>
|
155 | >;
|
156 | }
|
157 | >;
|
158 |
|
159 | export interface AutocompleteProps<
|
160 | Value,
|
161 | Multiple extends boolean | undefined,
|
162 | DisableClearable extends boolean | undefined,
|
163 | FreeSolo extends boolean | undefined,
|
164 | ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
|
165 | > extends UseAutocompleteProps<Value, Multiple, DisableClearable, FreeSolo>,
|
166 | StandardProps<React.HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange' | 'children'>,
|
167 | AutocompleteSlotsAndSlotProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent> {
|
168 | |
169 |
|
170 |
|
171 | ChipProps?: ChipProps<ChipComponent>;
|
172 | |
173 |
|
174 |
|
175 | classes?: Partial<AutocompleteClasses>;
|
176 | |
177 |
|
178 |
|
179 |
|
180 | clearIcon?: React.ReactNode;
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | clearText?: string;
|
188 | |
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | closeText?: string;
|
195 | |
196 |
|
197 |
|
198 |
|
199 | componentsProps?: {
|
200 | clearIndicator?: Partial<IconButtonProps>;
|
201 | paper?: PaperProps;
|
202 | popper?: Partial<PopperProps>;
|
203 | popupIndicator?: Partial<IconButtonProps>;
|
204 | };
|
205 | |
206 |
|
207 |
|
208 |
|
209 | disabled?: boolean;
|
210 | |
211 |
|
212 |
|
213 |
|
214 | disablePortal?: boolean;
|
215 | |
216 |
|
217 |
|
218 |
|
219 | forcePopupIcon?: true | false | 'auto';
|
220 | |
221 |
|
222 |
|
223 |
|
224 | fullWidth?: boolean;
|
225 | |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | getLimitTagsText?: (more: number) => React.ReactNode;
|
233 | |
234 |
|
235 |
|
236 |
|
237 | ListboxComponent?: React.JSXElementConstructor<React.HTMLAttributes<HTMLElement>>;
|
238 | |
239 |
|
240 |
|
241 | ListboxProps?: ReturnType<ReturnType<typeof useAutocomplete>['getListboxProps']> & {
|
242 | sx?: SxProps<Theme>;
|
243 | ref?: React.Ref<Element>;
|
244 | };
|
245 | |
246 |
|
247 |
|
248 |
|
249 |
|
250 | loading?: boolean;
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | loadingText?: React.ReactNode;
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 | limitTags?: number;
|
264 | |
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | noOptionsText?: React.ReactNode;
|
271 | onKeyDown?: (
|
272 | event: React.KeyboardEvent<HTMLDivElement> & { defaultMuiPrevented?: boolean },
|
273 | ) => void;
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | openText?: string;
|
281 | |
282 |
|
283 |
|
284 |
|
285 | PaperComponent?: React.JSXElementConstructor<React.HTMLAttributes<HTMLElement>>;
|
286 | |
287 |
|
288 |
|
289 |
|
290 | PopperComponent?: React.JSXElementConstructor<PopperProps>;
|
291 | |
292 |
|
293 |
|
294 |
|
295 | popupIcon?: React.ReactNode;
|
296 | |
297 |
|
298 |
|
299 |
|
300 | readOnly?: boolean;
|
301 | |
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | renderGroup?: (params: AutocompleteRenderGroupParams) => React.ReactNode;
|
308 | |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 | renderInput: (params: AutocompleteRenderInputParams) => React.ReactNode;
|
315 | |
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | renderOption?: (
|
325 | props: React.HTMLAttributes<HTMLLIElement> & { key: any },
|
326 | option: Value,
|
327 | state: AutocompleteRenderOptionState,
|
328 | ownerState: AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>,
|
329 | ) => React.ReactNode;
|
330 | |
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | renderTags?: (
|
339 | value: Value[],
|
340 | getTagProps: AutocompleteRenderGetTagProps,
|
341 | ownerState: AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>,
|
342 | ) => React.ReactNode;
|
343 | |
344 |
|
345 |
|
346 |
|
347 | size?: OverridableStringUnion<'small' | 'medium', AutocompletePropsSizeOverrides>;
|
348 | |
349 |
|
350 |
|
351 | sx?: SxProps<Theme>;
|
352 | }
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 | export default function Autocomplete<
|
365 | Value,
|
366 | Multiple extends boolean | undefined = false,
|
367 | DisableClearable extends boolean | undefined = false,
|
368 | FreeSolo extends boolean | undefined = false,
|
369 | ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
|
370 | >(
|
371 | props: AutocompleteProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>,
|
372 | ): React.JSX.Element;
|