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.
- package/lib/commonjs/app.js +39 -20
- package/lib/commonjs/app.js.map +1 -1
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +358 -0
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js.map +1 -0
- package/lib/commonjs/components/DateRangePicker/index.js +4 -0
- package/lib/commonjs/components/DateRangePicker/index.js.map +1 -0
- package/lib/commonjs/components/Filters/Filters.js +1 -1
- package/lib/commonjs/components/Filters/Filters.js.map +1 -1
- package/lib/commonjs/components/Input/Input.js +2 -2
- package/lib/commonjs/components/Input/Input.js.map +1 -1
- package/lib/commonjs/components/NumericStepper/NumericStepper.js +103 -0
- package/lib/commonjs/components/NumericStepper/NumericStepper.js.map +1 -0
- package/lib/commonjs/components/NumericStepper/index.js +29 -0
- package/lib/commonjs/components/NumericStepper/index.js.map +1 -0
- package/lib/commonjs/components/SelectAmount/SelectAmount.js +189 -0
- package/lib/commonjs/components/SelectAmount/SelectAmount.js.map +1 -0
- package/lib/commonjs/components/SelectAmount/index.js +4 -0
- package/lib/commonjs/components/SelectAmount/index.js.map +1 -0
- package/lib/commonjs/components/Suggestions/SuggestionList.js +98 -0
- package/lib/commonjs/components/Suggestions/SuggestionList.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/CarRentalForm.js +370 -0
- package/lib/commonjs/components/TravelBooking/CarRentalForm.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/FlightForm.js +347 -0
- package/lib/commonjs/components/TravelBooking/FlightForm.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/FlightSummary.js +257 -0
- package/lib/commonjs/components/TravelBooking/FlightSummary.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/HotelForm.js +290 -0
- package/lib/commonjs/components/TravelBooking/HotelForm.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/HotelSummary.js +246 -0
- package/lib/commonjs/components/TravelBooking/HotelSummary.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/README.md +421 -0
- package/lib/commonjs/components/TravelBooking/SummaryBar.js +181 -0
- package/lib/commonjs/components/TravelBooking/SummaryBar.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/TabSelector.js +115 -0
- package/lib/commonjs/components/TravelBooking/TabSelector.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/TravelBooking.js +261 -0
- package/lib/commonjs/components/TravelBooking/TravelBooking.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/index.js +22 -0
- package/lib/commonjs/components/TravelBooking/index.js.map +1 -0
- package/lib/commonjs/components/TravelBooking/types.js +15 -0
- package/lib/commonjs/components/TravelBooking/types.js.map +1 -0
- package/lib/commonjs/components/UnlockRewards/UnlockRewards.js +2 -2
- package/lib/commonjs/components/UnlockRewards/UnlockRewards.js.map +1 -1
- package/lib/commonjs/index.js +0 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/app.js +43 -24
- package/lib/module/app.js.map +1 -1
- package/lib/module/components/DateRangePicker/DateRangePicker.js +350 -0
- package/lib/module/components/DateRangePicker/DateRangePicker.js.map +1 -0
- package/lib/module/components/DateRangePicker/index.js +4 -0
- package/lib/module/components/DateRangePicker/index.js.map +1 -0
- package/lib/module/components/Filters/Filters.js +1 -1
- package/lib/module/components/Filters/Filters.js.map +1 -1
- package/lib/module/components/Input/Input.js +2 -2
- package/lib/module/components/Input/Input.js.map +1 -1
- package/lib/module/components/NumericStepper/NumericStepper.js +96 -0
- package/lib/module/components/NumericStepper/NumericStepper.js.map +1 -0
- package/lib/module/components/NumericStepper/index.js +5 -0
- package/lib/module/components/NumericStepper/index.js.map +1 -0
- package/lib/module/components/SelectAmount/SelectAmount.js +184 -0
- package/lib/module/components/SelectAmount/SelectAmount.js.map +1 -0
- package/lib/module/components/SelectAmount/index.js +4 -0
- package/lib/module/components/SelectAmount/index.js.map +1 -0
- package/lib/module/components/Suggestions/SuggestionList.js +92 -0
- package/lib/module/components/Suggestions/SuggestionList.js.map +1 -0
- package/lib/module/components/TravelBooking/CarRentalForm.js +363 -0
- package/lib/module/components/TravelBooking/CarRentalForm.js.map +1 -0
- package/lib/module/components/TravelBooking/FlightForm.js +340 -0
- package/lib/module/components/TravelBooking/FlightForm.js.map +1 -0
- package/lib/module/components/TravelBooking/FlightSummary.js +254 -0
- package/lib/module/components/TravelBooking/FlightSummary.js.map +1 -0
- package/lib/module/components/TravelBooking/HotelForm.js +286 -0
- package/lib/module/components/TravelBooking/HotelForm.js.map +1 -0
- package/lib/module/components/TravelBooking/HotelSummary.js +239 -0
- package/lib/module/components/TravelBooking/HotelSummary.js.map +1 -0
- package/lib/module/components/TravelBooking/README.md +421 -0
- package/lib/module/components/TravelBooking/SummaryBar.js +174 -0
- package/lib/module/components/TravelBooking/SummaryBar.js.map +1 -0
- package/lib/module/components/TravelBooking/TabSelector.js +110 -0
- package/lib/module/components/TravelBooking/TabSelector.js.map +1 -0
- package/lib/module/components/TravelBooking/TravelBooking.js +243 -0
- package/lib/module/components/TravelBooking/TravelBooking.js.map +1 -0
- package/lib/module/components/TravelBooking/index.js +22 -0
- package/lib/module/components/TravelBooking/index.js.map +1 -0
- package/lib/module/components/TravelBooking/types.js +11 -0
- package/lib/module/components/TravelBooking/types.js.map +1 -0
- package/lib/module/components/UnlockRewards/UnlockRewards.js +2 -2
- package/lib/module/components/UnlockRewards/UnlockRewards.js.map +1 -1
- package/lib/module/index.js +7 -4
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/app.d.ts.map +1 -1
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +25 -0
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/DateRangePicker/index.d.ts +1 -0
- package/lib/typescript/commonjs/components/DateRangePicker/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/NumericStepper/NumericStepper.d.ts +19 -0
- package/lib/typescript/commonjs/components/NumericStepper/NumericStepper.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/NumericStepper/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/NumericStepper/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/SelectAmount/SelectAmount.d.ts +29 -0
- package/lib/typescript/commonjs/components/SelectAmount/SelectAmount.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/SelectAmount/index.d.ts +1 -0
- package/lib/typescript/commonjs/components/SelectAmount/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Suggestions/SuggestionList.d.ts +14 -0
- package/lib/typescript/commonjs/components/Suggestions/SuggestionList.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/CarRentalForm.d.ts +58 -0
- package/lib/typescript/commonjs/components/TravelBooking/CarRentalForm.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/FlightForm.d.ts +57 -0
- package/lib/typescript/commonjs/components/TravelBooking/FlightForm.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/FlightSummary.d.ts +41 -0
- package/lib/typescript/commonjs/components/TravelBooking/FlightSummary.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/HotelForm.d.ts +52 -0
- package/lib/typescript/commonjs/components/TravelBooking/HotelForm.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/HotelSummary.d.ts +44 -0
- package/lib/typescript/commonjs/components/TravelBooking/HotelSummary.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/SummaryBar.d.ts +17 -0
- package/lib/typescript/commonjs/components/TravelBooking/SummaryBar.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/TabSelector.d.ts +17 -0
- package/lib/typescript/commonjs/components/TravelBooking/TabSelector.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/TravelBooking.d.ts +84 -0
- package/lib/typescript/commonjs/components/TravelBooking/TravelBooking.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/index.d.ts +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/TravelBooking/types.d.ts +26 -0
- package/lib/typescript/commonjs/components/TravelBooking/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +0 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/module/app.d.ts.map +1 -1
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +25 -0
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts.map +1 -0
- package/lib/typescript/module/components/DateRangePicker/index.d.ts +1 -0
- package/lib/typescript/module/components/DateRangePicker/index.d.ts.map +1 -0
- package/lib/typescript/module/components/NumericStepper/NumericStepper.d.ts +19 -0
- package/lib/typescript/module/components/NumericStepper/NumericStepper.d.ts.map +1 -0
- package/lib/typescript/module/components/NumericStepper/index.d.ts +3 -0
- package/lib/typescript/module/components/NumericStepper/index.d.ts.map +1 -0
- package/lib/typescript/module/components/SelectAmount/SelectAmount.d.ts +29 -0
- package/lib/typescript/module/components/SelectAmount/SelectAmount.d.ts.map +1 -0
- package/lib/typescript/module/components/SelectAmount/index.d.ts +1 -0
- package/lib/typescript/module/components/SelectAmount/index.d.ts.map +1 -0
- package/lib/typescript/module/components/Suggestions/SuggestionList.d.ts +14 -0
- package/lib/typescript/module/components/Suggestions/SuggestionList.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/CarRentalForm.d.ts +58 -0
- package/lib/typescript/module/components/TravelBooking/CarRentalForm.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/FlightForm.d.ts +57 -0
- package/lib/typescript/module/components/TravelBooking/FlightForm.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/FlightSummary.d.ts +41 -0
- package/lib/typescript/module/components/TravelBooking/FlightSummary.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/HotelForm.d.ts +52 -0
- package/lib/typescript/module/components/TravelBooking/HotelForm.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/HotelSummary.d.ts +44 -0
- package/lib/typescript/module/components/TravelBooking/HotelSummary.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/SummaryBar.d.ts +17 -0
- package/lib/typescript/module/components/TravelBooking/SummaryBar.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/TabSelector.d.ts +17 -0
- package/lib/typescript/module/components/TravelBooking/TabSelector.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/TravelBooking.d.ts +84 -0
- package/lib/typescript/module/components/TravelBooking/TravelBooking.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/index.d.ts +1 -0
- package/lib/typescript/module/components/TravelBooking/index.d.ts.map +1 -0
- package/lib/typescript/module/components/TravelBooking/types.d.ts +26 -0
- package/lib/typescript/module/components/TravelBooking/types.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +0 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/package.json +12 -8
- package/src/app.tsx +77 -13
- package/src/components/DateRangePicker/DateRangePicker.tsx +410 -0
- package/src/components/DateRangePicker/index.ts +2 -0
- package/src/components/Filters/Filters.tsx +1 -1
- package/src/components/Input/Input.tsx +1 -1
- package/src/components/NumericStepper/NumericStepper.tsx +117 -0
- package/src/components/NumericStepper/index.ts +2 -0
- package/src/components/SelectAmount/SelectAmount.tsx +217 -0
- package/src/components/SelectAmount/index.ts +2 -0
- package/src/components/Suggestions/SuggestionList.tsx +106 -0
- package/src/components/TravelBooking/CarRentalForm.tsx +440 -0
- package/src/components/TravelBooking/FlightForm.tsx +452 -0
- package/src/components/TravelBooking/FlightSummary.tsx +388 -0
- package/src/components/TravelBooking/HotelForm.tsx +365 -0
- package/src/components/TravelBooking/HotelSummary.tsx +340 -0
- package/src/components/TravelBooking/README.md +421 -0
- package/src/components/TravelBooking/SummaryBar.tsx +239 -0
- package/src/components/TravelBooking/TabSelector.tsx +158 -0
- package/src/components/TravelBooking/TravelBooking.tsx +407 -0
- package/src/components/TravelBooking/index.ts +20 -0
- package/src/components/TravelBooking/types.ts +28 -0
- package/src/components/UnlockRewards/UnlockRewards.tsx +2 -2
- 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,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;
|