@react-stately/autocomplete 3.0.0-nightly-f90799b33-241206
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 +3 -0
- package/dist/import.mjs +17 -0
- package/dist/main.js +22 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +17 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useAutocompleteState.main.js +38 -0
- package/dist/useAutocompleteState.main.js.map +1 -0
- package/dist/useAutocompleteState.mjs +33 -0
- package/dist/useAutocompleteState.module.js +33 -0
- package/dist/useAutocompleteState.module.js.map +1 -0
- package/package.json +35 -0
- package/src/index.ts +15 -0
- package/src/useAutocompleteState.ts +70 -0
package/README.md
ADDED
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {useAutocompleteState as $94680be9a48a8f2d$export$ce1595f6e1a63433} from "./useAutocompleteState.mjs";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export {$94680be9a48a8f2d$export$ce1595f6e1a63433 as useAutocompleteState};
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var $af5197e4b74cd279$exports = require("./useAutocompleteState.main.js");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "useAutocompleteState", () => $af5197e4b74cd279$exports.useAutocompleteState);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/autocomplete/src/index.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAutocompleteState} from './useAutocompleteState';\n\nexport type {AutocompleteProps, AutocompleteStateOptions, AutocompleteState} from './useAutocompleteState';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {useAutocompleteState as $94680be9a48a8f2d$export$ce1595f6e1a63433} from "./useAutocompleteState.module.js";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export {$94680be9a48a8f2d$export$ce1595f6e1a63433 as useAutocompleteState};
|
|
17
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/autocomplete/src/index.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAutocompleteState} from './useAutocompleteState';\n\nexport type {AutocompleteProps, AutocompleteStateOptions, AutocompleteState} from './useAutocompleteState';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export interface AutocompleteState {
|
|
3
|
+
/** The current value of the autocomplete input. */
|
|
4
|
+
inputValue: string;
|
|
5
|
+
/** Sets the value of the autocomplete input. */
|
|
6
|
+
setInputValue(value: string): void;
|
|
7
|
+
/** The id of the current aria-activedescendant of the autocomplete input. */
|
|
8
|
+
focusedNodeId: string | null;
|
|
9
|
+
/** Sets the id of the current aria-activedescendant of the autocomplete input. */
|
|
10
|
+
setFocusedNodeId(value: string | null): void;
|
|
11
|
+
}
|
|
12
|
+
export interface AutocompleteProps {
|
|
13
|
+
/** The value of the autocomplete input (controlled). */
|
|
14
|
+
inputValue?: string;
|
|
15
|
+
/** The default value of the autocomplete input (uncontrolled). */
|
|
16
|
+
defaultInputValue?: string;
|
|
17
|
+
/** Handler that is called when the autocomplete input value changes. */
|
|
18
|
+
onInputChange?: (value: string) => void;
|
|
19
|
+
/** The children wrapped by the autocomplete. Consists of at least an input element and a collection element to filter. */
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export interface AutocompleteStateOptions extends Omit<AutocompleteProps, 'children'> {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Provides state management for a autocomplete component.
|
|
26
|
+
*/
|
|
27
|
+
export function useAutocompleteState(props: AutocompleteStateOptions): AutocompleteState;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAeA;IACE,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,6EAA6E;IAC7E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kFAAkF;IAClF,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;CAC7C;AAED;IACE,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,0HAA0H;IAC1H,QAAQ,EAAE,SAAS,CAAA;CACpB;AAGD,yCAA0C,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC;CAAG;AAExF;;GAEG;AACH,qCAAqC,KAAK,EAAE,wBAAwB,GAAG,iBAAiB,CA0BvF","sources":["packages/@react-stately/autocomplete/src/packages/@react-stately/autocomplete/src/useAutocompleteState.ts","packages/@react-stately/autocomplete/src/packages/@react-stately/autocomplete/src/index.ts","packages/@react-stately/autocomplete/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAutocompleteState} from './useAutocompleteState';\n\nexport type {AutocompleteProps, AutocompleteStateOptions, AutocompleteState} from './useAutocompleteState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var $lcwab$react = require("react");
|
|
2
|
+
var $lcwab$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useAutocompleteState", () => $af5197e4b74cd279$export$ce1595f6e1a63433);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function $af5197e4b74cd279$export$ce1595f6e1a63433(props) {
|
|
23
|
+
let { onInputChange: propsOnInputChange, inputValue: propsInputValue, defaultInputValue: propsDefaultInputValue = '' } = props;
|
|
24
|
+
let onInputChange = (value)=>{
|
|
25
|
+
if (propsOnInputChange) propsOnInputChange(value);
|
|
26
|
+
};
|
|
27
|
+
let [focusedNodeId, setFocusedNodeId] = (0, $lcwab$react.useState)(null);
|
|
28
|
+
let [inputValue, setInputValue] = (0, $lcwab$reactstatelyutils.useControlledState)(propsInputValue, propsDefaultInputValue, onInputChange);
|
|
29
|
+
return {
|
|
30
|
+
inputValue: inputValue,
|
|
31
|
+
setInputValue: setInputValue,
|
|
32
|
+
focusedNodeId: focusedNodeId,
|
|
33
|
+
setFocusedNodeId: setFocusedNodeId
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=useAutocompleteState.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiCM,SAAS,0CAAqB,KAA+B;IAClE,IAAI,EACF,eAAe,kBAAkB,EACjC,YAAY,eAAe,EAC3B,mBAAmB,yBAAyB,EAAE,EAC/C,GAAG;IAEJ,IAAI,gBAAgB,CAAC;QACnB,IAAI,oBACF,mBAAmB;IAEvB;IAEA,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAChE,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,2CAAiB,EACjD,iBACA,wBACA;IAGF,OAAO;oBACL;uBACA;uBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/autocomplete/src/useAutocompleteState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface AutocompleteState {\n /** The current value of the autocomplete input. */\n inputValue: string,\n /** Sets the value of the autocomplete input. */\n setInputValue(value: string): void,\n /** The id of the current aria-activedescendant of the autocomplete input. */\n focusedNodeId: string | null,\n /** Sets the id of the current aria-activedescendant of the autocomplete input. */\n setFocusedNodeId(value: string | null): void\n}\n\nexport interface AutocompleteProps {\n /** The value of the autocomplete input (controlled). */\n inputValue?: string,\n /** The default value of the autocomplete input (uncontrolled). */\n defaultInputValue?: string,\n /** Handler that is called when the autocomplete input value changes. */\n onInputChange?: (value: string) => void,\n /** The children wrapped by the autocomplete. Consists of at least an input element and a collection element to filter. */\n children: ReactNode\n}\n\n// Emulate our other stately hooks which accept all \"base\" props even if not used\nexport interface AutocompleteStateOptions extends Omit<AutocompleteProps, 'children'> {}\n\n/**\n * Provides state management for a autocomplete component.\n */\nexport function useAutocompleteState(props: AutocompleteStateOptions): AutocompleteState {\n let {\n onInputChange: propsOnInputChange,\n inputValue: propsInputValue,\n defaultInputValue: propsDefaultInputValue = ''\n } = props;\n\n let onInputChange = (value) => {\n if (propsOnInputChange) {\n propsOnInputChange(value);\n }\n };\n\n let [focusedNodeId, setFocusedNodeId] = useState<string | null>(null);\n let [inputValue, setInputValue] = useControlledState(\n propsInputValue,\n propsDefaultInputValue!,\n onInputChange\n );\n\n return {\n inputValue,\n setInputValue,\n focusedNodeId,\n setFocusedNodeId\n };\n}\n"],"names":[],"version":3,"file":"useAutocompleteState.main.js.map"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {useState as $LM92H$useState} from "react";
|
|
2
|
+
import {useControlledState as $LM92H$useControlledState} from "@react-stately/utils";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $94680be9a48a8f2d$export$ce1595f6e1a63433(props) {
|
|
17
|
+
let { onInputChange: propsOnInputChange, inputValue: propsInputValue, defaultInputValue: propsDefaultInputValue = '' } = props;
|
|
18
|
+
let onInputChange = (value)=>{
|
|
19
|
+
if (propsOnInputChange) propsOnInputChange(value);
|
|
20
|
+
};
|
|
21
|
+
let [focusedNodeId, setFocusedNodeId] = (0, $LM92H$useState)(null);
|
|
22
|
+
let [inputValue, setInputValue] = (0, $LM92H$useControlledState)(propsInputValue, propsDefaultInputValue, onInputChange);
|
|
23
|
+
return {
|
|
24
|
+
inputValue: inputValue,
|
|
25
|
+
setInputValue: setInputValue,
|
|
26
|
+
focusedNodeId: focusedNodeId,
|
|
27
|
+
setFocusedNodeId: setFocusedNodeId
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export {$94680be9a48a8f2d$export$ce1595f6e1a63433 as useAutocompleteState};
|
|
33
|
+
//# sourceMappingURL=useAutocompleteState.module.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {useState as $LM92H$useState} from "react";
|
|
2
|
+
import {useControlledState as $LM92H$useControlledState} from "@react-stately/utils";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $94680be9a48a8f2d$export$ce1595f6e1a63433(props) {
|
|
17
|
+
let { onInputChange: propsOnInputChange, inputValue: propsInputValue, defaultInputValue: propsDefaultInputValue = '' } = props;
|
|
18
|
+
let onInputChange = (value)=>{
|
|
19
|
+
if (propsOnInputChange) propsOnInputChange(value);
|
|
20
|
+
};
|
|
21
|
+
let [focusedNodeId, setFocusedNodeId] = (0, $LM92H$useState)(null);
|
|
22
|
+
let [inputValue, setInputValue] = (0, $LM92H$useControlledState)(propsInputValue, propsDefaultInputValue, onInputChange);
|
|
23
|
+
return {
|
|
24
|
+
inputValue: inputValue,
|
|
25
|
+
setInputValue: setInputValue,
|
|
26
|
+
focusedNodeId: focusedNodeId,
|
|
27
|
+
setFocusedNodeId: setFocusedNodeId
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export {$94680be9a48a8f2d$export$ce1595f6e1a63433 as useAutocompleteState};
|
|
33
|
+
//# sourceMappingURL=useAutocompleteState.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiCM,SAAS,0CAAqB,KAA+B;IAClE,IAAI,EACF,eAAe,kBAAkB,EACjC,YAAY,eAAe,EAC3B,mBAAmB,yBAAyB,EAAE,EAC/C,GAAG;IAEJ,IAAI,gBAAgB,CAAC;QACnB,IAAI,oBACF,mBAAmB;IAEvB;IAEA,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAChE,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yBAAiB,EACjD,iBACA,wBACA;IAGF,OAAO;oBACL;uBACA;uBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/autocomplete/src/useAutocompleteState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface AutocompleteState {\n /** The current value of the autocomplete input. */\n inputValue: string,\n /** Sets the value of the autocomplete input. */\n setInputValue(value: string): void,\n /** The id of the current aria-activedescendant of the autocomplete input. */\n focusedNodeId: string | null,\n /** Sets the id of the current aria-activedescendant of the autocomplete input. */\n setFocusedNodeId(value: string | null): void\n}\n\nexport interface AutocompleteProps {\n /** The value of the autocomplete input (controlled). */\n inputValue?: string,\n /** The default value of the autocomplete input (uncontrolled). */\n defaultInputValue?: string,\n /** Handler that is called when the autocomplete input value changes. */\n onInputChange?: (value: string) => void,\n /** The children wrapped by the autocomplete. Consists of at least an input element and a collection element to filter. */\n children: ReactNode\n}\n\n// Emulate our other stately hooks which accept all \"base\" props even if not used\nexport interface AutocompleteStateOptions extends Omit<AutocompleteProps, 'children'> {}\n\n/**\n * Provides state management for a autocomplete component.\n */\nexport function useAutocompleteState(props: AutocompleteStateOptions): AutocompleteState {\n let {\n onInputChange: propsOnInputChange,\n inputValue: propsInputValue,\n defaultInputValue: propsDefaultInputValue = ''\n } = props;\n\n let onInputChange = (value) => {\n if (propsOnInputChange) {\n propsOnInputChange(value);\n }\n };\n\n let [focusedNodeId, setFocusedNodeId] = useState<string | null>(null);\n let [inputValue, setInputValue] = useControlledState(\n propsInputValue,\n propsDefaultInputValue!,\n onInputChange\n );\n\n return {\n inputValue,\n setInputValue,\n focusedNodeId,\n setFocusedNodeId\n };\n}\n"],"names":[],"version":3,"file":"useAutocompleteState.module.js.map"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-stately/autocomplete",
|
|
3
|
+
"version": "3.0.0-nightly-f90799b33-241206",
|
|
4
|
+
"description": "Spectrum UI components in React",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types.d.ts",
|
|
14
|
+
"source": "src/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-stately/utils": "^3.0.0-nightly-f90799b33-241206",
|
|
26
|
+
"@swc/helpers": "^0.5.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"stableVersion": "3.0.0-alpha.1"
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export {useAutocompleteState} from './useAutocompleteState';
|
|
14
|
+
|
|
15
|
+
export type {AutocompleteProps, AutocompleteStateOptions, AutocompleteState} from './useAutocompleteState';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {ReactNode, useState} from 'react';
|
|
14
|
+
import {useControlledState} from '@react-stately/utils';
|
|
15
|
+
|
|
16
|
+
export interface AutocompleteState {
|
|
17
|
+
/** The current value of the autocomplete input. */
|
|
18
|
+
inputValue: string,
|
|
19
|
+
/** Sets the value of the autocomplete input. */
|
|
20
|
+
setInputValue(value: string): void,
|
|
21
|
+
/** The id of the current aria-activedescendant of the autocomplete input. */
|
|
22
|
+
focusedNodeId: string | null,
|
|
23
|
+
/** Sets the id of the current aria-activedescendant of the autocomplete input. */
|
|
24
|
+
setFocusedNodeId(value: string | null): void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AutocompleteProps {
|
|
28
|
+
/** The value of the autocomplete input (controlled). */
|
|
29
|
+
inputValue?: string,
|
|
30
|
+
/** The default value of the autocomplete input (uncontrolled). */
|
|
31
|
+
defaultInputValue?: string,
|
|
32
|
+
/** Handler that is called when the autocomplete input value changes. */
|
|
33
|
+
onInputChange?: (value: string) => void,
|
|
34
|
+
/** The children wrapped by the autocomplete. Consists of at least an input element and a collection element to filter. */
|
|
35
|
+
children: ReactNode
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Emulate our other stately hooks which accept all "base" props even if not used
|
|
39
|
+
export interface AutocompleteStateOptions extends Omit<AutocompleteProps, 'children'> {}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Provides state management for a autocomplete component.
|
|
43
|
+
*/
|
|
44
|
+
export function useAutocompleteState(props: AutocompleteStateOptions): AutocompleteState {
|
|
45
|
+
let {
|
|
46
|
+
onInputChange: propsOnInputChange,
|
|
47
|
+
inputValue: propsInputValue,
|
|
48
|
+
defaultInputValue: propsDefaultInputValue = ''
|
|
49
|
+
} = props;
|
|
50
|
+
|
|
51
|
+
let onInputChange = (value) => {
|
|
52
|
+
if (propsOnInputChange) {
|
|
53
|
+
propsOnInputChange(value);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
let [focusedNodeId, setFocusedNodeId] = useState<string | null>(null);
|
|
58
|
+
let [inputValue, setInputValue] = useControlledState(
|
|
59
|
+
propsInputValue,
|
|
60
|
+
propsDefaultInputValue!,
|
|
61
|
+
onInputChange
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
inputValue,
|
|
66
|
+
setInputValue,
|
|
67
|
+
focusedNodeId,
|
|
68
|
+
setFocusedNodeId
|
|
69
|
+
};
|
|
70
|
+
}
|