react-native-input-autosuggest 0.1.2 → 0.1.3

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/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 VLS
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VLS
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useState","View","TextInput","FlatList","Text","TouchableOpacity","StyleSheet","jsx","_jsx","jsxs","_jsxs","suggestions","id","name","InputAutoSugest","inputText","setInputText","filteredSuggestions","setFilteredSuggestions","handleSelect","item","renderItem","style","styles","suggestionItem","onPress","children","filtered","length","filter","toLowerCase","includes","container","input","value","onChangeText","data","keyExtractor","suggestionsList","create","zIndex","borderWidth","borderColor","padding","borderRadius","borderTopWidth","maxHeight","borderBottomWidth","borderBottomColor"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SAASC,IAAI,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAO7F,MAAMC,WAAyB,GAAG,CAChC;EAAEC,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAe,CAAC,EACjC;EAAED,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAe,CAAC,EACjC;EAAED,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAe,CAAC,EACjC;EAAED,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAe,CAAC,EACjC;EAAED,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAe,CAAC,CAClC;AAEC,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AACL,QAAQ;MACPiC,IAAI,EAAEnB,mBAAoB;MAC1BoB,YAAY,EAAGjB,IAAI,IAAKA,IAAI,CAACR,EAAG;MAChCS,UAAU,EAAEA,UAAW;MACvBC,KAAK,EAAEC,MAAM,CAACe;IAAgB,CAC/B,CACF;EAAA,CACG,CAAC;AAEX,CAAC;AAED,MAAMf,MAAM,GAAGjB,UAAU,CAACiC,MAAM,CAAC;EAC/BP,SAAS,EAAE;IACTQ,MAAM,EAAE,CAAC,CAAE;EACb,CAAC;EACDP,KAAK,EAAE;IACLQ,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,MAAM;IACnBC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE;EAChB,CAAC;EACDN,eAAe,EAAE;IACfG,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,MAAM;IACnBG,cAAc,EAAE,CAAC;IACjBC,SAAS,EAAE,GAAG,CAAE;EAClB,CAAC;EACDtB,cAAc,EAAE;IACdmB,OAAO,EAAE,EAAE;IACXI,iBAAiB,EAAE,CAAC;IACpBC,iBAAiB,EAAE;EACrB;AACF,CAAC,CAAC;AAEF,eAAelC,eAAe","ignoreList":[]}
1
+ {"version":3,"names":["React","useEffect","useState","View","TextInput","FlatList","Text","TouchableOpacity","StyleSheet","jsx","_jsx","jsxs","_jsxs","suggestions","id","name","InputAutoSugest","inputText","setInputText","filteredSuggestions","setFilteredSuggestions","handleSelect","item","renderItem","style","styles","suggestionItem","onPress","children","filtered","length","filter","toLowerCase","includes","container","input","value","onChangeText","data","keyExtractor","suggestionsList","create","zIndex","borderWidth","borderColor","padding","borderRadius","borderTopWidth","maxHeight","borderBottomWidth","borderBottomColor"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SAASC,IAAI,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,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,CAACe,WAAW,CAAC,CAAC,CAC1D,CAAC;IACH;IACAZ,sBAAsB,CAACS,QAAQ,CAAC;EAClC,CAAC,EAAE,CAACZ,SAAS,EAAEJ,WAAW,CAAC,CAAC;EAE5B,oBACED,KAAA,CAACT,IAAI;IAACqB,KAAK,EAAEC,MAAM,CAACS,SAAU;IAAAN,QAAA,gBAC5BlB,IAAA,CAACN,SAAS;MACRoB,KAAK,EAAEC,MAAM,CAACU,KAAM;MACpBC,KAAK,EAAEnB,SAAU;MACjBoB,YAAY,EAAEnB;IAAa,CAC5B,CAAC,EACDC,mBAAmB,CAACW,MAAM,GAAG,CAAC,iBAC7BpB,IAAA,CAACL,QAAQ;MACPiC,IAAI,EAAEnB,mBAAoB;MAC1BoB,YAAY,EAAGjB,IAAI,IAAKA,IAAI,CAACR,EAAG;MAChCS,UAAU,EAAEA,UAAW;MACvBC,KAAK,EAAEC,MAAM,CAACe;IAAgB,CAC/B,CACF;EAAA,CACG,CAAC;AAEX,CAAC;AAED,MAAMf,MAAM,GAAGjB,UAAU,CAACiC,MAAM,CAAC;EAC/BP,SAAS,EAAE;IACTQ,MAAM,EAAE,CAAC,CAAE;EACb,CAAC;EACDP,KAAK,EAAE;IACLQ,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,MAAM;IACnBC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE;EAChB,CAAC;EACDN,eAAe,EAAE;IACfG,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,MAAM;IACnBG,cAAc,EAAE,CAAC;IACjBC,SAAS,EAAE,GAAG,CAAE;EAClB,CAAC;EACDtB,cAAc,EAAE;IACdmB,OAAO,EAAE,EAAE;IACXI,iBAAiB,EAAE,CAAC;IACpBC,iBAAiB,EAAE;EACrB;AACF,CAAC,CAAC;AAEF,eAAelC,eAAe","ignoreList":[]}
package/package.json CHANGED
@@ -1,125 +1,124 @@
1
- {
2
- "name": "react-native-input-autosuggest",
3
- "version": "0.1.2",
4
- "description": "input autosuggest react native",
5
- "main": "./lib/module/index.js",
6
- "types": "./lib/typescript/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "source": "./src/index.tsx",
10
- "types": "./lib/typescript/src/index.d.ts",
11
- "default": "./lib/module/index.js"
12
- },
13
- "./package.json": "./package.json"
14
- },
15
- "files": [
16
- "src",
17
- "lib",
18
- "android",
19
- "ios",
20
- "cpp",
21
- "*.podspec",
22
- "react-native.config.js",
23
- "!ios/build",
24
- "!android/build",
25
- "!android/gradle",
26
- "!android/gradlew",
27
- "!android/gradlew.bat",
28
- "!android/local.properties",
29
- "!**/__tests__",
30
- "!**/__fixtures__",
31
- "!**/__mocks__",
32
- "!**/.*"
33
- ],
34
- "scripts": {
35
- "clean": "del-cli lib",
36
- "prepare": "bob build",
37
- "typecheck": "tsc",
38
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
- "test": "jest"
40
- },
41
- "keywords": [
42
- "react-native",
43
- "ios",
44
- "android"
45
- ],
46
- "repository": {
47
- "type": "git",
48
- "url": "git+https://github.com/vinils/react-native-input-autosuggest.git"
49
- },
50
- "author": "VLS <vini_ls@hotmail.com> (https://github.com/vinils)",
51
- "license": "MIT",
52
- "bugs": {
53
- "url": "https://github.com/vinils/react-native-input-autosuggest/issues"
54
- },
55
- "homepage": "https://github.com/vinils/react-native-input-autosuggest#readme",
56
- "publishConfig": {
57
- "registry": "https://registry.npmjs.org/"
58
- },
59
- "devDependencies": {
60
- "@eslint/compat": "^1.3.2",
61
- "@eslint/eslintrc": "^3.3.1",
62
- "@eslint/js": "^9.35.0",
63
- "@react-native/babel-preset": "0.81.1",
64
- "@react-native/eslint-config": "^0.81.1",
65
- "@types/jest": "^29.5.14",
66
- "@types/react": "^19.1.12",
67
- "@types/react-native": "^0.73.0",
68
- "del-cli": "^6.0.0",
69
- "eslint": "^9.35.0",
70
- "eslint-config-prettier": "^10.1.8",
71
- "eslint-plugin-prettier": "^5.5.4",
72
- "jest": "^29.7.0",
73
- "prettier": "^2.8.8",
74
- "react-native": "^0.82.1",
75
- "react-native-builder-bob": "^0.40.13",
76
- "typescript": "^5.9.2"
77
- },
78
- "peerDependencies": {
79
- "react": "*",
80
- "react-native": "*"
81
- },
82
- "packageManager": "yarn@4.11.0",
83
- "react-native-builder-bob": {
84
- "source": "src",
85
- "output": "lib",
86
- "targets": [
87
- [
88
- "module",
89
- {
90
- "esm": true
91
- }
92
- ],
93
- [
94
- "typescript",
95
- {
96
- "project": "tsconfig.build.json"
97
- }
98
- ]
99
- ]
100
- },
101
- "prettier": {
102
- "quoteProps": "consistent",
103
- "singleQuote": true,
104
- "tabWidth": 2,
105
- "trailingComma": "es5",
106
- "useTabs": false
107
- },
108
- "jest": {
109
- "preset": "react-native",
110
- "modulePathIgnorePatterns": [
111
- "<rootDir>/example/node_modules",
112
- "<rootDir>/lib/"
113
- ]
114
- },
115
- "create-react-native-library": {
116
- "typescript": true,
117
- "languages": "js",
118
- "type": "library",
119
- "tools": [
120
- "eslint",
121
- "jest"
122
- ],
123
- "version": "0.55.1"
124
- }
125
- }
1
+ {
2
+ "name": "react-native-input-autosuggest",
3
+ "version": "0.1.3",
4
+ "description": "input autosuggest react native",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "clean": "del-cli lib",
36
+ "prepare": "bob build",
37
+ "typecheck": "tsc",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "test": "jest"
40
+ },
41
+ "keywords": [
42
+ "react-native",
43
+ "ios",
44
+ "android"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/vinils/react-native-input-autosuggest.git"
49
+ },
50
+ "author": "VLS <vini_ls@hotmail.com> (https://github.com/vinils)",
51
+ "license": "MIT",
52
+ "bugs": {
53
+ "url": "https://github.com/vinils/react-native-input-autosuggest/issues"
54
+ },
55
+ "homepage": "https://github.com/vinils/react-native-input-autosuggest#readme",
56
+ "publishConfig": {
57
+ "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "devDependencies": {
60
+ "@eslint/compat": "^1.3.2",
61
+ "@eslint/eslintrc": "^3.3.1",
62
+ "@eslint/js": "^9.35.0",
63
+ "@react-native/babel-preset": "0.83.0",
64
+ "@react-native/eslint-config": "0.83.0",
65
+ "@types/jest": "^29.5.14",
66
+ "@types/react": "^19.1.12",
67
+ "del-cli": "^6.0.0",
68
+ "eslint": "^9.35.0",
69
+ "eslint-config-prettier": "^10.1.8",
70
+ "eslint-plugin-prettier": "^5.5.4",
71
+ "jest": "^29.7.0",
72
+ "prettier": "^2.8.8",
73
+ "react": "19.1.0",
74
+ "react-native": "0.81.5",
75
+ "react-native-builder-bob": "^0.40.17",
76
+ "typescript": "^5.9.2"
77
+ },
78
+ "peerDependencies": {
79
+ "react": "*",
80
+ "react-native": "*"
81
+ },
82
+ "packageManager": "yarn@4.11.0",
83
+ "react-native-builder-bob": {
84
+ "source": "src",
85
+ "output": "lib",
86
+ "targets": [
87
+ [
88
+ "module",
89
+ {
90
+ "esm": true
91
+ }
92
+ ],
93
+ [
94
+ "typescript",
95
+ {
96
+ "project": "tsconfig.build.json"
97
+ }
98
+ ]
99
+ ]
100
+ },
101
+ "prettier": {
102
+ "quoteProps": "consistent",
103
+ "singleQuote": true,
104
+ "tabWidth": 2,
105
+ "trailingComma": "es5",
106
+ "useTabs": false
107
+ },
108
+ "jest": {
109
+ "preset": "react-native",
110
+ "modulePathIgnorePatterns": [
111
+ "<rootDir>/example/node_modules",
112
+ "<rootDir>/lib/"
113
+ ]
114
+ },
115
+ "create-react-native-library": {
116
+ "type": "library",
117
+ "languages": "js",
118
+ "tools": [
119
+ "eslint",
120
+ "jest"
121
+ ],
122
+ "version": "0.56.1"
123
+ }
124
+ }
package/src/index.tsx CHANGED
@@ -1,84 +1,84 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { View, TextInput, FlatList, Text, TouchableOpacity, StyleSheet } from 'react-native';
3
-
4
- interface Suggestion {
5
- id: string;
6
- name: string;
7
- }
8
-
9
- const suggestions: Suggestion[] = [
10
- { id: '1', name: 'Suggestion 1' },
11
- { id: '2', name: 'Suggestion 2' },
12
- { id: '3', name: 'Suggestion 3' },
13
- { id: '4', name: 'Suggestion 4' },
14
- { id: '5', name: 'Suggestion 5' },
15
- ];
16
-
17
- export const InputAutoSugest: React.FC = () => {
18
- const [inputText, setInputText] = useState<string>('');
19
- const [filteredSuggestions, setFilteredSuggestions] = useState<Suggestion[]>([]);
20
-
21
- const handleSelect = (item: Suggestion) => {
22
- setInputText(item.name);
23
- };
24
-
25
- const renderItem = ({ item }: { item: Suggestion }) => (
26
- <TouchableOpacity style={styles.suggestionItem} onPress={() => handleSelect(item)}>
27
- <Text>{item.name}</Text>
28
- </TouchableOpacity>
29
- );
30
-
31
- useEffect(() => {
32
- var filtered: Suggestion[] = [];
33
-
34
- if (inputText.length > 0) {
35
- filtered = suggestions.filter(item =>
36
- item.name.toLowerCase().includes(inputText.toLowerCase())
37
- );
38
- }
39
- setFilteredSuggestions(filtered);
40
- }, [inputText, suggestions]);
41
-
42
- return (
43
- <View style={styles.container}>
44
- <TextInput
45
- style={styles.input}
46
- value={inputText}
47
- onChangeText={setInputText}
48
- />
49
- {filteredSuggestions.length > 0 && (
50
- <FlatList
51
- data={filteredSuggestions}
52
- keyExtractor={(item) => item.id}
53
- renderItem={renderItem}
54
- style={styles.suggestionsList}
55
- />
56
- )}
57
- </View>
58
- );
59
- };
60
-
61
- const styles = StyleSheet.create({
62
- container: {
63
- zIndex: 1, // Ensure suggestions appear above other content
64
- },
65
- input: {
66
- borderWidth: 1,
67
- borderColor: '#ccc',
68
- padding: 10,
69
- borderRadius: 5,
70
- },
71
- suggestionsList: {
72
- borderWidth: 1,
73
- borderColor: '#ccc',
74
- borderTopWidth: 0,
75
- maxHeight: 200, // Limit height of the suggestion list
76
- },
77
- suggestionItem: {
78
- padding: 10,
79
- borderBottomWidth: 1,
80
- borderBottomColor: '#eee',
81
- },
82
- });
83
-
84
- export default InputAutoSugest;
1
+ import React, { useEffect, useState } from 'react';
2
+ import { View, TextInput, FlatList, Text, TouchableOpacity, StyleSheet } from 'react-native';
3
+
4
+ interface Suggestion {
5
+ id: string;
6
+ name: string;
7
+ }
8
+
9
+ const suggestions: Suggestion[] = [
10
+ { id: '1', name: 'Suggestion 1' },
11
+ { id: '2', name: 'Suggestion 2' },
12
+ { id: '3', name: 'Suggestion 3' },
13
+ { id: '4', name: 'Suggestion 4' },
14
+ { id: '5', name: 'Suggestion 5' },
15
+ ];
16
+
17
+ export const InputAutoSugest: React.FC = () => {
18
+ const [inputText, setInputText] = useState<string>('');
19
+ const [filteredSuggestions, setFilteredSuggestions] = useState<Suggestion[]>([]);
20
+
21
+ const handleSelect = (item: Suggestion) => {
22
+ setInputText(item.name);
23
+ };
24
+
25
+ const renderItem = ({ item }: { item: Suggestion }) => (
26
+ <TouchableOpacity style={styles.suggestionItem} onPress={() => handleSelect(item)}>
27
+ <Text>{item.name}</Text>
28
+ </TouchableOpacity>
29
+ );
30
+
31
+ useEffect(() => {
32
+ var filtered: Suggestion[] = [];
33
+
34
+ if (inputText.length > 0) {
35
+ filtered = suggestions.filter(item =>
36
+ item.name.toLowerCase().includes(inputText.toLowerCase())
37
+ );
38
+ }
39
+ setFilteredSuggestions(filtered);
40
+ }, [inputText, suggestions]);
41
+
42
+ return (
43
+ <View style={styles.container}>
44
+ <TextInput
45
+ style={styles.input}
46
+ value={inputText}
47
+ onChangeText={setInputText}
48
+ />
49
+ {filteredSuggestions.length > 0 && (
50
+ <FlatList
51
+ data={filteredSuggestions}
52
+ keyExtractor={(item) => item.id}
53
+ renderItem={renderItem}
54
+ style={styles.suggestionsList}
55
+ />
56
+ )}
57
+ </View>
58
+ );
59
+ };
60
+
61
+ const styles = StyleSheet.create({
62
+ container: {
63
+ zIndex: 1, // Ensure suggestions appear above other content
64
+ },
65
+ input: {
66
+ borderWidth: 1,
67
+ borderColor: '#ccc',
68
+ padding: 10,
69
+ borderRadius: 5,
70
+ },
71
+ suggestionsList: {
72
+ borderWidth: 1,
73
+ borderColor: '#ccc',
74
+ borderTopWidth: 0,
75
+ maxHeight: 200, // Limit height of the suggestion list
76
+ },
77
+ suggestionItem: {
78
+ padding: 10,
79
+ borderBottomWidth: 1,
80
+ borderBottomColor: '#eee',
81
+ },
82
+ });
83
+
84
+ export default InputAutoSugest;