@yamada-ui/autocomplete 0.1.12 → 0.2.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/dist/autocomplete-create.d.ts +6 -0
- package/dist/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.d.ts +6 -0
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.ts +1 -1
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.ts +1 -1
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.ts +19 -1
- package/dist/autocomplete.js +23 -8
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-YQULJUTP.mjs → chunk-JDV5RP6W.mjs} +24 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -8
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.ts +40 -1
- package/dist/multi-autocomplete.js +23 -8
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-4995431c.d.ts → use-autocomplete-cbe9b443.d.ts} +86 -10
- package/dist/use-autocomplete.d.ts +1 -1
- package/dist/use-autocomplete.js +23 -8
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +8 -8
|
@@ -3,7 +3,13 @@ import { HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
4
|
|
|
5
5
|
type AutocompleteCreateOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The autocomplete create option icon to use.
|
|
8
|
+
*/
|
|
6
9
|
icon?: ReactElement;
|
|
10
|
+
/**
|
|
11
|
+
* The label of the autocomplete create option.
|
|
12
|
+
*/
|
|
7
13
|
children?: string | ((inputValue: string) => string);
|
|
8
14
|
};
|
|
9
15
|
type AutocompleteCreateProps = Omit<HTMLUIProps<'li'>, 'children'> & AutocompleteCreateOptions;
|
|
@@ -3,7 +3,13 @@ import { HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
4
|
|
|
5
5
|
type AutocompleteEmptyOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The autocomplete empty option icon to use.
|
|
8
|
+
*/
|
|
6
9
|
icon?: ReactElement;
|
|
10
|
+
/**
|
|
11
|
+
* The label of the autocomplete empty option.
|
|
12
|
+
*/
|
|
7
13
|
children?: string;
|
|
8
14
|
};
|
|
9
15
|
type AutocompleteEmptyProps = Omit<HTMLUIProps<'li'>, 'children'> & AutocompleteEmptyOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-cbe9b443.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export {
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-cbe9b443.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
package/dist/autocomplete.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
5
|
-
import { b as UseAutocompleteProps } from './use-autocomplete-
|
|
5
|
+
import { b as UseAutocompleteProps } from './use-autocomplete-cbe9b443.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
@@ -11,11 +11,29 @@ import '@yamada-ui/select';
|
|
|
11
11
|
import '@yamada-ui/utils';
|
|
12
12
|
|
|
13
13
|
type AutocompleteOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* The border color when the input is focused.
|
|
16
|
+
*/
|
|
14
17
|
focusBorderColor?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The border color when the input is invalid.
|
|
20
|
+
*/
|
|
15
21
|
errorBorderColor?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Props for autocomplete container element.
|
|
24
|
+
*/
|
|
16
25
|
containerProps?: Omit<HTMLUIProps<'div'>, 'children'>;
|
|
26
|
+
/**
|
|
27
|
+
* Props for autocomplete list element.
|
|
28
|
+
*/
|
|
17
29
|
listProps?: Omit<AutocompleteListProps, 'children'>;
|
|
30
|
+
/**
|
|
31
|
+
* Props for autocomplete input element.
|
|
32
|
+
*/
|
|
18
33
|
inputProps?: HTMLUIProps<'input'>;
|
|
34
|
+
/**
|
|
35
|
+
* Props for autocomplete icon element.
|
|
36
|
+
*/
|
|
19
37
|
iconProps?: AutocompleteIconProps;
|
|
20
38
|
};
|
|
21
39
|
type AutocompleteProps = ThemeProps<'Select'> & Omit<UseAutocompleteProps<string>, 'maxSelectedValues' | 'omitSelectedValues'> & AutocompleteOptions;
|
package/dist/autocomplete.js
CHANGED
|
@@ -380,8 +380,7 @@ var useAutocomplete = ({
|
|
|
380
380
|
closeOnBlur = true,
|
|
381
381
|
closeOnEsc = true,
|
|
382
382
|
createOption = false,
|
|
383
|
-
|
|
384
|
-
createSecondOrder = "first",
|
|
383
|
+
insertPositionOnCreate = "first",
|
|
385
384
|
emptyMessage = "No results found",
|
|
386
385
|
format = defaultFormat,
|
|
387
386
|
placement = "bottom-start",
|
|
@@ -420,6 +419,13 @@ var useAutocomplete = ({
|
|
|
420
419
|
const isCreate = focusedIndex === -2 && createOption;
|
|
421
420
|
const isMulti = (0, import_utils6.isArray)(value);
|
|
422
421
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
422
|
+
const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = (0, import_react.useMemo)(() => {
|
|
423
|
+
if ((0, import_utils6.isArray)(insertPositionOnCreate)) {
|
|
424
|
+
return insertPositionOnCreate;
|
|
425
|
+
} else {
|
|
426
|
+
return [insertPositionOnCreate, "first"];
|
|
427
|
+
}
|
|
428
|
+
}, [insertPositionOnCreate]);
|
|
423
429
|
if (createOption && !(0, import_utils6.isUndefined)(children)) {
|
|
424
430
|
console.warn(
|
|
425
431
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
@@ -703,21 +709,21 @@ var useAutocomplete = ({
|
|
|
703
709
|
let newOptions = [];
|
|
704
710
|
if (options)
|
|
705
711
|
newOptions = options;
|
|
706
|
-
if (
|
|
712
|
+
if (firstInsertPositionOnCreate === "first") {
|
|
707
713
|
newOptions = [newOption, ...newOptions];
|
|
708
|
-
} else if (
|
|
714
|
+
} else if (firstInsertPositionOnCreate === "last") {
|
|
709
715
|
newOptions = [...newOptions, newOption];
|
|
710
716
|
} else {
|
|
711
|
-
const i = newOptions.findIndex(({ label }) => label ===
|
|
717
|
+
const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
|
|
712
718
|
if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
|
|
713
|
-
if (
|
|
719
|
+
if (secondInsertPositionOnCreate === "first") {
|
|
714
720
|
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
715
721
|
} else {
|
|
716
722
|
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
717
723
|
}
|
|
718
724
|
} else {
|
|
719
725
|
console.warn(
|
|
720
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
726
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
|
|
721
727
|
);
|
|
722
728
|
}
|
|
723
729
|
}
|
|
@@ -727,7 +733,16 @@ var useAutocomplete = ({
|
|
|
727
733
|
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
728
734
|
setFocusedIndex(index);
|
|
729
735
|
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
730
|
-
}, [
|
|
736
|
+
}, [
|
|
737
|
+
inputValue,
|
|
738
|
+
options,
|
|
739
|
+
firstInsertPositionOnCreate,
|
|
740
|
+
onChange,
|
|
741
|
+
rebirthOptions,
|
|
742
|
+
rest,
|
|
743
|
+
secondInsertPositionOnCreate,
|
|
744
|
+
isMulti
|
|
745
|
+
]);
|
|
731
746
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
732
747
|
if (!isMulti) {
|
|
733
748
|
onChange("");
|
package/dist/autocomplete.mjs
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
import {
|
|
35
35
|
useCallback,
|
|
36
36
|
useEffect,
|
|
37
|
+
useMemo as useMemo2,
|
|
37
38
|
useRef as useRef2,
|
|
38
39
|
useState
|
|
39
40
|
} from "react";
|
|
@@ -729,8 +730,7 @@ var useAutocomplete = ({
|
|
|
729
730
|
closeOnBlur = true,
|
|
730
731
|
closeOnEsc = true,
|
|
731
732
|
createOption = false,
|
|
732
|
-
|
|
733
|
-
createSecondOrder = "first",
|
|
733
|
+
insertPositionOnCreate = "first",
|
|
734
734
|
emptyMessage = "No results found",
|
|
735
735
|
format = defaultFormat,
|
|
736
736
|
placement = "bottom-start",
|
|
@@ -769,6 +769,13 @@ var useAutocomplete = ({
|
|
|
769
769
|
const isCreate = focusedIndex === -2 && createOption;
|
|
770
770
|
const isMulti = isArray(value);
|
|
771
771
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
772
|
+
const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = useMemo2(() => {
|
|
773
|
+
if (isArray(insertPositionOnCreate)) {
|
|
774
|
+
return insertPositionOnCreate;
|
|
775
|
+
} else {
|
|
776
|
+
return [insertPositionOnCreate, "first"];
|
|
777
|
+
}
|
|
778
|
+
}, [insertPositionOnCreate]);
|
|
772
779
|
if (createOption && !isUndefined(children)) {
|
|
773
780
|
console.warn(
|
|
774
781
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
@@ -1052,21 +1059,21 @@ var useAutocomplete = ({
|
|
|
1052
1059
|
let newOptions = [];
|
|
1053
1060
|
if (options)
|
|
1054
1061
|
newOptions = options;
|
|
1055
|
-
if (
|
|
1062
|
+
if (firstInsertPositionOnCreate === "first") {
|
|
1056
1063
|
newOptions = [newOption, ...newOptions];
|
|
1057
|
-
} else if (
|
|
1064
|
+
} else if (firstInsertPositionOnCreate === "last") {
|
|
1058
1065
|
newOptions = [...newOptions, newOption];
|
|
1059
1066
|
} else {
|
|
1060
|
-
const i = newOptions.findIndex(({ label }) => label ===
|
|
1067
|
+
const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
|
|
1061
1068
|
if (i !== -1 && isArray(newOptions[i].value)) {
|
|
1062
|
-
if (
|
|
1069
|
+
if (secondInsertPositionOnCreate === "first") {
|
|
1063
1070
|
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
1064
1071
|
} else {
|
|
1065
1072
|
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
1066
1073
|
}
|
|
1067
1074
|
} else {
|
|
1068
1075
|
console.warn(
|
|
1069
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
1076
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
|
|
1070
1077
|
);
|
|
1071
1078
|
}
|
|
1072
1079
|
}
|
|
@@ -1076,7 +1083,16 @@ var useAutocomplete = ({
|
|
|
1076
1083
|
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
1077
1084
|
setFocusedIndex(index);
|
|
1078
1085
|
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
1079
|
-
}, [
|
|
1086
|
+
}, [
|
|
1087
|
+
inputValue,
|
|
1088
|
+
options,
|
|
1089
|
+
firstInsertPositionOnCreate,
|
|
1090
|
+
onChange,
|
|
1091
|
+
rebirthOptions,
|
|
1092
|
+
rest,
|
|
1093
|
+
secondInsertPositionOnCreate,
|
|
1094
|
+
isMulti
|
|
1095
|
+
]);
|
|
1080
1096
|
const onDelete = useCallback(() => {
|
|
1081
1097
|
if (!isMulti) {
|
|
1082
1098
|
onChange("");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Autocomplete, AutocompleteProps } from './autocomplete.js';
|
|
2
2
|
export { AutocompleteOptionGroup, AutocompleteOptionGroupProps } from './autocomplete-option-group.js';
|
|
3
|
-
export {
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-cbe9b443.js';
|
|
4
4
|
export { AutocompleteCreate, AutocompleteCreateProps } from './autocomplete-create.js';
|
|
5
5
|
export { AutocompleteEmpty, AutocompleteEmptyProps } from './autocomplete-empty.js';
|
|
6
6
|
export { MultiAutocomplete, MultiAutocompleteProps } from './multi-autocomplete.js';
|
package/dist/index.js
CHANGED
|
@@ -185,8 +185,7 @@ var useAutocomplete = ({
|
|
|
185
185
|
closeOnBlur = true,
|
|
186
186
|
closeOnEsc = true,
|
|
187
187
|
createOption = false,
|
|
188
|
-
|
|
189
|
-
createSecondOrder = "first",
|
|
188
|
+
insertPositionOnCreate = "first",
|
|
190
189
|
emptyMessage = "No results found",
|
|
191
190
|
format = defaultFormat,
|
|
192
191
|
placement = "bottom-start",
|
|
@@ -225,6 +224,13 @@ var useAutocomplete = ({
|
|
|
225
224
|
const isCreate = focusedIndex === -2 && createOption;
|
|
226
225
|
const isMulti = (0, import_utils.isArray)(value);
|
|
227
226
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
227
|
+
const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = (0, import_react.useMemo)(() => {
|
|
228
|
+
if ((0, import_utils.isArray)(insertPositionOnCreate)) {
|
|
229
|
+
return insertPositionOnCreate;
|
|
230
|
+
} else {
|
|
231
|
+
return [insertPositionOnCreate, "first"];
|
|
232
|
+
}
|
|
233
|
+
}, [insertPositionOnCreate]);
|
|
228
234
|
if (createOption && !(0, import_utils.isUndefined)(children)) {
|
|
229
235
|
console.warn(
|
|
230
236
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
@@ -508,21 +514,21 @@ var useAutocomplete = ({
|
|
|
508
514
|
let newOptions = [];
|
|
509
515
|
if (options)
|
|
510
516
|
newOptions = options;
|
|
511
|
-
if (
|
|
517
|
+
if (firstInsertPositionOnCreate === "first") {
|
|
512
518
|
newOptions = [newOption, ...newOptions];
|
|
513
|
-
} else if (
|
|
519
|
+
} else if (firstInsertPositionOnCreate === "last") {
|
|
514
520
|
newOptions = [...newOptions, newOption];
|
|
515
521
|
} else {
|
|
516
|
-
const i = newOptions.findIndex(({ label }) => label ===
|
|
522
|
+
const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
|
|
517
523
|
if (i !== -1 && (0, import_utils.isArray)(newOptions[i].value)) {
|
|
518
|
-
if (
|
|
524
|
+
if (secondInsertPositionOnCreate === "first") {
|
|
519
525
|
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
520
526
|
} else {
|
|
521
527
|
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
522
528
|
}
|
|
523
529
|
} else {
|
|
524
530
|
console.warn(
|
|
525
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
531
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
|
|
526
532
|
);
|
|
527
533
|
}
|
|
528
534
|
}
|
|
@@ -532,7 +538,16 @@ var useAutocomplete = ({
|
|
|
532
538
|
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
533
539
|
setFocusedIndex(index);
|
|
534
540
|
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
535
|
-
}, [
|
|
541
|
+
}, [
|
|
542
|
+
inputValue,
|
|
543
|
+
options,
|
|
544
|
+
firstInsertPositionOnCreate,
|
|
545
|
+
onChange,
|
|
546
|
+
rebirthOptions,
|
|
547
|
+
rest,
|
|
548
|
+
secondInsertPositionOnCreate,
|
|
549
|
+
isMulti
|
|
550
|
+
]);
|
|
536
551
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
537
552
|
if (!isMulti) {
|
|
538
553
|
onChange("");
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { FC, MouseEventHandler } from 'react';
|
|
4
4
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
5
5
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
6
|
-
import { b as UseAutocompleteProps } from './use-autocomplete-
|
|
6
|
+
import { b as UseAutocompleteProps } from './use-autocomplete-cbe9b443.js';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
@@ -11,21 +11,60 @@ import '@yamada-ui/select';
|
|
|
11
11
|
import '@yamada-ui/utils';
|
|
12
12
|
|
|
13
13
|
type MultiAutocompleteOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* The visual separator between each value.
|
|
16
|
+
*
|
|
17
|
+
* @default ','
|
|
18
|
+
*/
|
|
14
19
|
separator?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The custom display value to use.
|
|
22
|
+
*/
|
|
15
23
|
component?: FC<{
|
|
16
24
|
value: string | number;
|
|
17
25
|
displayValue: string;
|
|
18
26
|
index: number;
|
|
19
27
|
onRemove: MouseEventHandler<HTMLElement>;
|
|
20
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* If `true`, keep the placeholder.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
21
34
|
keepPlaceholder?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* If `true`, display the select clear icon.
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
22
40
|
isClearable?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The border color when the input is focused.
|
|
43
|
+
*/
|
|
23
44
|
focusBorderColor?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The border color when the input is invalid.
|
|
47
|
+
*/
|
|
24
48
|
errorBorderColor?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Props for multi autocomplete container element.
|
|
51
|
+
*/
|
|
25
52
|
containerProps?: Omit<HTMLUIProps<'div'>, 'children'>;
|
|
53
|
+
/**
|
|
54
|
+
* Props for multi autocomplete list element.
|
|
55
|
+
*/
|
|
26
56
|
listProps?: Omit<AutocompleteListProps, 'children'>;
|
|
57
|
+
/**
|
|
58
|
+
* Props for multi autocomplete input element.
|
|
59
|
+
*/
|
|
27
60
|
inputProps?: HTMLUIProps<'input'>;
|
|
61
|
+
/**
|
|
62
|
+
* Props for multi autocomplete icon element.
|
|
63
|
+
*/
|
|
28
64
|
iconProps?: AutocompleteIconProps;
|
|
65
|
+
/**
|
|
66
|
+
* Props for multi autocomplete clear icon element.
|
|
67
|
+
*/
|
|
29
68
|
clearIconProps?: AutocompleteIconProps;
|
|
30
69
|
};
|
|
31
70
|
type MultiAutocompleteProps = ThemeProps<'Select'> & UseAutocompleteProps<string[]> & MultiAutocompleteOptions;
|
|
@@ -381,8 +381,7 @@ var useAutocomplete = ({
|
|
|
381
381
|
closeOnBlur = true,
|
|
382
382
|
closeOnEsc = true,
|
|
383
383
|
createOption = false,
|
|
384
|
-
|
|
385
|
-
createSecondOrder = "first",
|
|
384
|
+
insertPositionOnCreate = "first",
|
|
386
385
|
emptyMessage = "No results found",
|
|
387
386
|
format = defaultFormat,
|
|
388
387
|
placement = "bottom-start",
|
|
@@ -421,6 +420,13 @@ var useAutocomplete = ({
|
|
|
421
420
|
const isCreate = focusedIndex === -2 && createOption;
|
|
422
421
|
const isMulti = (0, import_utils6.isArray)(value);
|
|
423
422
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
423
|
+
const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = (0, import_react.useMemo)(() => {
|
|
424
|
+
if ((0, import_utils6.isArray)(insertPositionOnCreate)) {
|
|
425
|
+
return insertPositionOnCreate;
|
|
426
|
+
} else {
|
|
427
|
+
return [insertPositionOnCreate, "first"];
|
|
428
|
+
}
|
|
429
|
+
}, [insertPositionOnCreate]);
|
|
424
430
|
if (createOption && !(0, import_utils6.isUndefined)(children)) {
|
|
425
431
|
console.warn(
|
|
426
432
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
@@ -704,21 +710,21 @@ var useAutocomplete = ({
|
|
|
704
710
|
let newOptions = [];
|
|
705
711
|
if (options)
|
|
706
712
|
newOptions = options;
|
|
707
|
-
if (
|
|
713
|
+
if (firstInsertPositionOnCreate === "first") {
|
|
708
714
|
newOptions = [newOption, ...newOptions];
|
|
709
|
-
} else if (
|
|
715
|
+
} else if (firstInsertPositionOnCreate === "last") {
|
|
710
716
|
newOptions = [...newOptions, newOption];
|
|
711
717
|
} else {
|
|
712
|
-
const i = newOptions.findIndex(({ label }) => label ===
|
|
718
|
+
const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
|
|
713
719
|
if (i !== -1 && (0, import_utils6.isArray)(newOptions[i].value)) {
|
|
714
|
-
if (
|
|
720
|
+
if (secondInsertPositionOnCreate === "first") {
|
|
715
721
|
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
716
722
|
} else {
|
|
717
723
|
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
718
724
|
}
|
|
719
725
|
} else {
|
|
720
726
|
console.warn(
|
|
721
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
727
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
|
|
722
728
|
);
|
|
723
729
|
}
|
|
724
730
|
}
|
|
@@ -728,7 +734,16 @@ var useAutocomplete = ({
|
|
|
728
734
|
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
729
735
|
setFocusedIndex(index);
|
|
730
736
|
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
731
|
-
}, [
|
|
737
|
+
}, [
|
|
738
|
+
inputValue,
|
|
739
|
+
options,
|
|
740
|
+
firstInsertPositionOnCreate,
|
|
741
|
+
onChange,
|
|
742
|
+
rebirthOptions,
|
|
743
|
+
rest,
|
|
744
|
+
secondInsertPositionOnCreate,
|
|
745
|
+
isMulti
|
|
746
|
+
]);
|
|
732
747
|
const onDelete = (0, import_react.useCallback)(() => {
|
|
733
748
|
if (!isMulti) {
|
|
734
749
|
onChange("");
|
|
@@ -9,6 +9,9 @@ import { UIOption } from '@yamada-ui/select';
|
|
|
9
9
|
import { PropGetter, Dict, DOMAttributes, Union } from '@yamada-ui/utils';
|
|
10
10
|
|
|
11
11
|
type AutocompleteOptionOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* The autocomplete option icon to use.
|
|
14
|
+
*/
|
|
12
15
|
icon?: ReactElement;
|
|
13
16
|
};
|
|
14
17
|
type AutocompleteOptionProps = UseAutocompleteOptionProps & AutocompleteOptionOptions;
|
|
@@ -3317,11 +3320,9 @@ declare const useAutocompleteDescendant: (options?: {
|
|
|
3317
3320
|
enabledIndex: number;
|
|
3318
3321
|
register: (node: HTMLElement | null) => void;
|
|
3319
3322
|
};
|
|
3320
|
-
type MaybeValue = string | string[];
|
|
3321
|
-
type Order = 'first' | 'last';
|
|
3322
3323
|
type AutocompleteContext = Omit<UseAutocompleteProps, 'value' | 'defaultValue' | 'onChange' | 'onCreate'> & {
|
|
3323
|
-
value:
|
|
3324
|
-
displayValue:
|
|
3324
|
+
value: string | string[];
|
|
3325
|
+
displayValue: string | string[] | undefined;
|
|
3325
3326
|
inputValue: string;
|
|
3326
3327
|
isHit: boolean;
|
|
3327
3328
|
isEmpty: boolean;
|
|
@@ -3348,25 +3349,76 @@ type AutocompleteContext = Omit<UseAutocompleteProps, 'value' | 'defaultValue' |
|
|
|
3348
3349
|
};
|
|
3349
3350
|
declare const AutocompleteProvider: react.Provider<AutocompleteContext>;
|
|
3350
3351
|
declare const useAutocompleteContext: () => AutocompleteContext;
|
|
3351
|
-
type UseAutocompleteBaseProps<T extends
|
|
3352
|
+
type UseAutocompleteBaseProps<T extends string | string[] = string> = Omit<PopoverProps, 'initialFocusRef' | 'closeOnButton' | 'isOpen' | 'trigger' | 'autoFocus' | 'restoreFocus' | 'openDelay' | 'closeDelay'> & FormControlOptions & {
|
|
3353
|
+
/**
|
|
3354
|
+
* The value of the autocomplete.
|
|
3355
|
+
*/
|
|
3352
3356
|
value?: T;
|
|
3357
|
+
/**
|
|
3358
|
+
* The initial value of the autocomplete.
|
|
3359
|
+
*/
|
|
3353
3360
|
defaultValue?: T;
|
|
3361
|
+
/**
|
|
3362
|
+
* The callback invoked when value state changes.
|
|
3363
|
+
*/
|
|
3354
3364
|
onChange?: (value: T) => void;
|
|
3365
|
+
/**
|
|
3366
|
+
* The callback invoked when search input.
|
|
3367
|
+
*/
|
|
3355
3368
|
onSearch?: (ev: ChangeEvent<HTMLInputElement>) => void;
|
|
3369
|
+
/**
|
|
3370
|
+
* The callback invoked when autocomlete option created.
|
|
3371
|
+
*/
|
|
3356
3372
|
onCreate?: (newOption: UIOption, newOptions: UIOption[]) => void;
|
|
3373
|
+
/**
|
|
3374
|
+
* Function to format text when search input.
|
|
3375
|
+
*/
|
|
3357
3376
|
format?: (value: string) => string;
|
|
3358
|
-
|
|
3359
|
-
|
|
3377
|
+
/**
|
|
3378
|
+
* The position to be inserted when the autocomplete option is created.
|
|
3379
|
+
*
|
|
3380
|
+
* @default 'first'
|
|
3381
|
+
*/
|
|
3382
|
+
insertPositionOnCreate?: Union<'first' | 'last'> | [string, 'first' | 'last'];
|
|
3383
|
+
/**
|
|
3384
|
+
* If `true`, the list element will be closed when value is selected.
|
|
3385
|
+
*
|
|
3386
|
+
* @default true
|
|
3387
|
+
*/
|
|
3360
3388
|
closeOnSelect?: boolean;
|
|
3389
|
+
/**
|
|
3390
|
+
* The message displayed when the search yields no hits.
|
|
3391
|
+
*
|
|
3392
|
+
* @default 'No results found'
|
|
3393
|
+
*/
|
|
3361
3394
|
emptyMessage?: string;
|
|
3395
|
+
/**
|
|
3396
|
+
* If `true`, enables the creation of autocomplete options.
|
|
3397
|
+
*
|
|
3398
|
+
* @default false
|
|
3399
|
+
*/
|
|
3362
3400
|
createOption?: boolean;
|
|
3401
|
+
/**
|
|
3402
|
+
* If `true`, the selected item(s) will be excluded from the list.
|
|
3403
|
+
*
|
|
3404
|
+
* @default false
|
|
3405
|
+
*/
|
|
3363
3406
|
omitSelectedValues?: boolean;
|
|
3407
|
+
/**
|
|
3408
|
+
* The maximum selectable value.
|
|
3409
|
+
*/
|
|
3364
3410
|
maxSelectedValues?: number;
|
|
3411
|
+
/**
|
|
3412
|
+
* Props for select option element.
|
|
3413
|
+
*/
|
|
3365
3414
|
optionProps?: Omit<AutocompleteOptionProps, 'value' | 'children'>;
|
|
3415
|
+
/**
|
|
3416
|
+
* If provided, generate options based on data.
|
|
3417
|
+
*/
|
|
3366
3418
|
options?: UIOption[];
|
|
3367
3419
|
};
|
|
3368
|
-
type UseAutocompleteProps<T extends
|
|
3369
|
-
declare const useAutocomplete: <T extends
|
|
3420
|
+
type UseAutocompleteProps<T extends string | string[] = string> = Omit<HTMLUIProps<'input'>, keyof UseAutocompleteBaseProps | 'list' | 'disabled' | 'required' | 'readOnly' | 'size'> & UseAutocompleteBaseProps<T>;
|
|
3421
|
+
declare const useAutocomplete: <T extends string | string[] = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, createOption, insertPositionOnCreate, emptyMessage, format, placement, duration, optionProps, placeholder, children, ...rest }: UseAutocompleteProps<T>) => {
|
|
3370
3422
|
id: string | undefined;
|
|
3371
3423
|
descendants: {
|
|
3372
3424
|
register: (nodeOrOptions: HTMLElement | {
|
|
@@ -4015,6 +4067,9 @@ declare const useAutocompleteList: () => {
|
|
|
4015
4067
|
getListProps: PropGetter;
|
|
4016
4068
|
};
|
|
4017
4069
|
type UseAutocompleteOptionGroupProps = HTMLUIProps<'ul'> & {
|
|
4070
|
+
/**
|
|
4071
|
+
* The label of the autocomplete option group.
|
|
4072
|
+
*/
|
|
4018
4073
|
label: string;
|
|
4019
4074
|
};
|
|
4020
4075
|
declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOptionGroupProps) => {
|
|
@@ -4024,10 +4079,31 @@ declare const useAutocompleteOptionGroup: ({ label, ...rest }: UseAutocompleteOp
|
|
|
4024
4079
|
};
|
|
4025
4080
|
type UseAutocompleteOptionGroupReturn = ReturnType<typeof useAutocompleteOptionGroup>;
|
|
4026
4081
|
type UseAutocompleteOptionProps = Omit<HTMLUIProps<'li'>, 'value' | 'children'> & {
|
|
4082
|
+
/**
|
|
4083
|
+
* The value of the select option.
|
|
4084
|
+
*/
|
|
4027
4085
|
value?: string;
|
|
4086
|
+
/**
|
|
4087
|
+
* The label of the select option.
|
|
4088
|
+
*/
|
|
4028
4089
|
children?: string;
|
|
4090
|
+
/**
|
|
4091
|
+
* If `true`, the select option will be disabled.
|
|
4092
|
+
*
|
|
4093
|
+
* @default false
|
|
4094
|
+
*/
|
|
4029
4095
|
isDisabled?: boolean;
|
|
4096
|
+
/**
|
|
4097
|
+
* If `true`, the select option will be focusable.
|
|
4098
|
+
*
|
|
4099
|
+
* @default false
|
|
4100
|
+
*/
|
|
4030
4101
|
isFocusable?: boolean;
|
|
4102
|
+
/**
|
|
4103
|
+
* If `true`, the list element will be closed when selected.
|
|
4104
|
+
*
|
|
4105
|
+
* @default false
|
|
4106
|
+
*/
|
|
4031
4107
|
closeOnSelect?: boolean;
|
|
4032
4108
|
};
|
|
4033
4109
|
declare const useAutocompleteOption: (props: UseAutocompleteOptionProps) => {
|
|
@@ -4047,4 +4123,4 @@ declare const useAutocompleteEmpty: () => {
|
|
|
4047
4123
|
};
|
|
4048
4124
|
type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>;
|
|
4049
4125
|
|
|
4050
|
-
export {
|
|
4126
|
+
export { AutocompleteOption as A, UseAutocompleteOptionGroupProps as U, AutocompleteOptionProps as a, UseAutocompleteProps as b, AutocompleteDescendantsContextProvider as c, useAutocompleteDescendants as d, useAutocompleteDescendant as e, AutocompleteProvider as f, useAutocompleteContext as g, useAutocomplete as h, UseAutocompleteReturn as i, useAutocompleteInput as j, UseAutocompleteInputReturn as k, useAutocompleteList as l, useAutocompleteOptionGroup as m, UseAutocompleteOptionGroupReturn as n, UseAutocompleteOptionProps as o, useAutocompleteOption as p, UseAutocompleteOptionReturn as q, useAutocompleteCreate as r, UseAutocompleteCreateReturn as s, useAutocompleteEmpty as t, useAutocompleteDescendantsContext as u, UseAutocompleteEmptyReturn as v };
|
|
@@ -5,4 +5,4 @@ import '@yamada-ui/form-control';
|
|
|
5
5
|
import '@yamada-ui/popover';
|
|
6
6
|
import '@yamada-ui/select';
|
|
7
7
|
import '@yamada-ui/utils';
|
|
8
|
-
export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider,
|
|
8
|
+
export { c as AutocompleteDescendantsContextProvider, f as AutocompleteProvider, s as UseAutocompleteCreateReturn, v as UseAutocompleteEmptyReturn, k as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, n as UseAutocompleteOptionGroupReturn, o as UseAutocompleteOptionProps, q as UseAutocompleteOptionReturn, b as UseAutocompleteProps, i as UseAutocompleteReturn, h as useAutocomplete, g as useAutocompleteContext, r as useAutocompleteCreate, e as useAutocompleteDescendant, d as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, t as useAutocompleteEmpty, j as useAutocompleteInput, l as useAutocompleteList, p as useAutocompleteOption, m as useAutocompleteOptionGroup } from './use-autocomplete-cbe9b443.js';
|
package/dist/use-autocomplete.js
CHANGED
|
@@ -325,8 +325,7 @@ var useAutocomplete = ({
|
|
|
325
325
|
closeOnBlur = true,
|
|
326
326
|
closeOnEsc = true,
|
|
327
327
|
createOption = false,
|
|
328
|
-
|
|
329
|
-
createSecondOrder = "first",
|
|
328
|
+
insertPositionOnCreate = "first",
|
|
330
329
|
emptyMessage = "No results found",
|
|
331
330
|
format = defaultFormat,
|
|
332
331
|
placement = "bottom-start",
|
|
@@ -365,6 +364,13 @@ var useAutocomplete = ({
|
|
|
365
364
|
const isCreate = focusedIndex === -2 && createOption;
|
|
366
365
|
const isMulti = (0, import_utils4.isArray)(value);
|
|
367
366
|
const isEmptyValue = !isMulti ? !value : !value.length;
|
|
367
|
+
const [firstInsertPositionOnCreate, secondInsertPositionOnCreate] = (0, import_react2.useMemo)(() => {
|
|
368
|
+
if ((0, import_utils4.isArray)(insertPositionOnCreate)) {
|
|
369
|
+
return insertPositionOnCreate;
|
|
370
|
+
} else {
|
|
371
|
+
return [insertPositionOnCreate, "first"];
|
|
372
|
+
}
|
|
373
|
+
}, [insertPositionOnCreate]);
|
|
368
374
|
if (createOption && !(0, import_utils4.isUndefined)(children)) {
|
|
369
375
|
console.warn(
|
|
370
376
|
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'options' in props.`
|
|
@@ -648,21 +654,21 @@ var useAutocomplete = ({
|
|
|
648
654
|
let newOptions = [];
|
|
649
655
|
if (options)
|
|
650
656
|
newOptions = options;
|
|
651
|
-
if (
|
|
657
|
+
if (firstInsertPositionOnCreate === "first") {
|
|
652
658
|
newOptions = [newOption, ...newOptions];
|
|
653
|
-
} else if (
|
|
659
|
+
} else if (firstInsertPositionOnCreate === "last") {
|
|
654
660
|
newOptions = [...newOptions, newOption];
|
|
655
661
|
} else {
|
|
656
|
-
const i = newOptions.findIndex(({ label }) => label ===
|
|
662
|
+
const i = newOptions.findIndex(({ label }) => label === firstInsertPositionOnCreate);
|
|
657
663
|
if (i !== -1 && (0, import_utils4.isArray)(newOptions[i].value)) {
|
|
658
|
-
if (
|
|
664
|
+
if (secondInsertPositionOnCreate === "first") {
|
|
659
665
|
newOptions[i].value = [newOption, ...newOptions[i].value];
|
|
660
666
|
} else {
|
|
661
667
|
newOptions[i].value = [...newOptions[i].value, newOption];
|
|
662
668
|
}
|
|
663
669
|
} else {
|
|
664
670
|
console.warn(
|
|
665
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${
|
|
671
|
+
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionOnCreate}' specified in insertPositionOnCreate does not exist in the option group.`
|
|
666
672
|
);
|
|
667
673
|
}
|
|
668
674
|
}
|
|
@@ -672,7 +678,16 @@ var useAutocomplete = ({
|
|
|
672
678
|
const index = flattenOptions(newOptions).findIndex(({ value: value2 }) => value2 === inputValue);
|
|
673
679
|
setFocusedIndex(index);
|
|
674
680
|
(_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newOptions);
|
|
675
|
-
}, [
|
|
681
|
+
}, [
|
|
682
|
+
inputValue,
|
|
683
|
+
options,
|
|
684
|
+
firstInsertPositionOnCreate,
|
|
685
|
+
onChange,
|
|
686
|
+
rebirthOptions,
|
|
687
|
+
rest,
|
|
688
|
+
secondInsertPositionOnCreate,
|
|
689
|
+
isMulti
|
|
690
|
+
]);
|
|
676
691
|
const onDelete = (0, import_react2.useCallback)(() => {
|
|
677
692
|
if (!isMulti) {
|
|
678
693
|
onChange("");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/autocomplete",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Yamada UI autocomplete component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@yamada-ui/core": "0.
|
|
39
|
+
"@yamada-ui/core": "0.4.0",
|
|
40
40
|
"@yamada-ui/utils": "0.1.1",
|
|
41
|
-
"@yamada-ui/icon": "0.1
|
|
42
|
-
"@yamada-ui/select": "0.1
|
|
43
|
-
"@yamada-ui/form-control": "0.1
|
|
44
|
-
"@yamada-ui/popover": "0.1
|
|
41
|
+
"@yamada-ui/icon": "0.2.1",
|
|
42
|
+
"@yamada-ui/select": "0.2.1",
|
|
43
|
+
"@yamada-ui/form-control": "0.2.1",
|
|
44
|
+
"@yamada-ui/popover": "0.2.1",
|
|
45
45
|
"@yamada-ui/use-descendant": "0.1.1",
|
|
46
|
-
"@yamada-ui/use-clickable": "0.
|
|
46
|
+
"@yamada-ui/use-clickable": "0.2.0",
|
|
47
47
|
"@yamada-ui/use-outside-click": "0.1.1",
|
|
48
48
|
"@yamada-ui/use-controllable-state": "0.1.2"
|
|
49
49
|
},
|
|
@@ -79,6 +79,6 @@
|
|
|
79
79
|
"build:fast": "tsup src",
|
|
80
80
|
"clean": "rimraf dist .turbo",
|
|
81
81
|
"typecheck": "tsc --noEmit",
|
|
82
|
-
"gen:
|
|
82
|
+
"gen:docs": "tsx ../../../scripts/generate-docs"
|
|
83
83
|
}
|
|
84
84
|
}
|