UNPKG

42.5 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
5var _ClearIcon, _ArrowDropDownIcon;
6
7import * as React from 'react';
8import PropTypes from 'prop-types';
9import clsx from 'clsx';
10import { chainPropTypes, integerPropType } from '@mui/utils';
11import { unstable_composeClasses as composeClasses, useAutocomplete, createFilterOptions } from '@mui/base';
12import { alpha } from '@mui/system';
13import Popper from '../Popper';
14import ListSubheader from '../ListSubheader';
15import Paper from '../Paper';
16import IconButton from '../IconButton';
17import Chip from '../Chip';
18import inputClasses from '../Input/inputClasses';
19import inputBaseClasses from '../InputBase/inputBaseClasses';
20import outlinedInputClasses from '../OutlinedInput/outlinedInputClasses';
21import filledInputClasses from '../FilledInput/filledInputClasses';
22import ClearIcon from '../internal/svg-icons/Close';
23import ArrowDropDownIcon from '../internal/svg-icons/ArrowDropDown';
24import useThemeProps from '../styles/useThemeProps';
25import styled from '../styles/styled';
26import autocompleteClasses, { getAutocompleteUtilityClass } from './autocompleteClasses';
27import capitalize from '../utils/capitalize';
28import { jsx as _jsx } from "react/jsx-runtime";
29import { jsxs as _jsxs } from "react/jsx-runtime";
30
31var useUtilityClasses = function useUtilityClasses(ownerState) {
32 var classes = ownerState.classes,
33 disablePortal = ownerState.disablePortal,
34 focused = ownerState.focused,
35 fullWidth = ownerState.fullWidth,
36 hasClearIcon = ownerState.hasClearIcon,
37 hasPopupIcon = ownerState.hasPopupIcon,
38 inputFocused = ownerState.inputFocused,
39 popupOpen = ownerState.popupOpen,
40 size = ownerState.size;
41 var slots = {
42 root: ['root', focused && 'focused', fullWidth && 'fullWidth', hasClearIcon && 'hasClearIcon', hasPopupIcon && 'hasPopupIcon'],
43 inputRoot: ['inputRoot'],
44 input: ['input', inputFocused && 'inputFocused'],
45 tag: ['tag', "tagSize".concat(capitalize(size))],
46 endAdornment: ['endAdornment'],
47 clearIndicator: ['clearIndicator'],
48 popupIndicator: ['popupIndicator', popupOpen && 'popupIndicatorOpen'],
49 popper: ['popper', disablePortal && 'popperDisablePortal'],
50 paper: ['paper'],
51 listbox: ['listbox'],
52 loading: ['loading'],
53 noOptions: ['noOptions'],
54 option: ['option'],
55 groupLabel: ['groupLabel'],
56 groupUl: ['groupUl']
57 };
58 return composeClasses(slots, getAutocompleteUtilityClass, classes);
59};
60
61var AutocompleteRoot = styled('div', {
62 name: 'MuiAutocomplete',
63 slot: 'Root',
64 overridesResolver: function overridesResolver(props, styles) {
65 var ownerState = props.ownerState;
66 var fullWidth = ownerState.fullWidth,
67 hasClearIcon = ownerState.hasClearIcon,
68 hasPopupIcon = ownerState.hasPopupIcon,
69 inputFocused = ownerState.inputFocused,
70 size = ownerState.size;
71 return [_defineProperty({}, "& .".concat(autocompleteClasses.tag), styles.tag), _defineProperty({}, "& .".concat(autocompleteClasses.tag), styles["tagSize".concat(capitalize(size))]), _defineProperty({}, "& .".concat(autocompleteClasses.inputRoot), styles.inputRoot), _defineProperty({}, "& .".concat(autocompleteClasses.input), styles.input), _defineProperty({}, "& .".concat(autocompleteClasses.input), inputFocused && styles.inputFocused), styles.root, fullWidth && styles.fullWidth, hasPopupIcon && styles.hasPopupIcon, hasClearIcon && styles.hasClearIcon];
72 }
73})(function (_ref6) {
74 var _extends2, _$concat, _$concat2, _$concat3, _extends3;
75
76 var ownerState = _ref6.ownerState;
77 return _extends((_extends2 = {}, _defineProperty(_extends2, "&.".concat(autocompleteClasses.focused, " .").concat(autocompleteClasses.clearIndicator), {
78 visibility: 'visible'
79 }), _defineProperty(_extends2, '@media (pointer: fine)', _defineProperty({}, "&:hover .".concat(autocompleteClasses.clearIndicator), {
80 visibility: 'visible'
81 })), _extends2), ownerState.fullWidth && {
82 width: '100%'
83 }, (_extends3 = {}, _defineProperty(_extends3, "& .".concat(autocompleteClasses.tag), _extends({
84 margin: 3,
85 maxWidth: 'calc(100% - 6px)'
86 }, ownerState.size === 'small' && {
87 margin: 2,
88 maxWidth: 'calc(100% - 4px)'
89 })), _defineProperty(_extends3, "& .".concat(autocompleteClasses.inputRoot), (_$concat = {
90 flexWrap: 'wrap'
91 }, _defineProperty(_$concat, ".".concat(autocompleteClasses.hasPopupIcon, "&, .").concat(autocompleteClasses.hasClearIcon, "&"), {
92 paddingRight: 26 + 4
93 }), _defineProperty(_$concat, ".".concat(autocompleteClasses.hasPopupIcon, ".").concat(autocompleteClasses.hasClearIcon, "&"), {
94 paddingRight: 52 + 4
95 }), _defineProperty(_$concat, "& .".concat(autocompleteClasses.input), {
96 width: 0,
97 minWidth: 30
98 }), _$concat)), _defineProperty(_extends3, "& .".concat(inputClasses.root), {
99 paddingBottom: 1,
100 '& .MuiInput-input': {
101 padding: '4px 4px 4px 0px'
102 }
103 }), _defineProperty(_extends3, "& .".concat(inputClasses.root, ".").concat(inputBaseClasses.sizeSmall), _defineProperty({}, "& .".concat(inputClasses.input), {
104 padding: '2px 4px 3px 0'
105 })), _defineProperty(_extends3, "& .".concat(outlinedInputClasses.root), (_$concat2 = {
106 padding: 9
107 }, _defineProperty(_$concat2, ".".concat(autocompleteClasses.hasPopupIcon, "&, .").concat(autocompleteClasses.hasClearIcon, "&"), {
108 paddingRight: 26 + 4 + 9
109 }), _defineProperty(_$concat2, ".".concat(autocompleteClasses.hasPopupIcon, ".").concat(autocompleteClasses.hasClearIcon, "&"), {
110 paddingRight: 52 + 4 + 9
111 }), _defineProperty(_$concat2, "& .".concat(autocompleteClasses.input), {
112 padding: '7.5px 4px 7.5px 6px'
113 }), _defineProperty(_$concat2, "& .".concat(autocompleteClasses.endAdornment), {
114 right: 9
115 }), _$concat2)), _defineProperty(_extends3, "& .".concat(outlinedInputClasses.root, ".").concat(inputBaseClasses.sizeSmall), _defineProperty({
116 padding: 6
117 }, "& .".concat(autocompleteClasses.input), {
118 padding: '2.5px 4px 2.5px 6px'
119 })), _defineProperty(_extends3, "& .".concat(filledInputClasses.root), (_$concat3 = {
120 paddingTop: 19,
121 paddingLeft: 8
122 }, _defineProperty(_$concat3, ".".concat(autocompleteClasses.hasPopupIcon, "&, .").concat(autocompleteClasses.hasClearIcon, "&"), {
123 paddingRight: 26 + 4 + 9
124 }), _defineProperty(_$concat3, ".".concat(autocompleteClasses.hasPopupIcon, ".").concat(autocompleteClasses.hasClearIcon, "&"), {
125 paddingRight: 52 + 4 + 9
126 }), _defineProperty(_$concat3, "& .".concat(filledInputClasses.input), {
127 padding: '7px 4px'
128 }), _defineProperty(_$concat3, "& .".concat(autocompleteClasses.endAdornment), {
129 right: 9
130 }), _$concat3)), _defineProperty(_extends3, "& .".concat(filledInputClasses.root, ".").concat(inputBaseClasses.sizeSmall), _defineProperty({
131 paddingBottom: 1
132 }, "& .".concat(filledInputClasses.input), {
133 padding: '2.5px 4px'
134 })), _defineProperty(_extends3, "& .".concat(inputBaseClasses.hiddenLabel), {
135 paddingTop: 8
136 }), _defineProperty(_extends3, "& .".concat(autocompleteClasses.input), _extends({
137 flexGrow: 1,
138 textOverflow: 'ellipsis',
139 opacity: 0
140 }, ownerState.inputFocused && {
141 opacity: 1
142 })), _extends3));
143});
144var AutocompleteEndAdornment = styled('div', {
145 name: 'MuiAutocomplete',
146 slot: 'EndAdornment',
147 overridesResolver: function overridesResolver(props, styles) {
148 return styles.endAdornment;
149 }
150})({
151 // We use a position absolute to support wrapping tags.
152 position: 'absolute',
153 right: 0,
154 top: 'calc(50% - 14px)' // Center vertically
155
156});
157var AutocompleteClearIndicator = styled(IconButton, {
158 name: 'MuiAutocomplete',
159 slot: 'ClearIndicator',
160 overridesResolver: function overridesResolver(props, styles) {
161 return styles.clearIndicator;
162 }
163})({
164 marginRight: -2,
165 padding: 4,
166 visibility: 'hidden'
167});
168var AutocompletePopupIndicator = styled(IconButton, {
169 name: 'MuiAutocomplete',
170 slot: 'PopupIndicator',
171 overridesResolver: function overridesResolver(_ref7, styles) {
172 var ownerState = _ref7.ownerState;
173 return _extends({}, styles.popupIndicator, ownerState.popupOpen && styles.popupIndicatorOpen);
174 }
175})(function (_ref8) {
176 var ownerState = _ref8.ownerState;
177 return _extends({
178 padding: 2,
179 marginRight: -2
180 }, ownerState.popupOpen && {
181 transform: 'rotate(180deg)'
182 });
183});
184var AutocompletePopper = styled(Popper, {
185 name: 'MuiAutocomplete',
186 slot: 'Popper',
187 overridesResolver: function overridesResolver(props, styles) {
188 var ownerState = props.ownerState;
189 return [_defineProperty({}, "& .".concat(autocompleteClasses.option), styles.option), styles.popper, ownerState.disablePortal && styles.popperDisablePortal];
190 }
191})(function (_ref10) {
192 var theme = _ref10.theme,
193 ownerState = _ref10.ownerState;
194 return _extends({
195 zIndex: (theme.vars || theme).zIndex.modal
196 }, ownerState.disablePortal && {
197 position: 'absolute'
198 });
199});
200var AutocompletePaper = styled(Paper, {
201 name: 'MuiAutocomplete',
202 slot: 'Paper',
203 overridesResolver: function overridesResolver(props, styles) {
204 return styles.paper;
205 }
206})(function (_ref11) {
207 var theme = _ref11.theme;
208 return _extends({}, theme.typography.body1, {
209 overflow: 'auto'
210 });
211});
212var AutocompleteLoading = styled('div', {
213 name: 'MuiAutocomplete',
214 slot: 'Loading',
215 overridesResolver: function overridesResolver(props, styles) {
216 return styles.loading;
217 }
218})(function (_ref12) {
219 var theme = _ref12.theme;
220 return {
221 color: (theme.vars || theme).palette.text.secondary,
222 padding: '14px 16px'
223 };
224});
225var AutocompleteNoOptions = styled('div', {
226 name: 'MuiAutocomplete',
227 slot: 'NoOptions',
228 overridesResolver: function overridesResolver(props, styles) {
229 return styles.noOptions;
230 }
231})(function (_ref13) {
232 var theme = _ref13.theme;
233 return {
234 color: (theme.vars || theme).palette.text.secondary,
235 padding: '14px 16px'
236 };
237});
238var AutocompleteListbox = styled('div', {
239 name: 'MuiAutocomplete',
240 slot: 'Listbox',
241 overridesResolver: function overridesResolver(props, styles) {
242 return styles.listbox;
243 }
244})(function (_ref14) {
245 var _ariaSelectedTru, _$concat4;
246
247 var theme = _ref14.theme;
248 return _defineProperty({
249 listStyle: 'none',
250 margin: 0,
251 padding: '8px 0',
252 maxHeight: '40vh',
253 overflow: 'auto'
254 }, "& .".concat(autocompleteClasses.option), (_$concat4 = {
255 minHeight: 48,
256 display: 'flex',
257 overflow: 'hidden',
258 justifyContent: 'flex-start',
259 alignItems: 'center',
260 cursor: 'pointer',
261 paddingTop: 6,
262 boxSizing: 'border-box',
263 outline: '0',
264 WebkitTapHighlightColor: 'transparent',
265 paddingBottom: 6,
266 paddingLeft: 16,
267 paddingRight: 16
268 }, _defineProperty(_$concat4, theme.breakpoints.up('sm'), {
269 minHeight: 'auto'
270 }), _defineProperty(_$concat4, "&.".concat(autocompleteClasses.focused), {
271 backgroundColor: (theme.vars || theme).palette.action.hover,
272 // Reset on touch devices, it doesn't add specificity
273 '@media (hover: none)': {
274 backgroundColor: 'transparent'
275 }
276 }), _defineProperty(_$concat4, '&[aria-disabled="true"]', {
277 opacity: (theme.vars || theme).palette.action.disabledOpacity,
278 pointerEvents: 'none'
279 }), _defineProperty(_$concat4, "&.".concat(autocompleteClasses.focusVisible), {
280 backgroundColor: (theme.vars || theme).palette.action.focus
281 }), _defineProperty(_$concat4, '&[aria-selected="true"]', (_ariaSelectedTru = {
282 backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / ").concat(theme.vars.palette.action.selectedOpacity, ")") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity)
283 }, _defineProperty(_ariaSelectedTru, "&.".concat(autocompleteClasses.focused), {
284 backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / calc(").concat(theme.vars.palette.action.selectedOpacity, " + ").concat(theme.vars.palette.action.hoverOpacity, "))") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
285 // Reset on touch devices, it doesn't add specificity
286 '@media (hover: none)': {
287 backgroundColor: (theme.vars || theme).palette.action.selected
288 }
289 }), _defineProperty(_ariaSelectedTru, "&.".concat(autocompleteClasses.focusVisible), {
290 backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / calc(").concat(theme.vars.palette.action.selectedOpacity, " + ").concat(theme.vars.palette.action.focusOpacity, "))") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
291 }), _ariaSelectedTru)), _$concat4));
292});
293var AutocompleteGroupLabel = styled(ListSubheader, {
294 name: 'MuiAutocomplete',
295 slot: 'GroupLabel',
296 overridesResolver: function overridesResolver(props, styles) {
297 return styles.groupLabel;
298 }
299})(function (_ref16) {
300 var theme = _ref16.theme;
301 return {
302 backgroundColor: (theme.vars || theme).palette.background.paper,
303 top: -8
304 };
305});
306var AutocompleteGroupUl = styled('ul', {
307 name: 'MuiAutocomplete',
308 slot: 'GroupUl',
309 overridesResolver: function overridesResolver(props, styles) {
310 return styles.groupUl;
311 }
312})(_defineProperty({
313 padding: 0
314}, "& .".concat(autocompleteClasses.option), {
315 paddingLeft: 24
316}));
317export { createFilterOptions };
318var Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps, ref) {
319 var _componentsProps$clea, _componentsProps$popu, _componentsProps$popp, _componentsProps$pape;
320
321 var props = useThemeProps({
322 props: inProps,
323 name: 'MuiAutocomplete'
324 });
325 /* eslint-disable @typescript-eslint/no-unused-vars */
326
327 var _props$autoComplete = props.autoComplete,
328 autoComplete = _props$autoComplete === void 0 ? false : _props$autoComplete,
329 _props$autoHighlight = props.autoHighlight,
330 autoHighlight = _props$autoHighlight === void 0 ? false : _props$autoHighlight,
331 _props$autoSelect = props.autoSelect,
332 autoSelect = _props$autoSelect === void 0 ? false : _props$autoSelect,
333 _props$blurOnSelect = props.blurOnSelect,
334 blurOnSelect = _props$blurOnSelect === void 0 ? false : _props$blurOnSelect,
335 ChipProps = props.ChipProps,
336 className = props.className,
337 _props$clearIcon = props.clearIcon,
338 clearIcon = _props$clearIcon === void 0 ? _ClearIcon || (_ClearIcon = /*#__PURE__*/_jsx(ClearIcon, {
339 fontSize: "small"
340 })) : _props$clearIcon,
341 _props$clearOnBlur = props.clearOnBlur,
342 clearOnBlur = _props$clearOnBlur === void 0 ? !props.freeSolo : _props$clearOnBlur,
343 _props$clearOnEscape = props.clearOnEscape,
344 clearOnEscape = _props$clearOnEscape === void 0 ? false : _props$clearOnEscape,
345 _props$clearText = props.clearText,
346 clearText = _props$clearText === void 0 ? 'Clear' : _props$clearText,
347 _props$closeText = props.closeText,
348 closeText = _props$closeText === void 0 ? 'Close' : _props$closeText,
349 _props$componentsProp = props.componentsProps,
350 componentsProps = _props$componentsProp === void 0 ? {} : _props$componentsProp,
351 _props$defaultValue = props.defaultValue,
352 defaultValue = _props$defaultValue === void 0 ? props.multiple ? [] : null : _props$defaultValue,
353 _props$disableClearab = props.disableClearable,
354 disableClearable = _props$disableClearab === void 0 ? false : _props$disableClearab,
355 _props$disableCloseOn = props.disableCloseOnSelect,
356 disableCloseOnSelect = _props$disableCloseOn === void 0 ? false : _props$disableCloseOn,
357 _props$disabled = props.disabled,
358 disabled = _props$disabled === void 0 ? false : _props$disabled,
359 _props$disabledItemsF = props.disabledItemsFocusable,
360 disabledItemsFocusable = _props$disabledItemsF === void 0 ? false : _props$disabledItemsF,
361 _props$disableListWra = props.disableListWrap,
362 disableListWrap = _props$disableListWra === void 0 ? false : _props$disableListWra,
363 _props$disablePortal = props.disablePortal,
364 disablePortal = _props$disablePortal === void 0 ? false : _props$disablePortal,
365 filterOptions = props.filterOptions,
366 _props$filterSelected = props.filterSelectedOptions,
367 filterSelectedOptions = _props$filterSelected === void 0 ? false : _props$filterSelected,
368 _props$forcePopupIcon = props.forcePopupIcon,
369 forcePopupIcon = _props$forcePopupIcon === void 0 ? 'auto' : _props$forcePopupIcon,
370 _props$freeSolo = props.freeSolo,
371 freeSolo = _props$freeSolo === void 0 ? false : _props$freeSolo,
372 _props$fullWidth = props.fullWidth,
373 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
374 _props$getLimitTagsTe = props.getLimitTagsText,
375 getLimitTagsText = _props$getLimitTagsTe === void 0 ? function (more) {
376 return "+".concat(more);
377 } : _props$getLimitTagsTe,
378 getOptionDisabled = props.getOptionDisabled,
379 _props$getOptionLabel = props.getOptionLabel,
380 getOptionLabel = _props$getOptionLabel === void 0 ? function (option) {
381 var _option$label;
382
383 return (_option$label = option.label) != null ? _option$label : option;
384 } : _props$getOptionLabel,
385 isOptionEqualToValue = props.isOptionEqualToValue,
386 groupBy = props.groupBy,
387 _props$handleHomeEndK = props.handleHomeEndKeys,
388 handleHomeEndKeys = _props$handleHomeEndK === void 0 ? !props.freeSolo : _props$handleHomeEndK,
389 idProp = props.id,
390 _props$includeInputIn = props.includeInputInList,
391 includeInputInList = _props$includeInputIn === void 0 ? false : _props$includeInputIn,
392 inputValueProp = props.inputValue,
393 _props$limitTags = props.limitTags,
394 limitTags = _props$limitTags === void 0 ? -1 : _props$limitTags,
395 _props$ListboxCompone = props.ListboxComponent,
396 ListboxComponent = _props$ListboxCompone === void 0 ? 'ul' : _props$ListboxCompone,
397 ListboxProps = props.ListboxProps,
398 _props$loading = props.loading,
399 loading = _props$loading === void 0 ? false : _props$loading,
400 _props$loadingText = props.loadingText,
401 loadingText = _props$loadingText === void 0 ? 'Loading…' : _props$loadingText,
402 _props$multiple = props.multiple,
403 multiple = _props$multiple === void 0 ? false : _props$multiple,
404 _props$noOptionsText = props.noOptionsText,
405 noOptionsText = _props$noOptionsText === void 0 ? 'No options' : _props$noOptionsText,
406 onChange = props.onChange,
407 onClose = props.onClose,
408 onHighlightChange = props.onHighlightChange,
409 onInputChange = props.onInputChange,
410 onOpen = props.onOpen,
411 open = props.open,
412 _props$openOnFocus = props.openOnFocus,
413 openOnFocus = _props$openOnFocus === void 0 ? false : _props$openOnFocus,
414 _props$openText = props.openText,
415 openText = _props$openText === void 0 ? 'Open' : _props$openText,
416 options = props.options,
417 _props$PaperComponent = props.PaperComponent,
418 PaperComponent = _props$PaperComponent === void 0 ? Paper : _props$PaperComponent,
419 _props$PopperComponen = props.PopperComponent,
420 PopperComponent = _props$PopperComponen === void 0 ? Popper : _props$PopperComponen,
421 _props$popupIcon = props.popupIcon,
422 popupIcon = _props$popupIcon === void 0 ? _ArrowDropDownIcon || (_ArrowDropDownIcon = /*#__PURE__*/_jsx(ArrowDropDownIcon, {})) : _props$popupIcon,
423 _props$readOnly = props.readOnly,
424 readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
425 renderGroupProp = props.renderGroup,
426 renderInput = props.renderInput,
427 renderOptionProp = props.renderOption,
428 renderTags = props.renderTags,
429 _props$selectOnFocus = props.selectOnFocus,
430 selectOnFocus = _props$selectOnFocus === void 0 ? !props.freeSolo : _props$selectOnFocus,
431 _props$size = props.size,
432 size = _props$size === void 0 ? 'medium' : _props$size,
433 valueProp = props.value,
434 other = _objectWithoutProperties(props, ["autoComplete", "autoHighlight", "autoSelect", "blurOnSelect", "ChipProps", "className", "clearIcon", "clearOnBlur", "clearOnEscape", "clearText", "closeText", "componentsProps", "defaultValue", "disableClearable", "disableCloseOnSelect", "disabled", "disabledItemsFocusable", "disableListWrap", "disablePortal", "filterOptions", "filterSelectedOptions", "forcePopupIcon", "freeSolo", "fullWidth", "getLimitTagsText", "getOptionDisabled", "getOptionLabel", "isOptionEqualToValue", "groupBy", "handleHomeEndKeys", "id", "includeInputInList", "inputValue", "limitTags", "ListboxComponent", "ListboxProps", "loading", "loadingText", "multiple", "noOptionsText", "onChange", "onClose", "onHighlightChange", "onInputChange", "onOpen", "open", "openOnFocus", "openText", "options", "PaperComponent", "PopperComponent", "popupIcon", "readOnly", "renderGroup", "renderInput", "renderOption", "renderTags", "selectOnFocus", "size", "value"]);
435 /* eslint-enable @typescript-eslint/no-unused-vars */
436
437
438 var _useAutocomplete = useAutocomplete(_extends({}, props, {
439 componentName: 'Autocomplete'
440 })),
441 getRootProps = _useAutocomplete.getRootProps,
442 getInputProps = _useAutocomplete.getInputProps,
443 getInputLabelProps = _useAutocomplete.getInputLabelProps,
444 getPopupIndicatorProps = _useAutocomplete.getPopupIndicatorProps,
445 getClearProps = _useAutocomplete.getClearProps,
446 getTagProps = _useAutocomplete.getTagProps,
447 getListboxProps = _useAutocomplete.getListboxProps,
448 getOptionProps = _useAutocomplete.getOptionProps,
449 value = _useAutocomplete.value,
450 dirty = _useAutocomplete.dirty,
451 id = _useAutocomplete.id,
452 popupOpen = _useAutocomplete.popupOpen,
453 focused = _useAutocomplete.focused,
454 focusedTag = _useAutocomplete.focusedTag,
455 anchorEl = _useAutocomplete.anchorEl,
456 setAnchorEl = _useAutocomplete.setAnchorEl,
457 inputValue = _useAutocomplete.inputValue,
458 groupedOptions = _useAutocomplete.groupedOptions;
459
460 var hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
461 var hasPopupIcon = (!freeSolo || forcePopupIcon === true) && forcePopupIcon !== false; // If you modify this, make sure to keep the `AutocompleteOwnerState` type in sync.
462
463 var ownerState = _extends({}, props, {
464 disablePortal: disablePortal,
465 focused: focused,
466 fullWidth: fullWidth,
467 hasClearIcon: hasClearIcon,
468 hasPopupIcon: hasPopupIcon,
469 inputFocused: focusedTag === -1,
470 popupOpen: popupOpen,
471 size: size
472 });
473
474 var classes = useUtilityClasses(ownerState);
475 var startAdornment;
476
477 if (multiple && value.length > 0) {
478 var getCustomizedTagProps = function getCustomizedTagProps(params) {
479 return _extends({
480 className: classes.tag,
481 disabled: disabled
482 }, getTagProps(params));
483 };
484
485 if (renderTags) {
486 startAdornment = renderTags(value, getCustomizedTagProps, ownerState);
487 } else {
488 startAdornment = value.map(function (option, index) {
489 return /*#__PURE__*/_jsx(Chip, _extends({
490 label: getOptionLabel(option),
491 size: size
492 }, getCustomizedTagProps({
493 index: index
494 }), ChipProps));
495 });
496 }
497 }
498
499 if (limitTags > -1 && Array.isArray(startAdornment)) {
500 var more = startAdornment.length - limitTags;
501
502 if (!focused && more > 0) {
503 startAdornment = startAdornment.splice(0, limitTags);
504 startAdornment.push( /*#__PURE__*/_jsx("span", {
505 className: classes.tag,
506 children: getLimitTagsText(more)
507 }, startAdornment.length));
508 }
509 }
510
511 var defaultRenderGroup = function defaultRenderGroup(params) {
512 return /*#__PURE__*/_jsxs("li", {
513 children: [/*#__PURE__*/_jsx(AutocompleteGroupLabel, {
514 className: classes.groupLabel,
515 ownerState: ownerState,
516 component: "div",
517 children: params.group
518 }), /*#__PURE__*/_jsx(AutocompleteGroupUl, {
519 className: classes.groupUl,
520 ownerState: ownerState,
521 children: params.children
522 })]
523 }, params.key);
524 };
525
526 var renderGroup = renderGroupProp || defaultRenderGroup;
527
528 var defaultRenderOption = function defaultRenderOption(props2, option) {
529 return /*#__PURE__*/_jsx("li", _extends({}, props2, {
530 children: getOptionLabel(option)
531 }));
532 };
533
534 var renderOption = renderOptionProp || defaultRenderOption;
535
536 var renderListOption = function renderListOption(option, index) {
537 var optionProps = getOptionProps({
538 option: option,
539 index: index
540 });
541 return renderOption(_extends({}, optionProps, {
542 className: classes.option
543 }), option, {
544 selected: optionProps['aria-selected'],
545 inputValue: inputValue
546 });
547 };
548
549 return /*#__PURE__*/_jsxs(React.Fragment, {
550 children: [/*#__PURE__*/_jsx(AutocompleteRoot, _extends({
551 ref: ref,
552 className: clsx(classes.root, className),
553 ownerState: ownerState
554 }, getRootProps(other), {
555 children: renderInput({
556 id: id,
557 disabled: disabled,
558 fullWidth: true,
559 size: size === 'small' ? 'small' : undefined,
560 InputLabelProps: getInputLabelProps(),
561 InputProps: _extends({
562 ref: setAnchorEl,
563 className: classes.inputRoot,
564 startAdornment: startAdornment
565 }, (hasClearIcon || hasPopupIcon) && {
566 endAdornment: /*#__PURE__*/_jsxs(AutocompleteEndAdornment, {
567 className: classes.endAdornment,
568 ownerState: ownerState,
569 children: [hasClearIcon ? /*#__PURE__*/_jsx(AutocompleteClearIndicator, _extends({}, getClearProps(), {
570 "aria-label": clearText,
571 title: clearText,
572 ownerState: ownerState
573 }, componentsProps.clearIndicator, {
574 className: clsx(classes.clearIndicator, (_componentsProps$clea = componentsProps.clearIndicator) == null ? void 0 : _componentsProps$clea.className),
575 children: clearIcon
576 })) : null, hasPopupIcon ? /*#__PURE__*/_jsx(AutocompletePopupIndicator, _extends({}, getPopupIndicatorProps(), {
577 disabled: disabled,
578 "aria-label": popupOpen ? closeText : openText,
579 title: popupOpen ? closeText : openText,
580 ownerState: ownerState
581 }, componentsProps.popupIndicator, {
582 className: clsx(classes.popupIndicator, (_componentsProps$popu = componentsProps.popupIndicator) == null ? void 0 : _componentsProps$popu.className),
583 children: popupIcon
584 })) : null]
585 })
586 }),
587 inputProps: _extends({
588 className: classes.input,
589 disabled: disabled,
590 readOnly: readOnly
591 }, getInputProps())
592 })
593 })), popupOpen && anchorEl ? /*#__PURE__*/_jsx(AutocompletePopper, _extends({
594 as: PopperComponent,
595 disablePortal: disablePortal,
596 style: {
597 width: anchorEl ? anchorEl.clientWidth : null
598 },
599 ownerState: ownerState,
600 role: "presentation",
601 anchorEl: anchorEl,
602 open: true
603 }, componentsProps.popper, {
604 className: clsx(classes.popper, (_componentsProps$popp = componentsProps.popper) == null ? void 0 : _componentsProps$popp.className),
605 children: /*#__PURE__*/_jsxs(AutocompletePaper, _extends({
606 ownerState: ownerState,
607 as: PaperComponent
608 }, componentsProps.paper, {
609 className: clsx(classes.paper, (_componentsProps$pape = componentsProps.paper) == null ? void 0 : _componentsProps$pape.className),
610 children: [loading && groupedOptions.length === 0 ? /*#__PURE__*/_jsx(AutocompleteLoading, {
611 className: classes.loading,
612 ownerState: ownerState,
613 children: loadingText
614 }) : null, groupedOptions.length === 0 && !freeSolo && !loading ? /*#__PURE__*/_jsx(AutocompleteNoOptions, {
615 className: classes.noOptions,
616 ownerState: ownerState,
617 role: "presentation",
618 onMouseDown: function onMouseDown(event) {
619 // Prevent input blur when interacting with the "no options" content
620 event.preventDefault();
621 },
622 children: noOptionsText
623 }) : null, groupedOptions.length > 0 ? /*#__PURE__*/_jsx(AutocompleteListbox, _extends({
624 as: ListboxComponent,
625 className: classes.listbox,
626 ownerState: ownerState
627 }, getListboxProps(), ListboxProps, {
628 children: groupedOptions.map(function (option, index) {
629 if (groupBy) {
630 return renderGroup({
631 key: option.key,
632 group: option.group,
633 children: option.options.map(function (option2, index2) {
634 return renderListOption(option2, option.index + index2);
635 })
636 });
637 }
638
639 return renderListOption(option, index);
640 })
641 })) : null]
642 }))
643 })) : null]
644 });
645});
646process.env.NODE_ENV !== "production" ? Autocomplete.propTypes
647/* remove-proptypes */
648= {
649 // ----------------------------- Warning --------------------------------
650 // | These PropTypes are generated from the TypeScript type definitions |
651 // | To update them edit the d.ts file and run "yarn proptypes" |
652 // ----------------------------------------------------------------------
653
654 /**
655 * If `true`, the portion of the selected suggestion that has not been typed by the user,
656 * known as the completion string, appears inline after the input cursor in the textbox.
657 * The inline completion string is visually highlighted and has a selected state.
658 * @default false
659 */
660 autoComplete: PropTypes.bool,
661
662 /**
663 * If `true`, the first option is automatically highlighted.
664 * @default false
665 */
666 autoHighlight: PropTypes.bool,
667
668 /**
669 * If `true`, the selected option becomes the value of the input
670 * when the Autocomplete loses focus unless the user chooses
671 * a different option or changes the character string in the input.
672 * @default false
673 */
674 autoSelect: PropTypes.bool,
675
676 /**
677 * Control if the input should be blurred when an option is selected:
678 *
679 * - `false` the input is not blurred.
680 * - `true` the input is always blurred.
681 * - `touch` the input is blurred after a touch event.
682 * - `mouse` the input is blurred after a mouse event.
683 * @default false
684 */
685 blurOnSelect: PropTypes.oneOfType([PropTypes.oneOf(['mouse', 'touch']), PropTypes.bool]),
686
687 /**
688 * Props applied to the [`Chip`](/material-ui/api/chip/) element.
689 */
690 ChipProps: PropTypes.object,
691
692 /**
693 * Override or extend the styles applied to the component.
694 */
695 classes: PropTypes.object,
696
697 /**
698 * @ignore
699 */
700 className: PropTypes.string,
701
702 /**
703 * The icon to display in place of the default clear icon.
704 * @default <ClearIcon fontSize="small" />
705 */
706 clearIcon: PropTypes.node,
707
708 /**
709 * If `true`, the input's text is cleared on blur if no value is selected.
710 *
711 * Set to `true` if you want to help the user enter a new value.
712 * Set to `false` if you want to help the user resume their search.
713 * @default !props.freeSolo
714 */
715 clearOnBlur: PropTypes.bool,
716
717 /**
718 * If `true`, clear all values when the user presses escape and the popup is closed.
719 * @default false
720 */
721 clearOnEscape: PropTypes.bool,
722
723 /**
724 * Override the default text for the *clear* icon button.
725 *
726 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
727 * @default 'Clear'
728 */
729 clearText: PropTypes.string,
730
731 /**
732 * Override the default text for the *close popup* icon button.
733 *
734 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
735 * @default 'Close'
736 */
737 closeText: PropTypes.string,
738
739 /**
740 * The props used for each slot inside.
741 * @default {}
742 */
743 componentsProps: PropTypes.shape({
744 clearIndicator: PropTypes.object,
745 paper: PropTypes.object,
746 popper: PropTypes.object,
747 popupIndicator: PropTypes.object
748 }),
749
750 /**
751 * The default value. Use when the component is not controlled.
752 * @default props.multiple ? [] : null
753 */
754 defaultValue: chainPropTypes(PropTypes.any, function (props) {
755 if (props.multiple && props.defaultValue !== undefined && !Array.isArray(props.defaultValue)) {
756 return new Error(['MUI: The Autocomplete expects the `defaultValue` prop to be an array when `multiple={true}` or undefined.', "However, ".concat(props.defaultValue, " was provided.")].join('\n'));
757 }
758
759 return null;
760 }),
761
762 /**
763 * If `true`, the input can't be cleared.
764 * @default false
765 */
766 disableClearable: PropTypes.bool,
767
768 /**
769 * If `true`, the popup won't close when a value is selected.
770 * @default false
771 */
772 disableCloseOnSelect: PropTypes.bool,
773
774 /**
775 * If `true`, the component is disabled.
776 * @default false
777 */
778 disabled: PropTypes.bool,
779
780 /**
781 * If `true`, will allow focus on disabled items.
782 * @default false
783 */
784 disabledItemsFocusable: PropTypes.bool,
785
786 /**
787 * If `true`, the list box in the popup will not wrap focus.
788 * @default false
789 */
790 disableListWrap: PropTypes.bool,
791
792 /**
793 * If `true`, the `Popper` content will be under the DOM hierarchy of the parent component.
794 * @default false
795 */
796 disablePortal: PropTypes.bool,
797
798 /**
799 * A function that determines the filtered options to be rendered on search.
800 *
801 * @param {T[]} options The options to render.
802 * @param {object} state The state of the component.
803 * @returns {T[]}
804 */
805 filterOptions: PropTypes.func,
806
807 /**
808 * If `true`, hide the selected options from the list box.
809 * @default false
810 */
811 filterSelectedOptions: PropTypes.bool,
812
813 /**
814 * Force the visibility display of the popup icon.
815 * @default 'auto'
816 */
817 forcePopupIcon: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.bool]),
818
819 /**
820 * If `true`, the Autocomplete is free solo, meaning that the user input is not bound to provided options.
821 * @default false
822 */
823 freeSolo: PropTypes.bool,
824
825 /**
826 * If `true`, the input will take up the full width of its container.
827 * @default false
828 */
829 fullWidth: PropTypes.bool,
830
831 /**
832 * The label to display when the tags are truncated (`limitTags`).
833 *
834 * @param {number} more The number of truncated tags.
835 * @returns {ReactNode}
836 * @default (more) => `+${more}`
837 */
838 getLimitTagsText: PropTypes.func,
839
840 /**
841 * Used to determine the disabled state for a given option.
842 *
843 * @param {T} option The option to test.
844 * @returns {boolean}
845 */
846 getOptionDisabled: PropTypes.func,
847
848 /**
849 * Used to determine the string value for a given option.
850 * It's used to fill the input (and the list box options if `renderOption` is not provided).
851 *
852 * If used in free solo mode, it must accept both the type of the options and a string.
853 *
854 * @param {T} option
855 * @returns {string}
856 * @default (option) => option.label ?? option
857 */
858 getOptionLabel: PropTypes.func,
859
860 /**
861 * If provided, the options will be grouped under the returned string.
862 * The groupBy value is also used as the text for group headings when `renderGroup` is not provided.
863 *
864 * @param {T} options The options to group.
865 * @returns {string}
866 */
867 groupBy: PropTypes.func,
868
869 /**
870 * If `true`, the component handles the "Home" and "End" keys when the popup is open.
871 * It should move focus to the first option and last option, respectively.
872 * @default !props.freeSolo
873 */
874 handleHomeEndKeys: PropTypes.bool,
875
876 /**
877 * This prop is used to help implement the accessibility logic.
878 * If you don't provide an id it will fall back to a randomly generated one.
879 */
880 id: PropTypes.string,
881
882 /**
883 * If `true`, the highlight can move to the input.
884 * @default false
885 */
886 includeInputInList: PropTypes.bool,
887
888 /**
889 * The input value.
890 */
891 inputValue: PropTypes.string,
892
893 /**
894 * Used to determine if the option represents the given value.
895 * Uses strict equality by default.
896 * ⚠️ Both arguments need to be handled, an option can only match with one value.
897 *
898 * @param {T} option The option to test.
899 * @param {T} value The value to test against.
900 * @returns {boolean}
901 */
902 isOptionEqualToValue: PropTypes.func,
903
904 /**
905 * The maximum number of tags that will be visible when not focused.
906 * Set `-1` to disable the limit.
907 * @default -1
908 */
909 limitTags: integerPropType,
910
911 /**
912 * The component used to render the listbox.
913 * @default 'ul'
914 */
915 ListboxComponent: PropTypes.elementType,
916
917 /**
918 * Props applied to the Listbox element.
919 */
920 ListboxProps: PropTypes.object,
921
922 /**
923 * If `true`, the component is in a loading state.
924 * This shows the `loadingText` in place of suggestions (only if there are no suggestions to show, e.g. `options` are empty).
925 * @default false
926 */
927 loading: PropTypes.bool,
928
929 /**
930 * Text to display when in a loading state.
931 *
932 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
933 * @default 'Loading…'
934 */
935 loadingText: PropTypes.node,
936
937 /**
938 * If `true`, `value` must be an array and the menu will support multiple selections.
939 * @default false
940 */
941 multiple: PropTypes.bool,
942
943 /**
944 * Text to display when there are no options.
945 *
946 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
947 * @default 'No options'
948 */
949 noOptionsText: PropTypes.node,
950
951 /**
952 * Callback fired when the value changes.
953 *
954 * @param {React.SyntheticEvent} event The event source of the callback.
955 * @param {T|T[]} value The new value of the component.
956 * @param {string} reason One of "createOption", "selectOption", "removeOption", "blur" or "clear".
957 * @param {string} [details]
958 */
959 onChange: PropTypes.func,
960
961 /**
962 * Callback fired when the popup requests to be closed.
963 * Use in controlled mode (see open).
964 *
965 * @param {React.SyntheticEvent} event The event source of the callback.
966 * @param {string} reason Can be: `"toggleInput"`, `"escape"`, `"selectOption"`, `"removeOption"`, `"blur"`.
967 */
968 onClose: PropTypes.func,
969
970 /**
971 * Callback fired when the highlight option changes.
972 *
973 * @param {React.SyntheticEvent} event The event source of the callback.
974 * @param {T} option The highlighted option.
975 * @param {string} reason Can be: `"keyboard"`, `"auto"`, `"mouse"`.
976 */
977 onHighlightChange: PropTypes.func,
978
979 /**
980 * Callback fired when the input value changes.
981 *
982 * @param {React.SyntheticEvent} event The event source of the callback.
983 * @param {string} value The new value of the text input.
984 * @param {string} reason Can be: `"input"` (user input), `"reset"` (programmatic change), `"clear"`.
985 */
986 onInputChange: PropTypes.func,
987
988 /**
989 * Callback fired when the popup requests to be opened.
990 * Use in controlled mode (see open).
991 *
992 * @param {React.SyntheticEvent} event The event source of the callback.
993 */
994 onOpen: PropTypes.func,
995
996 /**
997 * If `true`, the component is shown.
998 */
999 open: PropTypes.bool,
1000
1001 /**
1002 * If `true`, the popup will open on input focus.
1003 * @default false
1004 */
1005 openOnFocus: PropTypes.bool,
1006
1007 /**
1008 * Override the default text for the *open popup* icon button.
1009 *
1010 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
1011 * @default 'Open'
1012 */
1013 openText: PropTypes.string,
1014
1015 /**
1016 * Array of options.
1017 */
1018 options: PropTypes.array.isRequired,
1019
1020 /**
1021 * The component used to render the body of the popup.
1022 * @default Paper
1023 */
1024 PaperComponent: PropTypes.elementType,
1025
1026 /**
1027 * The component used to position the popup.
1028 * @default Popper
1029 */
1030 PopperComponent: PropTypes.elementType,
1031
1032 /**
1033 * The icon to display in place of the default popup icon.
1034 * @default <ArrowDropDownIcon />
1035 */
1036 popupIcon: PropTypes.node,
1037
1038 /**
1039 * If `true`, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
1040 * @default false
1041 */
1042 readOnly: PropTypes.bool,
1043
1044 /**
1045 * Render the group.
1046 *
1047 * @param {AutocompleteRenderGroupParams} params The group to render.
1048 * @returns {ReactNode}
1049 */
1050 renderGroup: PropTypes.func,
1051
1052 /**
1053 * Render the input.
1054 *
1055 * @param {object} params
1056 * @returns {ReactNode}
1057 */
1058 renderInput: PropTypes.func.isRequired,
1059
1060 /**
1061 * Render the option, use `getOptionLabel` by default.
1062 *
1063 * @param {object} props The props to apply on the li element.
1064 * @param {T} option The option to render.
1065 * @param {object} state The state of the component.
1066 * @returns {ReactNode}
1067 */
1068 renderOption: PropTypes.func,
1069
1070 /**
1071 * Render the selected value.
1072 *
1073 * @param {T[]} value The `value` provided to the component.
1074 * @param {function} getTagProps A tag props getter.
1075 * @param {object} ownerState The state of the Autocomplete component.
1076 * @returns {ReactNode}
1077 */
1078 renderTags: PropTypes.func,
1079
1080 /**
1081 * If `true`, the input's text is selected on focus.
1082 * It helps the user clear the selected value.
1083 * @default !props.freeSolo
1084 */
1085 selectOnFocus: PropTypes.bool,
1086
1087 /**
1088 * The size of the component.
1089 * @default 'medium'
1090 */
1091 size: PropTypes
1092 /* @typescript-to-proptypes-ignore */
1093 .oneOfType([PropTypes.oneOf(['small', 'medium']), PropTypes.string]),
1094
1095 /**
1096 * The system prop that allows defining system overrides as well as additional CSS styles.
1097 */
1098 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
1099
1100 /**
1101 * The value of the autocomplete.
1102 *
1103 * The value must have reference equality with the option in order to be selected.
1104 * You can customize the equality behavior with the `isOptionEqualToValue` prop.
1105 */
1106 value: chainPropTypes(PropTypes.any, function (props) {
1107 if (props.multiple && props.value !== undefined && !Array.isArray(props.value)) {
1108 return new Error(['MUI: The Autocomplete expects the `value` prop to be an array when `multiple={true}` or undefined.', "However, ".concat(props.value, " was provided.")].join('\n'));
1109 }
1110
1111 return null;
1112 })
1113} : void 0;
1114export default Autocomplete;
\No newline at end of file