rn-searchable-textinput 0.1.1 → 2.0.0

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.
Files changed (42) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +122 -58
  3. package/lib/module/components/Dropdown.js +67 -0
  4. package/lib/module/components/Dropdown.js.map +1 -0
  5. package/lib/module/components/SearchableTextInput.js +113 -0
  6. package/lib/module/components/SearchableTextInput.js.map +1 -0
  7. package/lib/module/hooks/useDebounce.js +16 -0
  8. package/lib/module/hooks/useDebounce.js.map +1 -0
  9. package/lib/module/hooks/useDropdownLayout.js +28 -0
  10. package/lib/module/hooks/useDropdownLayout.js.map +1 -0
  11. package/lib/module/index.js +4 -0
  12. package/lib/module/index.js.map +1 -0
  13. package/lib/module/package.json +1 -0
  14. package/lib/module/styles/defaultStyles.js +68 -0
  15. package/lib/module/styles/defaultStyles.js.map +1 -0
  16. package/lib/module/types/index.js +4 -0
  17. package/lib/module/types/index.js.map +1 -0
  18. package/lib/typescript/package.json +1 -0
  19. package/lib/typescript/src/components/Dropdown.d.ts +20 -0
  20. package/lib/typescript/src/components/Dropdown.d.ts.map +1 -0
  21. package/lib/typescript/src/components/SearchableTextInput.d.ts +3 -0
  22. package/lib/typescript/src/components/SearchableTextInput.d.ts.map +1 -0
  23. package/lib/typescript/src/hooks/useDebounce.d.ts +2 -0
  24. package/lib/typescript/src/hooks/useDebounce.d.ts.map +1 -0
  25. package/lib/typescript/src/hooks/useDropdownLayout.d.ts +10 -0
  26. package/lib/typescript/src/hooks/useDropdownLayout.d.ts.map +1 -0
  27. package/lib/typescript/src/index.d.ts +3 -0
  28. package/lib/typescript/src/index.d.ts.map +1 -0
  29. package/lib/typescript/src/styles/defaultStyles.d.ts +63 -0
  30. package/lib/typescript/src/styles/defaultStyles.d.ts.map +1 -0
  31. package/lib/typescript/src/types/index.d.ts +27 -0
  32. package/lib/typescript/src/types/index.d.ts.map +1 -0
  33. package/package.json +166 -16
  34. package/src/components/Dropdown.tsx +99 -0
  35. package/src/components/SearchableTextInput.tsx +130 -0
  36. package/src/hooks/useDebounce.ts +17 -0
  37. package/src/hooks/useDropdownLayout.ts +27 -0
  38. package/src/index.tsx +2 -0
  39. package/src/styles/defaultStyles.ts +63 -0
  40. package/src/types/index.ts +36 -0
  41. package/components/searchable-text-input.js +0 -114
  42. package/index.js +0 -2
@@ -1,114 +0,0 @@
1
- import React, { useState } from "react";
2
- import {
3
- FlatList,
4
- View,
5
- TextInput,
6
- Text,
7
- StyleSheet,
8
- TouchableOpacity,
9
- SafeAreaView,
10
- } from "react-native";
11
- const SearchableTextInput = (props) => {
12
- const [changedText, onChangeText] = useState("");
13
- const [filteredTextInArray, setFilteredTextInArray] = useState([]);
14
- //NOTE: search the text entered in text-input and filter the array
15
- const findTextInArray = (query) => {
16
- //NOTE: avoid special char in text-input
17
- let filterdTextInput = query.replace(
18
- /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,
19
- ""
20
- );
21
- //NOTE: putting user enterd value in text-input
22
- onChangeText(filterdTextInput);
23
- //NOTE: filter the array with text entered by user
24
- if (filterdTextInput.length) {
25
- const regex = new RegExp(`${filterdTextInput.trim()}`, "i");
26
- setFilteredTextInArray(
27
- props.arrayWithSetOfValue.filter(
28
- (companyName) => companyName.search(regex) >= 0
29
- )
30
- );
31
- } else {
32
- setFilteredTextInArray([]);
33
- }
34
- };
35
- //NOTE: callback function to give user entered value to parent controller
36
- const handleOnChangeText = (changedTextValue) => {
37
- return props.handleOnChangeText(changedTextValue);
38
- };
39
- const listSeparator = () => {
40
- return <View style={[styles.listSeparator, props.listSeparatorStyle]} />;
41
- };
42
- return (
43
- <SafeAreaView style={styles.safeAreaView}>
44
- <View style={styles.mainView}>
45
- <View>
46
- <TextInput
47
- placeholder={props.placeholder}
48
- onChangeText={(text) => findTextInArray(text)}
49
- value={(handleOnChangeText(changedText), changedText)}
50
- autoFocus={true}
51
- style={[styles.autoCompleteResultText, props.textInputStyle]}
52
- />
53
- </View>
54
- <FlatList
55
- data={filteredTextInArray.slice(0, 5)}
56
- ItemSeparatorComponent={listSeparator}
57
- style={styles.flatList}
58
- keyExtractor={(item) => item}
59
- maxToRenderPerBatch={1}
60
- onEndThreshold={0}
61
- renderItem={({ item }) => (
62
- <TouchableOpacity
63
- onPress={() => {
64
- onChangeText(item);
65
- setFilteredTextInArray([]);
66
- }}
67
- >
68
- <View style={styles.flatListView}>
69
- <Text style={[props.searchTextStyle]}>{item}</Text>
70
- <Text>-</Text>
71
- </View>
72
- </TouchableOpacity>
73
- )}
74
- />
75
- </View>
76
- </SafeAreaView>
77
- );
78
- };
79
-
80
- const styles = StyleSheet.create({
81
- autoCompleteResultText: {
82
- borderColor: "#798777",
83
- borderWidth: 1,
84
- borderRadius: 16,
85
- height: 50,
86
- width: 300,
87
- padding: 10,
88
- },
89
- listSeparator: {
90
- borderWidth: 0.3,
91
- borderColor: "#DEDDE3",
92
- height: 1,
93
- borderRadius: 8,
94
- },
95
- flatList: {
96
- position: "absolute",
97
- top: 50,
98
- left: 0,
99
- right: 0,
100
- },
101
- flatListView: {
102
- flexDirection: "row",
103
- padding: 10,
104
- justifyContent: "space-between",
105
- },
106
- mainView: {
107
- justifyContent: "center",
108
- },
109
- safeAreaView: {
110
- alignContent: "center",
111
- },
112
- });
113
-
114
- export default SearchableTextInput;
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- import SearchableTextInput from "./components/searchable-text-input";
2
- export default SearchableTextInput;