related-ui-components 1.3.3 → 1.3.5

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 (188) hide show
  1. package/lib/commonjs/app.js +39 -20
  2. package/lib/commonjs/app.js.map +1 -1
  3. package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +358 -0
  4. package/lib/commonjs/components/DateRangePicker/DateRangePicker.js.map +1 -0
  5. package/lib/commonjs/components/DateRangePicker/index.js +4 -0
  6. package/lib/commonjs/components/DateRangePicker/index.js.map +1 -0
  7. package/lib/commonjs/components/Filters/Filters.js +1 -1
  8. package/lib/commonjs/components/Filters/Filters.js.map +1 -1
  9. package/lib/commonjs/components/Input/Input.js +2 -2
  10. package/lib/commonjs/components/Input/Input.js.map +1 -1
  11. package/lib/commonjs/components/NumericStepper/NumericStepper.js +103 -0
  12. package/lib/commonjs/components/NumericStepper/NumericStepper.js.map +1 -0
  13. package/lib/commonjs/components/NumericStepper/index.js +29 -0
  14. package/lib/commonjs/components/NumericStepper/index.js.map +1 -0
  15. package/lib/commonjs/components/SelectAmount/SelectAmount.js +189 -0
  16. package/lib/commonjs/components/SelectAmount/SelectAmount.js.map +1 -0
  17. package/lib/commonjs/components/SelectAmount/index.js +4 -0
  18. package/lib/commonjs/components/SelectAmount/index.js.map +1 -0
  19. package/lib/commonjs/components/Suggestions/SuggestionList.js +98 -0
  20. package/lib/commonjs/components/Suggestions/SuggestionList.js.map +1 -0
  21. package/lib/commonjs/components/TravelBooking/CarRentalForm.js +370 -0
  22. package/lib/commonjs/components/TravelBooking/CarRentalForm.js.map +1 -0
  23. package/lib/commonjs/components/TravelBooking/FlightForm.js +347 -0
  24. package/lib/commonjs/components/TravelBooking/FlightForm.js.map +1 -0
  25. package/lib/commonjs/components/TravelBooking/FlightSummary.js +257 -0
  26. package/lib/commonjs/components/TravelBooking/FlightSummary.js.map +1 -0
  27. package/lib/commonjs/components/TravelBooking/HotelForm.js +290 -0
  28. package/lib/commonjs/components/TravelBooking/HotelForm.js.map +1 -0
  29. package/lib/commonjs/components/TravelBooking/HotelSummary.js +246 -0
  30. package/lib/commonjs/components/TravelBooking/HotelSummary.js.map +1 -0
  31. package/lib/commonjs/components/TravelBooking/README.md +421 -0
  32. package/lib/commonjs/components/TravelBooking/SummaryBar.js +181 -0
  33. package/lib/commonjs/components/TravelBooking/SummaryBar.js.map +1 -0
  34. package/lib/commonjs/components/TravelBooking/TabSelector.js +115 -0
  35. package/lib/commonjs/components/TravelBooking/TabSelector.js.map +1 -0
  36. package/lib/commonjs/components/TravelBooking/TravelBooking.js +261 -0
  37. package/lib/commonjs/components/TravelBooking/TravelBooking.js.map +1 -0
  38. package/lib/commonjs/components/TravelBooking/index.js +22 -0
  39. package/lib/commonjs/components/TravelBooking/index.js.map +1 -0
  40. package/lib/commonjs/components/TravelBooking/types.js +15 -0
  41. package/lib/commonjs/components/TravelBooking/types.js.map +1 -0
  42. package/lib/commonjs/components/UnlockRewards/UnlockRewards.js +2 -2
  43. package/lib/commonjs/components/UnlockRewards/UnlockRewards.js.map +1 -1
  44. package/lib/commonjs/index.js +0 -5
  45. package/lib/commonjs/index.js.map +1 -1
  46. package/lib/module/app.js +43 -24
  47. package/lib/module/app.js.map +1 -1
  48. package/lib/module/components/DateRangePicker/DateRangePicker.js +350 -0
  49. package/lib/module/components/DateRangePicker/DateRangePicker.js.map +1 -0
  50. package/lib/module/components/DateRangePicker/index.js +4 -0
  51. package/lib/module/components/DateRangePicker/index.js.map +1 -0
  52. package/lib/module/components/Filters/Filters.js +1 -1
  53. package/lib/module/components/Filters/Filters.js.map +1 -1
  54. package/lib/module/components/Input/Input.js +2 -2
  55. package/lib/module/components/Input/Input.js.map +1 -1
  56. package/lib/module/components/NumericStepper/NumericStepper.js +96 -0
  57. package/lib/module/components/NumericStepper/NumericStepper.js.map +1 -0
  58. package/lib/module/components/NumericStepper/index.js +5 -0
  59. package/lib/module/components/NumericStepper/index.js.map +1 -0
  60. package/lib/module/components/SelectAmount/SelectAmount.js +184 -0
  61. package/lib/module/components/SelectAmount/SelectAmount.js.map +1 -0
  62. package/lib/module/components/SelectAmount/index.js +4 -0
  63. package/lib/module/components/SelectAmount/index.js.map +1 -0
  64. package/lib/module/components/Suggestions/SuggestionList.js +92 -0
  65. package/lib/module/components/Suggestions/SuggestionList.js.map +1 -0
  66. package/lib/module/components/TravelBooking/CarRentalForm.js +363 -0
  67. package/lib/module/components/TravelBooking/CarRentalForm.js.map +1 -0
  68. package/lib/module/components/TravelBooking/FlightForm.js +340 -0
  69. package/lib/module/components/TravelBooking/FlightForm.js.map +1 -0
  70. package/lib/module/components/TravelBooking/FlightSummary.js +254 -0
  71. package/lib/module/components/TravelBooking/FlightSummary.js.map +1 -0
  72. package/lib/module/components/TravelBooking/HotelForm.js +286 -0
  73. package/lib/module/components/TravelBooking/HotelForm.js.map +1 -0
  74. package/lib/module/components/TravelBooking/HotelSummary.js +239 -0
  75. package/lib/module/components/TravelBooking/HotelSummary.js.map +1 -0
  76. package/lib/module/components/TravelBooking/README.md +421 -0
  77. package/lib/module/components/TravelBooking/SummaryBar.js +174 -0
  78. package/lib/module/components/TravelBooking/SummaryBar.js.map +1 -0
  79. package/lib/module/components/TravelBooking/TabSelector.js +110 -0
  80. package/lib/module/components/TravelBooking/TabSelector.js.map +1 -0
  81. package/lib/module/components/TravelBooking/TravelBooking.js +243 -0
  82. package/lib/module/components/TravelBooking/TravelBooking.js.map +1 -0
  83. package/lib/module/components/TravelBooking/index.js +22 -0
  84. package/lib/module/components/TravelBooking/index.js.map +1 -0
  85. package/lib/module/components/TravelBooking/types.js +11 -0
  86. package/lib/module/components/TravelBooking/types.js.map +1 -0
  87. package/lib/module/components/UnlockRewards/UnlockRewards.js +2 -2
  88. package/lib/module/components/UnlockRewards/UnlockRewards.js.map +1 -1
  89. package/lib/module/index.js +7 -4
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/typescript/commonjs/app.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +25 -0
  93. package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/components/DateRangePicker/index.d.ts +1 -0
  95. package/lib/typescript/commonjs/components/DateRangePicker/index.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/components/NumericStepper/NumericStepper.d.ts +19 -0
  97. package/lib/typescript/commonjs/components/NumericStepper/NumericStepper.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/components/NumericStepper/index.d.ts +3 -0
  99. package/lib/typescript/commonjs/components/NumericStepper/index.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/components/SelectAmount/SelectAmount.d.ts +29 -0
  101. package/lib/typescript/commonjs/components/SelectAmount/SelectAmount.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/components/SelectAmount/index.d.ts +1 -0
  103. package/lib/typescript/commonjs/components/SelectAmount/index.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/components/Suggestions/SuggestionList.d.ts +14 -0
  105. package/lib/typescript/commonjs/components/Suggestions/SuggestionList.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/components/TravelBooking/CarRentalForm.d.ts +58 -0
  107. package/lib/typescript/commonjs/components/TravelBooking/CarRentalForm.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/components/TravelBooking/FlightForm.d.ts +57 -0
  109. package/lib/typescript/commonjs/components/TravelBooking/FlightForm.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/components/TravelBooking/FlightSummary.d.ts +41 -0
  111. package/lib/typescript/commonjs/components/TravelBooking/FlightSummary.d.ts.map +1 -0
  112. package/lib/typescript/commonjs/components/TravelBooking/HotelForm.d.ts +52 -0
  113. package/lib/typescript/commonjs/components/TravelBooking/HotelForm.d.ts.map +1 -0
  114. package/lib/typescript/commonjs/components/TravelBooking/HotelSummary.d.ts +44 -0
  115. package/lib/typescript/commonjs/components/TravelBooking/HotelSummary.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/components/TravelBooking/SummaryBar.d.ts +17 -0
  117. package/lib/typescript/commonjs/components/TravelBooking/SummaryBar.d.ts.map +1 -0
  118. package/lib/typescript/commonjs/components/TravelBooking/TabSelector.d.ts +17 -0
  119. package/lib/typescript/commonjs/components/TravelBooking/TabSelector.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/components/TravelBooking/TravelBooking.d.ts +84 -0
  121. package/lib/typescript/commonjs/components/TravelBooking/TravelBooking.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/components/TravelBooking/index.d.ts +1 -0
  123. package/lib/typescript/commonjs/components/TravelBooking/index.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/components/TravelBooking/types.d.ts +26 -0
  125. package/lib/typescript/commonjs/components/TravelBooking/types.d.ts.map +1 -0
  126. package/lib/typescript/commonjs/index.d.ts +0 -1
  127. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  128. package/lib/typescript/module/app.d.ts.map +1 -1
  129. package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +25 -0
  130. package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts.map +1 -0
  131. package/lib/typescript/module/components/DateRangePicker/index.d.ts +1 -0
  132. package/lib/typescript/module/components/DateRangePicker/index.d.ts.map +1 -0
  133. package/lib/typescript/module/components/NumericStepper/NumericStepper.d.ts +19 -0
  134. package/lib/typescript/module/components/NumericStepper/NumericStepper.d.ts.map +1 -0
  135. package/lib/typescript/module/components/NumericStepper/index.d.ts +3 -0
  136. package/lib/typescript/module/components/NumericStepper/index.d.ts.map +1 -0
  137. package/lib/typescript/module/components/SelectAmount/SelectAmount.d.ts +29 -0
  138. package/lib/typescript/module/components/SelectAmount/SelectAmount.d.ts.map +1 -0
  139. package/lib/typescript/module/components/SelectAmount/index.d.ts +1 -0
  140. package/lib/typescript/module/components/SelectAmount/index.d.ts.map +1 -0
  141. package/lib/typescript/module/components/Suggestions/SuggestionList.d.ts +14 -0
  142. package/lib/typescript/module/components/Suggestions/SuggestionList.d.ts.map +1 -0
  143. package/lib/typescript/module/components/TravelBooking/CarRentalForm.d.ts +58 -0
  144. package/lib/typescript/module/components/TravelBooking/CarRentalForm.d.ts.map +1 -0
  145. package/lib/typescript/module/components/TravelBooking/FlightForm.d.ts +57 -0
  146. package/lib/typescript/module/components/TravelBooking/FlightForm.d.ts.map +1 -0
  147. package/lib/typescript/module/components/TravelBooking/FlightSummary.d.ts +41 -0
  148. package/lib/typescript/module/components/TravelBooking/FlightSummary.d.ts.map +1 -0
  149. package/lib/typescript/module/components/TravelBooking/HotelForm.d.ts +52 -0
  150. package/lib/typescript/module/components/TravelBooking/HotelForm.d.ts.map +1 -0
  151. package/lib/typescript/module/components/TravelBooking/HotelSummary.d.ts +44 -0
  152. package/lib/typescript/module/components/TravelBooking/HotelSummary.d.ts.map +1 -0
  153. package/lib/typescript/module/components/TravelBooking/SummaryBar.d.ts +17 -0
  154. package/lib/typescript/module/components/TravelBooking/SummaryBar.d.ts.map +1 -0
  155. package/lib/typescript/module/components/TravelBooking/TabSelector.d.ts +17 -0
  156. package/lib/typescript/module/components/TravelBooking/TabSelector.d.ts.map +1 -0
  157. package/lib/typescript/module/components/TravelBooking/TravelBooking.d.ts +84 -0
  158. package/lib/typescript/module/components/TravelBooking/TravelBooking.d.ts.map +1 -0
  159. package/lib/typescript/module/components/TravelBooking/index.d.ts +1 -0
  160. package/lib/typescript/module/components/TravelBooking/index.d.ts.map +1 -0
  161. package/lib/typescript/module/components/TravelBooking/types.d.ts +26 -0
  162. package/lib/typescript/module/components/TravelBooking/types.d.ts.map +1 -0
  163. package/lib/typescript/module/index.d.ts +0 -1
  164. package/lib/typescript/module/index.d.ts.map +1 -1
  165. package/package.json +12 -8
  166. package/src/app.tsx +77 -13
  167. package/src/components/DateRangePicker/DateRangePicker.tsx +410 -0
  168. package/src/components/DateRangePicker/index.ts +2 -0
  169. package/src/components/Filters/Filters.tsx +1 -1
  170. package/src/components/Input/Input.tsx +1 -1
  171. package/src/components/NumericStepper/NumericStepper.tsx +117 -0
  172. package/src/components/NumericStepper/index.ts +2 -0
  173. package/src/components/SelectAmount/SelectAmount.tsx +217 -0
  174. package/src/components/SelectAmount/index.ts +2 -0
  175. package/src/components/Suggestions/SuggestionList.tsx +106 -0
  176. package/src/components/TravelBooking/CarRentalForm.tsx +440 -0
  177. package/src/components/TravelBooking/FlightForm.tsx +452 -0
  178. package/src/components/TravelBooking/FlightSummary.tsx +388 -0
  179. package/src/components/TravelBooking/HotelForm.tsx +365 -0
  180. package/src/components/TravelBooking/HotelSummary.tsx +340 -0
  181. package/src/components/TravelBooking/README.md +421 -0
  182. package/src/components/TravelBooking/SummaryBar.tsx +239 -0
  183. package/src/components/TravelBooking/TabSelector.tsx +158 -0
  184. package/src/components/TravelBooking/TravelBooking.tsx +407 -0
  185. package/src/components/TravelBooking/index.ts +20 -0
  186. package/src/components/TravelBooking/types.ts +28 -0
  187. package/src/components/UnlockRewards/UnlockRewards.tsx +2 -2
  188. package/src/index.ts +4 -4
@@ -0,0 +1,217 @@
1
+ import { useCallback, useMemo, useRef, useState } from "react";
2
+ import { ThemeType, useTheme } from "../../theme";
3
+ import {
4
+ View,
5
+ StyleSheet,
6
+ Text,
7
+ TouchableOpacity,
8
+ StyleProp,
9
+ ViewStyle,
10
+ TextStyle,
11
+ } from "react-native";
12
+ import Slider from "@react-native-community/slider";
13
+ import NumericStepper from "../NumericStepper/NumericStepper";
14
+
15
+ interface SelectAmountProps {
16
+ isRTL?: boolean;
17
+ pointsValue?: number;
18
+ minValue?: number;
19
+ maxValue?: number;
20
+ step?: number;
21
+ conversionRate?: number;
22
+ pointsLabel?: string;
23
+ currencyLabel?: string;
24
+ buttonText?: string;
25
+ title?: string;
26
+ containerStyle?: StyleProp<ViewStyle>;
27
+ titleStyle?: StyleProp<TextStyle>;
28
+ rowStyle?: StyleProp<ViewStyle>;
29
+ labelStyle?: StyleProp<TextStyle>;
30
+ currencyValueTextStyle?: StyleProp<TextStyle>;
31
+ stepperButtonStyle?: StyleProp<ViewStyle>;
32
+ stepperButtonTextStyle?: StyleProp<TextStyle>;
33
+ stepperValueTextStyle?: StyleProp<TextStyle>;
34
+ sliderContainerStyle?: StyleProp<ViewStyle>;
35
+ actionButtonStyle?: StyleProp<ViewStyle>;
36
+ actionButtonTextStyle?: StyleProp<TextStyle>;
37
+
38
+ onValueChange?: (value: number) => void;
39
+ onClick?: (value: number) => void;
40
+ }
41
+
42
+ const SelectAmount: React.FC<SelectAmountProps> = ({
43
+ isRTL,
44
+ conversionRate = 20,
45
+ minValue = 1,
46
+ maxValue = 1000,
47
+ pointsValue = 1,
48
+ step = 20,
49
+ title,
50
+ buttonText = "Redeem",
51
+ currencyLabel = "SAR",
52
+ pointsLabel = "points",
53
+ rowStyle,
54
+ labelStyle,
55
+ titleStyle,
56
+ containerStyle,
57
+ actionButtonStyle,
58
+ actionButtonTextStyle,
59
+ sliderContainerStyle,
60
+ stepperButtonStyle,
61
+ stepperButtonTextStyle,
62
+ stepperValueTextStyle,
63
+ currencyValueTextStyle,
64
+ onValueChange,
65
+ onClick,
66
+ }) => {
67
+ const { theme, isRTL: rtl } = useTheme();
68
+ isRTL = isRTL || rtl;
69
+
70
+ const styles = useMemo(() => themedStyles(theme, isRTL), [theme, isRTL]);
71
+
72
+ const sliding = useRef<boolean>(false);
73
+
74
+ const clampedInitialValue = Math.max(
75
+ minValue,
76
+ Math.min(maxValue, pointsValue)
77
+ );
78
+ const [currentValue, setCurrentValue] = useState(clampedInitialValue);
79
+
80
+ const currencyValue = useMemo(() => {
81
+ return conversionRate > 0 ? Math.ceil(currentValue / conversionRate) : 0;
82
+ }, [currentValue, conversionRate]);
83
+
84
+ const handleValueChange = useCallback(
85
+ (newValue: number) => {
86
+ let clampedValue = Math.max(minValue, Math.min(maxValue, newValue));
87
+
88
+ if (clampedValue !== currentValue && sliding.current) {
89
+ setCurrentValue(Math.round(clampedValue));
90
+ onValueChange?.(clampedValue);
91
+ }
92
+ },
93
+ [minValue, maxValue, step, currentValue]
94
+ );
95
+
96
+ const handleIncrement = () => {
97
+ setCurrentValue((prev) => prev + step);
98
+ };
99
+
100
+ const handleDecrement = () => {
101
+ setCurrentValue((prev) => prev - step);
102
+ };
103
+
104
+ return (
105
+ <View style={[styles.mainContainer, containerStyle]}>
106
+ {title && <Text style={[styles.title, titleStyle]}>{title}</Text>}
107
+ <View>
108
+ <View style={[styles.row, rowStyle]}>
109
+ <Text style={[styles.label, labelStyle]}>{pointsLabel}</Text>
110
+ <NumericStepper
111
+ value={currentValue}
112
+ minValue={minValue}
113
+ maxValue={maxValue}
114
+ onIncrement={handleIncrement}
115
+ onDecrement={handleDecrement}
116
+ isRTL={isRTL}
117
+ buttonStyle={stepperButtonStyle}
118
+ buttonTextStyle={stepperButtonTextStyle}
119
+ valueTextStyle={stepperValueTextStyle}
120
+ />
121
+ </View>
122
+ <View style={[styles.row, rowStyle]}>
123
+ <Text style={[styles.label, labelStyle]}>{currencyLabel}</Text>
124
+ <View style={{ flexDirection: "row" }}>
125
+ <View style={[styles.controlButton, { opacity: 0 }]} />
126
+ <Text style={[styles.currencyValueText, currencyValueTextStyle]}>
127
+ {currencyValue}
128
+ </Text>
129
+ <View style={[styles.controlButton, { opacity: 0 }]} />
130
+ </View>
131
+ </View>
132
+ <Slider
133
+ step={step}
134
+ minimumValue={minValue}
135
+ maximumValue={maxValue}
136
+ onValueChange={handleValueChange}
137
+ onSlidingStart={() => (sliding.current = true)}
138
+ onSlidingComplete={() => (sliding.current = false)}
139
+ minimumTrackTintColor={theme.primary}
140
+ maximumTrackTintColor={theme.primary}
141
+ thumbTintColor={theme.primary}
142
+ inverted={isRTL}
143
+ style={sliderContainerStyle}
144
+ />
145
+ </View>
146
+ <TouchableOpacity
147
+ style={[styles.actionButton, actionButtonStyle]}
148
+ onPress={() => onClick?.(currentValue)}
149
+ >
150
+ <Text style={[styles.actionButtonText, actionButtonTextStyle]}>
151
+ {buttonText}
152
+ </Text>
153
+ </TouchableOpacity>
154
+ </View>
155
+ );
156
+ };
157
+
158
+ const themedStyles = (theme: ThemeType, isRTL: boolean) =>
159
+ StyleSheet.create({
160
+ mainContainer: {
161
+ width: "100%",
162
+ backgroundColor: theme.surface,
163
+ padding: 16,
164
+ },
165
+ row: {
166
+ flexDirection: isRTL ? "row-reverse" : "row",
167
+ justifyContent: "space-between",
168
+ alignItems: "center",
169
+ marginBottom: 12,
170
+ },
171
+ title: {
172
+ fontSize: 18,
173
+ fontWeight: "bold",
174
+ color: theme.onSurface,
175
+ marginBottom: 16,
176
+ textAlign: isRTL ? "right" : "left",
177
+ },
178
+ label: {
179
+ fontSize: 14,
180
+ color: theme.onSurface,
181
+ },
182
+ controlButton: {
183
+ backgroundColor: theme.secondary,
184
+ width: 36,
185
+ height: 36,
186
+ borderRadius: 18,
187
+ justifyContent: "center",
188
+ alignItems: "center",
189
+ },
190
+ actionButton: {
191
+ backgroundColor: theme.primary,
192
+ paddingVertical: 12,
193
+ paddingHorizontal: 20,
194
+ borderRadius: 6,
195
+ alignItems: "center",
196
+ marginTop: 16,
197
+ },
198
+ valueText: {
199
+ fontSize: 16,
200
+ color: theme.onSurface,
201
+ minWidth: 50,
202
+ textAlign: "center",
203
+ marginHorizontal: 8,
204
+ },
205
+ currencyValueText: {
206
+ fontSize: 16,
207
+ color: theme.primary,
208
+ minWidth: 50,
209
+ textAlign: "center",
210
+ marginHorizontal: 8,
211
+ },
212
+ actionButtonText: {
213
+ color: theme.onPrimary,
214
+ },
215
+ });
216
+
217
+ export default SelectAmount;
@@ -0,0 +1,2 @@
1
+ // export {default as SelectAmount} from "./SelectAmount";
2
+ // export * from "./SelectAmount";
@@ -0,0 +1,106 @@
1
+ import React from "react"; // Ensure React is imported
2
+ import {
3
+ View,
4
+ Text,
5
+ FlatList,
6
+ TouchableOpacity,
7
+ StyleSheet,
8
+ StyleProp,
9
+ ViewStyle,
10
+ TextStyle,
11
+ ListRenderItemInfo, // Import this type
12
+ } from "react-native";
13
+ import { ThemeType, useTheme } from "@/theme"; // Adjust import path
14
+
15
+ interface SuggestionListProps<T> {
16
+ data: T[];
17
+ visible: boolean;
18
+ renderItemContent: (item: T) => React.ReactNode; // Function to render item content
19
+ containerStyle?: StyleProp<ViewStyle>;
20
+ itemStyle?: StyleProp<ViewStyle>;
21
+ itemTextStyle?: StyleProp<TextStyle>; // Default text style
22
+ listStyle?: StyleProp<ViewStyle>;
23
+ }
24
+
25
+ const SuggestionList = <T extends unknown>({
26
+ data,
27
+ visible,
28
+ renderItemContent,
29
+ containerStyle,
30
+ itemStyle, // Style for the default wrapper
31
+ itemTextStyle, // Style for the default text
32
+ listStyle,
33
+ }: SuggestionListProps<T>) => {
34
+ const { theme } = useTheme();
35
+ const styles = suggestionStyles(theme);
36
+
37
+ if (!visible || data.length === 0) {
38
+ return null;
39
+ }
40
+
41
+ const renderListItem = ({ item }: ListRenderItemInfo<T>) => {
42
+ const content = renderItemContent(item);
43
+ if (React.isValidElement(content)) {
44
+ return content;
45
+ }
46
+
47
+ if (content === null || content === undefined) {
48
+ return null;
49
+ }
50
+
51
+ return (
52
+ <View style={[styles.suggestionItem, itemStyle]}>
53
+ <Text style={[styles.suggestionText, itemTextStyle]}>{String(content)}</Text>
54
+ </View>
55
+ );
56
+ };
57
+
58
+ return (
59
+ <View style={[styles.suggestionContainer, containerStyle]}>
60
+ <FlatList
61
+ data={data}
62
+ showsVerticalScrollIndicator={false}
63
+ keyExtractor={(_, index) => index.toString()}
64
+ renderItem={renderListItem} // Use the robust render function
65
+ style={[styles.list, listStyle]}
66
+ keyboardShouldPersistTaps="handled"
67
+ />
68
+ </View>
69
+ );
70
+ };
71
+
72
+ const suggestionStyles = (theme: ThemeType) =>
73
+ StyleSheet.create({
74
+ suggestionContainer: {
75
+ // ... (keep as before)
76
+ position: "absolute",
77
+ left: 0,
78
+ right: 0,
79
+ backgroundColor: theme.surface,
80
+ borderColor: theme.border,
81
+ top:"100%",
82
+ borderWidth: 1,
83
+ borderBottomRightRadius: 5,
84
+ borderBottomLeftRadius: 5,
85
+ padding: 12,
86
+ zIndex: 10,
87
+ maxHeight: 150,
88
+ },
89
+ list: {
90
+ flexGrow: 0,
91
+ // padding: 12
92
+ },
93
+ // Default wrapper style (used if renderItemContent returns primitive)
94
+ suggestionItem: {
95
+ padding: 12,
96
+ borderBottomWidth: StyleSheet.hairlineWidth,
97
+ borderBottomColor: theme.border,
98
+ },
99
+ // Default text style (used if renderItemContent returns primitive)
100
+ suggestionText: {
101
+ fontSize: 14,
102
+ color: theme.onSurface,
103
+ },
104
+ });
105
+
106
+ export default SuggestionList;