UNPKG

5.96 kBTypeScriptView Raw
1import * as React from 'react';
2import { StandardProps } from '@material-ui/core';
3import { PopperProps } from '@material-ui/core/Popper';
4import {
5 AutocompleteChangeDetails,
6 AutocompleteChangeReason,
7 AutocompleteCloseReason,
8 AutocompleteInputChangeReason,
9 createFilterOptions,
10 UseAutocompleteProps,
11} from '../useAutocomplete';
12export {
13 AutocompleteChangeDetails,
14 AutocompleteChangeReason,
15 AutocompleteCloseReason,
16 AutocompleteInputChangeReason,
17 createFilterOptions,
18};
19
20export interface AutocompleteRenderOptionState {
21 inputValue: string;
22 selected: boolean;
23}
24
25export type AutocompleteGetTagProps = ({ index }: { index: number }) => {};
26
27export interface AutocompleteRenderGroupParams {
28 key: string;
29 group: string;
30 children: React.ReactNode;
31}
32
33export interface AutocompleteRenderInputParams {
34 id: string;
35 disabled: boolean;
36 fullWidth: boolean;
37 size: 'small' | undefined;
38 InputLabelProps: object;
39 InputProps: {
40 ref: React.Ref<any>;
41 className: string;
42 startAdornment: React.ReactNode;
43 endAdornment: React.ReactNode;
44 };
45 inputProps: object;
46}
47
48export interface AutocompleteProps<
49 T,
50 Multiple extends boolean | undefined,
51 DisableClearable extends boolean | undefined,
52 FreeSolo extends boolean | undefined
53>
54 extends UseAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>,
55 StandardProps<
56 React.HTMLAttributes<HTMLDivElement>,
57 AutocompleteClassKey,
58 'defaultValue' | 'onChange' | 'children'
59 > {
60 /**
61 * Props applied to the [`Chip`](/api/chip/) element.
62 */
63 ChipProps?: object;
64 /**
65 * The icon to display in place of the default close icon.
66 */
67 closeIcon?: React.ReactNode;
68 /**
69 * Override the default text for the *clear* icon button.
70 *
71 * For localization purposes, you can use the provided [translations](/guides/localization/).
72 */
73 clearText?: string;
74 /**
75 * Override the default text for the *close popup* icon button.
76 *
77 * For localization purposes, you can use the provided [translations](/guides/localization/).
78 */
79 closeText?: string;
80 /**
81 * If `true`, the input will be disabled.
82 */
83 disabled?: boolean;
84 /**
85 * Disable the portal behavior.
86 * The children stay within it's parent DOM hierarchy.
87 */
88 disablePortal?: boolean;
89 /**
90 * Force the visibility display of the popup icon.
91 */
92 forcePopupIcon?: true | false | 'auto';
93 /**
94 * If `true`, the input will take up the full width of its container.
95 */
96 fullWidth?: boolean;
97 /**
98 * The label to display when the tags are truncated (`limitTags`).
99 *
100 * @param {number} more The number of truncated tags.
101 * @returns {ReactNode}
102 */
103 getLimitTagsText?: (more: number) => React.ReactNode;
104 /**
105 * The component used to render the listbox.
106 */
107 ListboxComponent?: React.ComponentType<React.HTMLAttributes<HTMLElement>>;
108 /**
109 * Props applied to the Listbox element.
110 */
111 ListboxProps?: object;
112 /**
113 * If `true`, the component is in a loading state.
114 */
115 loading?: boolean;
116 /**
117 * Text to display when in a loading state.
118 *
119 * For localization purposes, you can use the provided [translations](/guides/localization/).
120 */
121 loadingText?: React.ReactNode;
122 /**
123 * The maximum number of tags that will be visible when not focused.
124 * Set `-1` to disable the limit.
125 */
126 limitTags?: number;
127 /**
128 * Text to display when there are no options.
129 *
130 * For localization purposes, you can use the provided [translations](/guides/localization/).
131 */
132 noOptionsText?: React.ReactNode;
133 /**
134 * Override the default text for the *open popup* icon button.
135 *
136 * For localization purposes, you can use the provided [translations](/guides/localization/).
137 */
138 openText?: string;
139 /**
140 * The component used to render the body of the popup.
141 */
142 PaperComponent?: React.ComponentType<React.HTMLAttributes<HTMLElement>>;
143 /**
144 * The component used to position the popup.
145 */
146 PopperComponent?: React.ComponentType<PopperProps>;
147 /**
148 * The icon to display in place of the default popup icon.
149 */
150 popupIcon?: React.ReactNode;
151 /**
152 * Render the group.
153 *
154 * @param {any} option The group to render.
155 * @returns {ReactNode}
156 */
157 renderGroup?: (params: AutocompleteRenderGroupParams) => React.ReactNode;
158 /**
159 * Render the input.
160 *
161 * @param {object} params
162 * @returns {ReactNode}
163 */
164 renderInput: (params: AutocompleteRenderInputParams) => React.ReactNode;
165 /**
166 * Render the option, use `getOptionLabel` by default.
167 *
168 * @param {T} option The option to render.
169 * @param {object} state The state of the component.
170 * @returns {ReactNode}
171 */
172 renderOption?: (option: T, state: AutocompleteRenderOptionState) => React.ReactNode;
173 /**
174 * Render the selected value.
175 *
176 * @param {T[]} value The `value` provided to the component.
177 * @param {function} getTagProps A tag props getter.
178 * @returns {ReactNode}
179 */
180 renderTags?: (value: T[], getTagProps: AutocompleteGetTagProps) => React.ReactNode;
181 /**
182 * The size of the autocomplete.
183 */
184 size?: 'small' | 'medium';
185}
186
187export type AutocompleteClassKey =
188 | 'root'
189 | 'focused'
190 | 'tag'
191 | 'tagSizeSmall'
192 | 'inputRoot'
193 | 'input'
194 | 'inputFocused'
195 | 'endAdornment'
196 | 'clearIndicator'
197 | 'clearIndicatorDirty'
198 | 'popupIndicator'
199 | 'popupIndicatorOpen'
200 | 'popper'
201 | 'popperDisablePortal'
202 | 'paper'
203 | 'listbox'
204 | 'loading'
205 | 'noOptions'
206 | 'option'
207 | 'groupLabel'
208 | 'groupUl';
209
210/**
211 *
212 * Demos:
213 *
214 * - [Autocomplete](https://mui.com/components/autocomplete/)
215 *
216 * API:
217 *
218 * - [Autocomplete API](https://mui.com/api/autocomplete/)
219 */
220export default function Autocomplete<
221 T,
222 Multiple extends boolean | undefined = undefined,
223 DisableClearable extends boolean | undefined = undefined,
224 FreeSolo extends boolean | undefined = undefined
225>(props: AutocompleteProps<T, Multiple, DisableClearable, FreeSolo>): JSX.Element;