1 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 |
|
5 | var _ClearIcon, _ArrowDropDownIcon;
|
6 |
|
7 | import * as React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 | import clsx from 'clsx';
|
10 | import { chainPropTypes, integerPropType } from '@mui/utils';
|
11 | import { unstable_composeClasses as composeClasses, useAutocomplete, createFilterOptions } from '@mui/base';
|
12 | import { alpha } from '@mui/system';
|
13 | import Popper from '../Popper';
|
14 | import ListSubheader from '../ListSubheader';
|
15 | import Paper from '../Paper';
|
16 | import IconButton from '../IconButton';
|
17 | import Chip from '../Chip';
|
18 | import inputClasses from '../Input/inputClasses';
|
19 | import inputBaseClasses from '../InputBase/inputBaseClasses';
|
20 | import outlinedInputClasses from '../OutlinedInput/outlinedInputClasses';
|
21 | import filledInputClasses from '../FilledInput/filledInputClasses';
|
22 | import ClearIcon from '../internal/svg-icons/Close';
|
23 | import ArrowDropDownIcon from '../internal/svg-icons/ArrowDropDown';
|
24 | import useThemeProps from '../styles/useThemeProps';
|
25 | import styled from '../styles/styled';
|
26 | import autocompleteClasses, { getAutocompleteUtilityClass } from './autocompleteClasses';
|
27 | import capitalize from '../utils/capitalize';
|
28 | import { jsx as _jsx } from "react/jsx-runtime";
|
29 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
30 |
|
31 | var 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 |
|
61 | var 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 | });
|
144 | var AutocompleteEndAdornment = styled('div', {
|
145 | name: 'MuiAutocomplete',
|
146 | slot: 'EndAdornment',
|
147 | overridesResolver: function overridesResolver(props, styles) {
|
148 | return styles.endAdornment;
|
149 | }
|
150 | })({
|
151 |
|
152 | position: 'absolute',
|
153 | right: 0,
|
154 | top: 'calc(50% - 14px)'
|
155 |
|
156 | });
|
157 | var 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 | });
|
168 | var 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 | });
|
184 | var 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 | });
|
200 | var 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 | });
|
212 | var 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 | });
|
225 | var 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 | });
|
238 | var 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 |
|
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 |
|
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 | });
|
293 | var 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 | });
|
306 | var 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 | }));
|
317 | export { createFilterOptions };
|
318 | var Autocomplete = 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 |
|
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 = _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 = _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 |
|
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;
|
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 _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( _jsx("span", {
|
505 | className: classes.tag,
|
506 | children: getLimitTagsText(more)
|
507 | }, startAdornment.length));
|
508 | }
|
509 | }
|
510 |
|
511 | var defaultRenderGroup = function defaultRenderGroup(params) {
|
512 | return _jsxs("li", {
|
513 | children: [_jsx(AutocompleteGroupLabel, {
|
514 | className: classes.groupLabel,
|
515 | ownerState: ownerState,
|
516 | component: "div",
|
517 | children: params.group
|
518 | }), _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 _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 _jsxs(React.Fragment, {
|
550 | children: [_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: _jsxs(AutocompleteEndAdornment, {
|
567 | className: classes.endAdornment,
|
568 | ownerState: ownerState,
|
569 | children: [hasClearIcon ? _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 ? _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 ? _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: _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 ? _jsx(AutocompleteLoading, {
|
611 | className: classes.loading,
|
612 | ownerState: ownerState,
|
613 | children: loadingText
|
614 | }) : null, groupedOptions.length === 0 && !freeSolo && !loading ? _jsx(AutocompleteNoOptions, {
|
615 | className: classes.noOptions,
|
616 | ownerState: ownerState,
|
617 | role: "presentation",
|
618 | onMouseDown: function onMouseDown(event) {
|
619 |
|
620 | event.preventDefault();
|
621 | },
|
622 | children: noOptionsText
|
623 | }) : null, groupedOptions.length > 0 ? _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 | });
|
646 | process.env.NODE_ENV !== "production" ? Autocomplete.propTypes
|
647 |
|
648 | = {
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 | |
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | autoComplete: PropTypes.bool,
|
661 |
|
662 | |
663 |
|
664 |
|
665 |
|
666 | autoHighlight: PropTypes.bool,
|
667 |
|
668 | |
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 | autoSelect: PropTypes.bool,
|
675 |
|
676 | |
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | blurOnSelect: PropTypes.oneOfType([PropTypes.oneOf(['mouse', 'touch']), PropTypes.bool]),
|
686 |
|
687 | |
688 |
|
689 |
|
690 | ChipProps: PropTypes.object,
|
691 |
|
692 | |
693 |
|
694 |
|
695 | classes: PropTypes.object,
|
696 |
|
697 | |
698 |
|
699 |
|
700 | className: PropTypes.string,
|
701 |
|
702 | |
703 |
|
704 |
|
705 |
|
706 | clearIcon: PropTypes.node,
|
707 |
|
708 | |
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | clearOnBlur: PropTypes.bool,
|
716 |
|
717 | |
718 |
|
719 |
|
720 |
|
721 | clearOnEscape: PropTypes.bool,
|
722 |
|
723 | |
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 | clearText: PropTypes.string,
|
730 |
|
731 | |
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | closeText: PropTypes.string,
|
738 |
|
739 | |
740 |
|
741 |
|
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 |
|
752 |
|
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 |
|
764 |
|
765 |
|
766 | disableClearable: PropTypes.bool,
|
767 |
|
768 | |
769 |
|
770 |
|
771 |
|
772 | disableCloseOnSelect: PropTypes.bool,
|
773 |
|
774 | |
775 |
|
776 |
|
777 |
|
778 | disabled: PropTypes.bool,
|
779 |
|
780 | |
781 |
|
782 |
|
783 |
|
784 | disabledItemsFocusable: PropTypes.bool,
|
785 |
|
786 | |
787 |
|
788 |
|
789 |
|
790 | disableListWrap: PropTypes.bool,
|
791 |
|
792 | |
793 |
|
794 |
|
795 |
|
796 | disablePortal: PropTypes.bool,
|
797 |
|
798 | |
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | filterOptions: PropTypes.func,
|
806 |
|
807 | |
808 |
|
809 |
|
810 |
|
811 | filterSelectedOptions: PropTypes.bool,
|
812 |
|
813 | |
814 |
|
815 |
|
816 |
|
817 | forcePopupIcon: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.bool]),
|
818 |
|
819 | |
820 |
|
821 |
|
822 |
|
823 | freeSolo: PropTypes.bool,
|
824 |
|
825 | |
826 |
|
827 |
|
828 |
|
829 | fullWidth: PropTypes.bool,
|
830 |
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 | getLimitTagsText: PropTypes.func,
|
839 |
|
840 | |
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 | getOptionDisabled: PropTypes.func,
|
847 |
|
848 | |
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 | getOptionLabel: PropTypes.func,
|
859 |
|
860 | |
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 | groupBy: PropTypes.func,
|
868 |
|
869 | |
870 |
|
871 |
|
872 |
|
873 |
|
874 | handleHomeEndKeys: PropTypes.bool,
|
875 |
|
876 | |
877 |
|
878 |
|
879 |
|
880 | id: PropTypes.string,
|
881 |
|
882 | |
883 |
|
884 |
|
885 |
|
886 | includeInputInList: PropTypes.bool,
|
887 |
|
888 | |
889 |
|
890 |
|
891 | inputValue: PropTypes.string,
|
892 |
|
893 | |
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 | isOptionEqualToValue: PropTypes.func,
|
903 |
|
904 | |
905 |
|
906 |
|
907 |
|
908 |
|
909 | limitTags: integerPropType,
|
910 |
|
911 | |
912 |
|
913 |
|
914 |
|
915 | ListboxComponent: PropTypes.elementType,
|
916 |
|
917 | |
918 |
|
919 |
|
920 | ListboxProps: PropTypes.object,
|
921 |
|
922 | |
923 |
|
924 |
|
925 |
|
926 |
|
927 | loading: PropTypes.bool,
|
928 |
|
929 | |
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 | loadingText: PropTypes.node,
|
936 |
|
937 | |
938 |
|
939 |
|
940 |
|
941 | multiple: PropTypes.bool,
|
942 |
|
943 | |
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 | noOptionsText: PropTypes.node,
|
950 |
|
951 | |
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 | onChange: PropTypes.func,
|
960 |
|
961 | |
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 | onClose: PropTypes.func,
|
969 |
|
970 | |
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 | onHighlightChange: PropTypes.func,
|
978 |
|
979 | |
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 | onInputChange: PropTypes.func,
|
987 |
|
988 | |
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 | onOpen: PropTypes.func,
|
995 |
|
996 | |
997 |
|
998 |
|
999 | open: PropTypes.bool,
|
1000 |
|
1001 | |
1002 |
|
1003 |
|
1004 |
|
1005 | openOnFocus: PropTypes.bool,
|
1006 |
|
1007 | |
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 | openText: PropTypes.string,
|
1014 |
|
1015 | |
1016 |
|
1017 |
|
1018 | options: PropTypes.array.isRequired,
|
1019 |
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 | PaperComponent: PropTypes.elementType,
|
1025 |
|
1026 | |
1027 |
|
1028 |
|
1029 |
|
1030 | PopperComponent: PropTypes.elementType,
|
1031 |
|
1032 | |
1033 |
|
1034 |
|
1035 |
|
1036 | popupIcon: PropTypes.node,
|
1037 |
|
1038 | |
1039 |
|
1040 |
|
1041 |
|
1042 | readOnly: PropTypes.bool,
|
1043 |
|
1044 | |
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | renderGroup: PropTypes.func,
|
1051 |
|
1052 | |
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 | renderInput: PropTypes.func.isRequired,
|
1059 |
|
1060 | |
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 | renderOption: PropTypes.func,
|
1069 |
|
1070 | |
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 | renderTags: PropTypes.func,
|
1079 |
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 | selectOnFocus: PropTypes.bool,
|
1086 |
|
1087 | |
1088 |
|
1089 |
|
1090 |
|
1091 | size: PropTypes
|
1092 |
|
1093 | .oneOfType([PropTypes.oneOf(['small', 'medium']), PropTypes.string]),
|
1094 |
|
1095 | |
1096 |
|
1097 |
|
1098 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
1099 |
|
1100 | |
1101 |
|
1102 |
|
1103 |
|
1104 |
|
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;
|
1114 | export default Autocomplete; |
\ | No newline at end of file |