@choc-ui/chakra-autocomplete 4.8.2 → 4.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -11
- package/dist/autocomplete-item.d.ts +0 -1
- package/dist/autocomplete.d.ts +10 -2
- package/dist/chakra-autocomplete.cjs.development.js +109 -64
- package/dist/chakra-autocomplete.cjs.development.js.map +1 -1
- package/dist/chakra-autocomplete.cjs.production.min.js +1 -1
- package/dist/chakra-autocomplete.cjs.production.min.js.map +1 -1
- package/dist/chakra-autocomplete.esm.js +110 -67
- package/dist/chakra-autocomplete.esm.js.map +1 -1
- package/dist/helpers/group.d.ts +4 -5
- package/dist/helpers/items.d.ts +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/types.d.ts +17 -16
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -147,7 +147,7 @@ function App() {
|
|
|
147
147
|
<AutoCompleteInput variant="filled" />
|
|
148
148
|
<AutoCompleteList>
|
|
149
149
|
{Object.entries(continents).map(([continent, countries], co_id) => (
|
|
150
|
-
<AutoCompleteGroup key={co_id}
|
|
150
|
+
<AutoCompleteGroup key={co_id} showDivider>
|
|
151
151
|
<AutoCompleteGroupTitle textTransform="capitalize">
|
|
152
152
|
{continent}
|
|
153
153
|
</AutoCompleteGroupTitle>
|
|
@@ -155,7 +155,6 @@ function App() {
|
|
|
155
155
|
<AutoCompleteItem
|
|
156
156
|
key={c_id}
|
|
157
157
|
value={country}
|
|
158
|
-
groupId={continent}
|
|
159
158
|
textTransform="capitalize"
|
|
160
159
|
>
|
|
161
160
|
{country}
|
|
@@ -178,7 +177,7 @@ export default App;
|
|
|
178
177
|
|
|
179
178
|
## Accessing the internal state
|
|
180
179
|
|
|
181
|
-
To access the internal state of the `AutoComplete`, use a function as children (commonly known as a render prop). You'll get access to the internal state `isOpen`, with the `onOpen
|
|
180
|
+
To access the internal state of the `AutoComplete`, use a function as children (commonly known as a render prop). You'll get access to the internal state `isOpen`, with the `onOpen` and `onClose` methods.
|
|
182
181
|
|
|
183
182
|
```js
|
|
184
183
|
import {
|
|
@@ -386,6 +385,13 @@ Then add the `AutoCompleteCreatable` component to the bottom of the list. Refer
|
|
|
386
385
|
|
|
387
386
|
<img width="517" alt="CleanShot 2021-07-29 at 02 29 20@2x" src="https://user-images.githubusercontent.com/30869823/127417453-e78b9b48-26e8-4ff0-a264-1d6bb4717ab0.png">
|
|
388
387
|
|
|
388
|
+
### Autocomplete methods
|
|
389
|
+
Assign a ref to the `AutoComplete` component and call the available methods with:
|
|
390
|
+
```js
|
|
391
|
+
ref.current?.resetItems()
|
|
392
|
+
ref.current?.removeItem(itemValue)
|
|
393
|
+
```
|
|
394
|
+
|
|
389
395
|
### Codesandbox Link [Here](https://githubbox.com/anubra266/choc-autocomplete/tree/main/demo)
|
|
390
396
|
|
|
391
397
|
## API Reference
|
|
@@ -560,6 +566,17 @@ boolean | MaybeRenderProp<{ value: Item["value"] }>
|
|
|
560
566
|
<td>method to call whenever a suggestion is focused</td>
|
|
561
567
|
<td>———</td>
|
|
562
568
|
</tr>
|
|
569
|
+
<tr>
|
|
570
|
+
<td>onReady</td>
|
|
571
|
+
<td>
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
(props:{tags:ItemTag[]}) => void
|
|
575
|
+
```
|
|
576
|
+
</td>
|
|
577
|
+
<td>method that exposes variables used in component</td>
|
|
578
|
+
<td>———</td>
|
|
579
|
+
</tr>
|
|
563
580
|
<tr>
|
|
564
581
|
<td>onTagRemoved</td>
|
|
565
582
|
<td>
|
|
@@ -794,13 +811,6 @@ val => val;
|
|
|
794
811
|
|
|
795
812
|
</td>
|
|
796
813
|
</tr>
|
|
797
|
-
<tr>
|
|
798
|
-
<td>groupId</td>
|
|
799
|
-
<td>string</td>
|
|
800
|
-
<td>The id of the group, if Item belongs to one. It's required if you need to wrap the items in an HOC.</td>
|
|
801
|
-
<td>no<br></td>
|
|
802
|
-
<td>———</td>
|
|
803
|
-
</tr>
|
|
804
814
|
<tr>
|
|
805
815
|
<td>label</td>
|
|
806
816
|
<td>string</td>
|
|
@@ -1013,7 +1023,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
1013
1023
|
<td align="center"><a href="https://anubra266.tk"><img src="https://avatars.githubusercontent.com/u/30869823?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Abraham</b></sub></a><br /><a href="https://github.com/anubra266/choc-autocomplete/commits?author=anubra266" title="Code">💻</a></td>
|
|
1014
1024
|
<td align="center"><a href="http://margalit.com.au"><img src="https://avatars.githubusercontent.com/u/2268424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sam Margalit</b></sub></a><br /><a href="https://github.com/anubra266/choc-autocomplete/commits?author=margalit" title="Documentation">📖</a></td>
|
|
1015
1025
|
<td align="center"><a href="https://github.com/gepd"><img src="https://avatars.githubusercontent.com/u/7091609?v=4?s=100" width="100px;" alt=""/><br /><sub><b>gepd</b></sub></a><br /><a href="https://github.com/anubra266/choc-autocomplete/commits?author=gepd" title="Code">💻</a> <a href="https://github.com/anubra266/choc-autocomplete/issues?q=author%3Agepd" title="Bug reports">🐛</a></td>
|
|
1016
|
-
<td align="center"><a href="https://github.com/Buupu"><img src="https://avatars.githubusercontent.com/u/26443341?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sammy Fattah</b></sub></a><br /><a href="https://github.com/anubra266/choc-autocomplete/commits?author=Buupu" title="Code">💻</a></td>
|
|
1017
1026
|
</tr>
|
|
1018
1027
|
</table>
|
|
1019
1028
|
|
|
@@ -7,7 +7,6 @@ export interface AutoCompleteItemProps extends FlexProps {
|
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
_fixed?: CSSObject;
|
|
9
9
|
getValue?: (item: AutoCompleteItemProps["value"]) => any;
|
|
10
|
-
groupId?: string;
|
|
11
10
|
}
|
|
12
11
|
export declare const AutoCompleteItem: import("@chakra-ui/react").ComponentWithAs<"div", AutoCompleteItemProps>;
|
|
13
12
|
export declare const baseItemStyles: FlexProps;
|
package/dist/autocomplete.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { MaybeRenderProp } from "@chakra-ui/react-utils";
|
|
3
|
+
import { AutoCompleteRefMethods, UseAutoCompleteProps } from "./types";
|
|
4
|
+
export declare type AutoCompleteChildProps = {
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onOpen: () => void;
|
|
8
|
+
};
|
|
2
9
|
export interface AutoCompleteProps extends UseAutoCompleteProps {
|
|
3
|
-
children:
|
|
10
|
+
children: MaybeRenderProp<AutoCompleteChildProps>;
|
|
11
|
+
ref: React.RefObject<AutoCompleteRefMethods>;
|
|
4
12
|
}
|
|
5
13
|
export declare const AutoComplete: import("@chakra-ui/react").ComponentWithAs<"div", AutoCompleteProps>;
|
|
@@ -9,12 +9,13 @@ var React__default = _interopDefault(React);
|
|
|
9
9
|
var reactUtils = require('@chakra-ui/react-utils');
|
|
10
10
|
var react = require('@chakra-ui/react');
|
|
11
11
|
var utils = require('@chakra-ui/utils');
|
|
12
|
+
var reactNanny = require('react-nanny');
|
|
12
13
|
var layout = require('@chakra-ui/layout');
|
|
13
14
|
var tag = require('@chakra-ui/tag');
|
|
14
15
|
|
|
15
16
|
var _createContext = /*#__PURE__*/reactUtils.createContext({
|
|
16
17
|
name: "AutoCompleteContext",
|
|
17
|
-
errorMessage: "useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all
|
|
18
|
+
errorMessage: "useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`"
|
|
18
19
|
}),
|
|
19
20
|
AutoCompleteProvider = _createContext[0],
|
|
20
21
|
useAutoCompleteContext = _createContext[1];
|
|
@@ -136,6 +137,9 @@ function fuzzyScore(str1, str2, gramSize) {
|
|
|
136
137
|
return hits / total;
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
var getDefItemValue = function getDefItemValue(item) {
|
|
141
|
+
return (typeof item === "string" ? item : item[Object.keys(item)[0]]).toString();
|
|
142
|
+
};
|
|
139
143
|
var setEmphasis = function setEmphasis(children, query) {
|
|
140
144
|
if (typeof children !== "string" || utils.isEmpty(query)) {
|
|
141
145
|
return children;
|
|
@@ -146,6 +150,25 @@ var setEmphasis = function setEmphasis(children, query) {
|
|
|
146
150
|
});
|
|
147
151
|
return newChildren;
|
|
148
152
|
};
|
|
153
|
+
var getItemList = function getItemList(children) {
|
|
154
|
+
var itemChildren = reactNanny.getChildrenDeep(children, function (child) {
|
|
155
|
+
var _child$type;
|
|
156
|
+
|
|
157
|
+
return (child == null ? void 0 : (_child$type = child.type) == null ? void 0 : _child$type.displayName) === "AutoCompleteItem";
|
|
158
|
+
});
|
|
159
|
+
return itemChildren.map(function (item) {
|
|
160
|
+
var itemObj = utils.pick(item.props, ["value", "label", "fixed", "disabled"]);
|
|
161
|
+
var _item$props$getValue = item.props.getValue,
|
|
162
|
+
getValue = _item$props$getValue === void 0 ? getDefItemValue : _item$props$getValue;
|
|
163
|
+
var value = getValue(itemObj.value);
|
|
164
|
+
var finObj = utils.isDefined(itemObj.label) ? itemObj : _extends({}, itemObj, {
|
|
165
|
+
label: value
|
|
166
|
+
});
|
|
167
|
+
return _extends({}, finObj, {
|
|
168
|
+
value: value
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
149
172
|
var getFocusedStyles = function getFocusedStyles() {
|
|
150
173
|
return {
|
|
151
174
|
bg: "whiteAlpha.100",
|
|
@@ -176,16 +199,30 @@ var getMultipleWrapStyles = function getMultipleWrapStyles(themeInput, multiple)
|
|
|
176
199
|
});
|
|
177
200
|
};
|
|
178
201
|
|
|
179
|
-
var hasFirstItem = function hasFirstItem(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
202
|
+
var hasFirstItem = function hasFirstItem(children, firstItem) {
|
|
203
|
+
var result = reactNanny.getChildDeep(children, function (child) {
|
|
204
|
+
var _child$type;
|
|
205
|
+
|
|
206
|
+
return (child == null ? void 0 : (_child$type = child.type) == null ? void 0 : _child$type.displayName) === "AutoCompleteItem" && child.props.value === (firstItem == null ? void 0 : firstItem.value);
|
|
207
|
+
});
|
|
208
|
+
return result;
|
|
184
209
|
};
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
var hasLastItem = function hasLastItem(children, lastItem) {
|
|
211
|
+
var result = reactNanny.getChildDeep(children, function (child) {
|
|
212
|
+
var _child$type2;
|
|
213
|
+
|
|
214
|
+
return (child == null ? void 0 : (_child$type2 = child.type) == null ? void 0 : _child$type2.displayName) === "AutoCompleteItem" && child.props.value === (lastItem == null ? void 0 : lastItem.value);
|
|
188
215
|
});
|
|
216
|
+
return result;
|
|
217
|
+
};
|
|
218
|
+
var hasChildren = function hasChildren(children, filteredList) {
|
|
219
|
+
return utils.isDefined(reactNanny.getChildDeep(children, function (child) {
|
|
220
|
+
return filteredList.findIndex(function (i) {
|
|
221
|
+
var _child$props;
|
|
222
|
+
|
|
223
|
+
return i.value === ((_child$props = child.props) == null ? void 0 : _child$props.value);
|
|
224
|
+
}) >= 0;
|
|
225
|
+
}));
|
|
189
226
|
};
|
|
190
227
|
|
|
191
228
|
var _excluded = ["onBlur", "onChange", "onFocus", "onKeyDown", "variant", "wrapStyles"],
|
|
@@ -213,6 +250,7 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
213
250
|
listAllValuesOnFocus = autoCompleteProps.listAllValuesOnFocus,
|
|
214
251
|
maxSuggestions = autoCompleteProps.maxSuggestions,
|
|
215
252
|
multiple = autoCompleteProps.multiple,
|
|
253
|
+
onReady = autoCompleteProps.onReady,
|
|
216
254
|
defaultIsOpen = autoCompleteProps.defaultIsOpen,
|
|
217
255
|
_autoCompleteProps$sh = autoCompleteProps.shouldRenderSuggestions,
|
|
218
256
|
shouldRenderSuggestions = _autoCompleteProps$sh === void 0 ? function () {
|
|
@@ -229,22 +267,24 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
229
267
|
onClose = _useDisclosure.onClose,
|
|
230
268
|
onOpen = _useDisclosure.onOpen;
|
|
231
269
|
|
|
232
|
-
var
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
270
|
+
var children = utils.runIfFn(autoCompleteProps.children, {
|
|
271
|
+
isOpen: isOpen,
|
|
272
|
+
onClose: onClose,
|
|
273
|
+
onOpen: onOpen
|
|
274
|
+
});
|
|
275
|
+
var itemList = getItemList(children);
|
|
236
276
|
var inputRef = React.useRef(null);
|
|
237
277
|
var inputWrapperRef = React.useRef(null);
|
|
238
278
|
var listRef = React.useRef(null);
|
|
239
279
|
var interactionRef = React.useRef(null);
|
|
240
280
|
|
|
241
|
-
var
|
|
242
|
-
query =
|
|
243
|
-
setQuery =
|
|
281
|
+
var _useState = React.useState(""),
|
|
282
|
+
query = _useState[0],
|
|
283
|
+
setQuery = _useState[1];
|
|
244
284
|
|
|
245
|
-
var
|
|
246
|
-
values =
|
|
247
|
-
setValues =
|
|
285
|
+
var _useState2 = React.useState(defaultValues),
|
|
286
|
+
values = _useState2[0],
|
|
287
|
+
setValues = _useState2[1];
|
|
248
288
|
|
|
249
289
|
React.useEffect(function () {
|
|
250
290
|
if (!multiple && !utils.isEmpty(defaultValues)) {
|
|
@@ -252,13 +292,13 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
252
292
|
}
|
|
253
293
|
}, []);
|
|
254
294
|
|
|
255
|
-
var
|
|
256
|
-
focusedValue =
|
|
257
|
-
setFocusedValue =
|
|
295
|
+
var _useState3 = React.useState((_itemList$ = itemList[0]) == null ? void 0 : _itemList$.value),
|
|
296
|
+
focusedValue = _useState3[0],
|
|
297
|
+
setFocusedValue = _useState3[1];
|
|
258
298
|
|
|
259
|
-
var
|
|
260
|
-
listAll =
|
|
261
|
-
setListAll =
|
|
299
|
+
var _useState4 = React.useState(false),
|
|
300
|
+
listAll = _useState4[0],
|
|
301
|
+
setListAll = _useState4[1];
|
|
262
302
|
|
|
263
303
|
var maxSelections = autoCompleteProps.maxSelections || values.length + 1;
|
|
264
304
|
var filteredResults = itemList.filter(function (i) {
|
|
@@ -351,6 +391,13 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
351
391
|
if (query === itemValue) setQuery("");
|
|
352
392
|
};
|
|
353
393
|
|
|
394
|
+
var resetItems = function resetItems(focusInput) {
|
|
395
|
+
var _inputRef$current3;
|
|
396
|
+
|
|
397
|
+
setValues([]);
|
|
398
|
+
if (focusInput) (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.focus();
|
|
399
|
+
};
|
|
400
|
+
|
|
354
401
|
var tags = multiple ? values.map(function (tag) {
|
|
355
402
|
var _itemList$find;
|
|
356
403
|
|
|
@@ -363,12 +410,11 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
363
410
|
}
|
|
364
411
|
};
|
|
365
412
|
}) : [];
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
});
|
|
413
|
+
React.useEffect(function () {
|
|
414
|
+
utils.runIfFn(onReady, {
|
|
415
|
+
tags: tags
|
|
416
|
+
});
|
|
417
|
+
}, [values]);
|
|
372
418
|
|
|
373
419
|
var getInputProps = function getInputProps(props, themeInput) {
|
|
374
420
|
var _onBlur = props.onBlur,
|
|
@@ -383,16 +429,16 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
383
429
|
wrapper: _extends({
|
|
384
430
|
ref: inputWrapperRef,
|
|
385
431
|
onClick: function onClick() {
|
|
386
|
-
var _inputRef$
|
|
432
|
+
var _inputRef$current4;
|
|
387
433
|
|
|
388
|
-
inputRef == null ? void 0 : (_inputRef$
|
|
434
|
+
inputRef == null ? void 0 : (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
389
435
|
},
|
|
390
436
|
tabIndex: 0
|
|
391
437
|
}, getMultipleWrapStyles(themeInput, multiple), wrapStyles),
|
|
392
438
|
input: _extends({
|
|
393
439
|
isReadOnly: isReadOnly,
|
|
394
440
|
onFocus: function onFocus(e) {
|
|
395
|
-
utils.runIfFn(_onFocus);
|
|
441
|
+
utils.runIfFn(_onFocus, e);
|
|
396
442
|
if (autoCompleteProps.openOnFocus && !isReadOnly) onOpen();
|
|
397
443
|
if (autoCompleteProps.selectOnFocus) e.target.select();
|
|
398
444
|
if (listAllValuesOnFocus) setListAll(true);
|
|
@@ -400,7 +446,7 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
400
446
|
onBlur: function onBlur(e) {
|
|
401
447
|
var _inputWrapperRef$curr;
|
|
402
448
|
|
|
403
|
-
utils.runIfFn(_onBlur);
|
|
449
|
+
utils.runIfFn(_onBlur, e);
|
|
404
450
|
var listIsFocused = e.relatedTarget === (listRef == null ? void 0 : listRef.current);
|
|
405
451
|
var inputWrapperIsFocused = (_inputWrapperRef$curr = inputWrapperRef.current) == null ? void 0 : _inputWrapperRef$curr.contains(e.relatedTarget);
|
|
406
452
|
|
|
@@ -426,9 +472,9 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
426
472
|
var focusedItem = filteredList[focusedIndex];
|
|
427
473
|
|
|
428
474
|
if (key === "Enter") {
|
|
429
|
-
var _inputRef$
|
|
475
|
+
var _inputRef$current5;
|
|
430
476
|
|
|
431
|
-
if (focusedItem && !(focusedItem != null && focusedItem.disabled)) selectItem(focusedItem.value);else (_inputRef$
|
|
477
|
+
if (focusedItem && !(focusedItem != null && focusedItem.disabled)) selectItem(focusedItem.value);else (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus();
|
|
432
478
|
e.preventDefault();
|
|
433
479
|
return;
|
|
434
480
|
}
|
|
@@ -482,11 +528,9 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
482
528
|
};
|
|
483
529
|
};
|
|
484
530
|
|
|
485
|
-
var getDefItemValue = function getDefItemValue(item) {
|
|
486
|
-
return (typeof item === "string" ? item : item[Object.keys(item)[0]]).toString();
|
|
487
|
-
};
|
|
488
|
-
|
|
489
531
|
var getItemProps = function getItemProps(props) {
|
|
532
|
+
var _getValue;
|
|
533
|
+
|
|
490
534
|
var _fixed = props._fixed,
|
|
491
535
|
_focus = props._focus,
|
|
492
536
|
itemChild = props.children,
|
|
@@ -501,7 +545,7 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
501
545
|
sx = props.sx,
|
|
502
546
|
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
503
547
|
|
|
504
|
-
var value = getValue(valueProp).toString();
|
|
548
|
+
var value = (_getValue = getValue(valueProp)) == null ? void 0 : _getValue.toString();
|
|
505
549
|
var isFocused = value === focusedValue;
|
|
506
550
|
var isValidSuggestion = filteredList.findIndex(function (i) {
|
|
507
551
|
return i.value === value;
|
|
@@ -523,10 +567,10 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
523
567
|
userSelect: "none"
|
|
524
568
|
},
|
|
525
569
|
onClick: function onClick(e) {
|
|
526
|
-
var _inputRef$
|
|
570
|
+
var _inputRef$current6;
|
|
527
571
|
|
|
528
572
|
utils.runIfFn(_onClick, e);
|
|
529
|
-
if (!disabled) selectItem(value);else (_inputRef$
|
|
573
|
+
if (!disabled) selectItem(value);else (_inputRef$current6 = inputRef.current) == null ? void 0 : _inputRef$current6.focus();
|
|
530
574
|
},
|
|
531
575
|
onMouseOver: function onMouseOver(e) {
|
|
532
576
|
utils.runIfFn(_onMouseOver, e);
|
|
@@ -544,21 +588,19 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
544
588
|
}, isFocused && (_focus || getFocusedStyles()), fixed && _fixed, rest),
|
|
545
589
|
root: {
|
|
546
590
|
isValidSuggestion: isValidSuggestion,
|
|
547
|
-
setItemList: setItemList,
|
|
548
591
|
value: value
|
|
549
592
|
}
|
|
550
593
|
};
|
|
551
594
|
};
|
|
552
595
|
|
|
553
596
|
var getGroupProps = function getGroupProps(props) {
|
|
554
|
-
var hasItems = hasChildren(props, filteredList);
|
|
555
|
-
var lastItem = utils.getLastItem(filteredList.filter(function (i) {
|
|
556
|
-
return utils.isUndefined(i == null ? void 0 : i.noFilter);
|
|
557
|
-
}));
|
|
597
|
+
var hasItems = hasChildren(props.children, filteredList);
|
|
558
598
|
return {
|
|
559
599
|
divider: {
|
|
560
|
-
hasFirstChild: hasFirstItem(props, firstItem),
|
|
561
|
-
hasLastChild: hasLastItem(props,
|
|
600
|
+
hasFirstChild: hasFirstItem(props.children, firstItem),
|
|
601
|
+
hasLastChild: hasLastItem(props.children, utils.getLastItem(filteredList.filter(function (i) {
|
|
602
|
+
return utils.isUndefined(i == null ? void 0 : i.noFilter);
|
|
603
|
+
})))
|
|
562
604
|
},
|
|
563
605
|
group: {
|
|
564
606
|
display: hasItems ? "initial" : "none"
|
|
@@ -597,6 +639,8 @@ function useAutoComplete(autoCompleteProps) {
|
|
|
597
639
|
onClose: onClose,
|
|
598
640
|
onOpen: onOpen,
|
|
599
641
|
query: query,
|
|
642
|
+
removeItem: removeItem,
|
|
643
|
+
resetItems: resetItems,
|
|
600
644
|
setQuery: setQuery,
|
|
601
645
|
tags: tags,
|
|
602
646
|
values: values
|
|
@@ -608,7 +652,15 @@ var AutoComplete = /*#__PURE__*/react.forwardRef(function (props, ref) {
|
|
|
608
652
|
var children = context.children,
|
|
609
653
|
isOpen = context.isOpen,
|
|
610
654
|
onClose = context.onClose,
|
|
611
|
-
onOpen = context.onOpen
|
|
655
|
+
onOpen = context.onOpen,
|
|
656
|
+
resetItems = context.resetItems,
|
|
657
|
+
removeItem = context.removeItem;
|
|
658
|
+
React.useImperativeHandle(ref, function () {
|
|
659
|
+
return {
|
|
660
|
+
resetItems: resetItems,
|
|
661
|
+
removeItem: removeItem
|
|
662
|
+
};
|
|
663
|
+
});
|
|
612
664
|
return React__default.createElement(AutoCompleteProvider, {
|
|
613
665
|
value: context
|
|
614
666
|
}, React__default.createElement(react.Popover, {
|
|
@@ -643,7 +695,6 @@ var AutoCompleteItem = /*#__PURE__*/react.forwardRef(function (props, forwardedR
|
|
|
643
695
|
var itemProps = getItemProps(props);
|
|
644
696
|
var _itemProps$root = itemProps.root,
|
|
645
697
|
isValidSuggestion = _itemProps$root.isValidSuggestion,
|
|
646
|
-
setItemList = _itemProps$root.setItemList,
|
|
647
698
|
value = _itemProps$root.value;
|
|
648
699
|
var isFocused = focusedValue === value;
|
|
649
700
|
React.useEffect(function () {
|
|
@@ -655,14 +706,6 @@ var AutoCompleteItem = /*#__PURE__*/react.forwardRef(function (props, forwardedR
|
|
|
655
706
|
});
|
|
656
707
|
}, [isFocused, interactionRef]);
|
|
657
708
|
React.useEffect(function () {
|
|
658
|
-
var item = _extends({}, utils.pick(props, ["label", "fixed", "disabled", "groupId"]), {
|
|
659
|
-
itemVal: props.value,
|
|
660
|
-
value: value
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
setItemList(function (itemList) {
|
|
664
|
-
return [].concat(itemList, [item]);
|
|
665
|
-
});
|
|
666
709
|
if (typeof value !== "string") console.warn("wow");
|
|
667
710
|
if (typeof value !== "string" && utils.isUndefined(props.getValue)) console.error("You must define the `getValue` prop, when an Item's value is not a string");
|
|
668
711
|
}, []);
|
|
@@ -684,7 +727,7 @@ var baseItemStyles = {
|
|
|
684
727
|
mx: "2",
|
|
685
728
|
px: "2",
|
|
686
729
|
py: "2",
|
|
687
|
-
|
|
730
|
+
rounded: "md",
|
|
688
731
|
cursor: "pointer"
|
|
689
732
|
};
|
|
690
733
|
|
|
@@ -864,10 +907,10 @@ var baseStyles = {
|
|
|
864
907
|
py: "4",
|
|
865
908
|
opacity: "0",
|
|
866
909
|
bg: "#232934",
|
|
867
|
-
|
|
910
|
+
rounded: "md",
|
|
868
911
|
maxH: "350px",
|
|
869
912
|
border: "none",
|
|
870
|
-
|
|
913
|
+
shadow: "base",
|
|
871
914
|
pos: "absolute",
|
|
872
915
|
zIndex: "popover",
|
|
873
916
|
overflowY: "auto",
|
|
@@ -912,7 +955,9 @@ exports.AutoCompleteGroupTitle = AutoCompleteGroupTitle;
|
|
|
912
955
|
exports.AutoCompleteInput = AutoCompleteInput;
|
|
913
956
|
exports.AutoCompleteItem = AutoCompleteItem;
|
|
914
957
|
exports.AutoCompleteList = AutoCompleteList;
|
|
958
|
+
exports.AutoCompleteProvider = AutoCompleteProvider;
|
|
915
959
|
exports.AutoCompleteTag = AutoCompleteTag;
|
|
916
960
|
exports.baseItemStyles = baseItemStyles;
|
|
917
961
|
exports.useAutoComplete = useAutoComplete;
|
|
962
|
+
exports.useAutoCompleteContext = useAutoCompleteContext;
|
|
918
963
|
//# sourceMappingURL=chakra-autocomplete.cjs.development.js.map
|