@hoddy-ui/core 1.0.43 → 1.0.45
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/package.json +5 -5
- package/src/Components/StarRating.tsx +174 -0
- package/src/Components/TextField.tsx +16 -3
- package/src/types.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hoddy-ui/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
4
4
|
"description": "Core rich react native components written in typescript",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"repository": {
|
|
@@ -13,8 +13,12 @@
|
|
|
13
13
|
"private": false,
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@expo/vector-icons": "^13.0.0",
|
|
16
|
+
"@react-navigation/native": ">=6.1.7",
|
|
16
17
|
"@types/react": "^18.2.6",
|
|
17
18
|
"@types/react-native": "^0.72.0",
|
|
19
|
+
"expo-location": ">=15.1.1",
|
|
20
|
+
"expo-navigation-bar": ">=2.1.1",
|
|
21
|
+
"expo-system-ui": ">=2.2.1",
|
|
18
22
|
"react": "^18.2.0",
|
|
19
23
|
"react-native": ">=0.71.8",
|
|
20
24
|
"react-native-safe-area-context": ">=4.5.3",
|
|
@@ -29,10 +33,6 @@
|
|
|
29
33
|
],
|
|
30
34
|
"dependencies": {
|
|
31
35
|
"@react-native-async-storage/async-storage": "^1.18.1",
|
|
32
|
-
"@react-navigation/native": "^6.1.7",
|
|
33
|
-
"expo-location": "^15.1.1",
|
|
34
|
-
"expo-navigation-bar": "^2.1.1",
|
|
35
|
-
"expo-system-ui": "^2.2.1",
|
|
36
36
|
"react-native-size-matters": "^0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
2
|
+
import * as Haptics from "expo-haptics";
|
|
3
|
+
import { FC, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { Alert, TouchableOpacity, View } from "react-native";
|
|
5
|
+
import { TextInput } from "react-native-gesture-handler";
|
|
6
|
+
import { ScaledSheet } from "react-native-size-matters";
|
|
7
|
+
import { GlobalContext } from "../../context";
|
|
8
|
+
import colors from "../../theme/colors";
|
|
9
|
+
import Button from "./Button";
|
|
10
|
+
import Popup from "./Popup";
|
|
11
|
+
import Typography from "./Typography";
|
|
12
|
+
import { errorMessage } from "../../utility";
|
|
13
|
+
import client from "../../api/client";
|
|
14
|
+
import { useColors } from "../hooks";
|
|
15
|
+
import { RatingInputProps, RatingStarsProps, StarRatingProps } from "../types";
|
|
16
|
+
|
|
17
|
+
export const RatingStars: FC<RatingStarsProps> = ({
|
|
18
|
+
rating = 0,
|
|
19
|
+
size = 16,
|
|
20
|
+
}) => {
|
|
21
|
+
const colors = useColors();
|
|
22
|
+
|
|
23
|
+
const styles = ScaledSheet.create({
|
|
24
|
+
root: {
|
|
25
|
+
flexDirection: "row",
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return (
|
|
30
|
+
<View style={styles.root}>
|
|
31
|
+
{[...Array(Math.floor(rating))].map((_, index) => (
|
|
32
|
+
<Ionicons key={index} name="star" size={size} color="#FFD700" />
|
|
33
|
+
))}
|
|
34
|
+
{[...Array(5 - Math.floor(rating))].map((_, index) => (
|
|
35
|
+
<Ionicons
|
|
36
|
+
key={index}
|
|
37
|
+
name="star"
|
|
38
|
+
size={size}
|
|
39
|
+
color={colors.textSecondary.light}
|
|
40
|
+
/>
|
|
41
|
+
))}
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const RatingInput: FC<RatingInputProps> = ({
|
|
47
|
+
onSubmit: _onSubmit,
|
|
48
|
+
_id,
|
|
49
|
+
rating = 0,
|
|
50
|
+
size = 16,
|
|
51
|
+
}) => {
|
|
52
|
+
const { themeState } = useContext(GlobalContext);
|
|
53
|
+
const [showReviewsModal, setShowReviewsModal] = useState(false);
|
|
54
|
+
const [rate, setRate] = useState(0);
|
|
55
|
+
const [loading, setLoading] = useState(false);
|
|
56
|
+
const [review, setReview] = useState("");
|
|
57
|
+
const styles = ScaledSheet.create({
|
|
58
|
+
root: {
|
|
59
|
+
flexDirection: "row",
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
},
|
|
62
|
+
inputCon: {
|
|
63
|
+
marginBottom: "20@vs",
|
|
64
|
+
backgroundColor: colors(themeState.value).white[3],
|
|
65
|
+
padding: "15@ms",
|
|
66
|
+
borderRadius: 20,
|
|
67
|
+
},
|
|
68
|
+
input: {
|
|
69
|
+
fontSize: "16@ms",
|
|
70
|
+
color: colors(themeState.value).dark.main,
|
|
71
|
+
height: "100@vs",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
setRate(rating);
|
|
77
|
+
}, [rating]);
|
|
78
|
+
const onRate = (index) => {
|
|
79
|
+
setRate(index + 1);
|
|
80
|
+
Haptics.selectionAsync();
|
|
81
|
+
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
setShowReviewsModal(true);
|
|
84
|
+
}, 500);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const onSubmit = async () => {
|
|
88
|
+
setLoading(true);
|
|
89
|
+
try {
|
|
90
|
+
const res = (
|
|
91
|
+
await client.post("customer/review/product", {
|
|
92
|
+
rate,
|
|
93
|
+
review,
|
|
94
|
+
productId: _id,
|
|
95
|
+
})
|
|
96
|
+
).data;
|
|
97
|
+
|
|
98
|
+
console.log("R", res);
|
|
99
|
+
_onSubmit(res.data);
|
|
100
|
+
setShowReviewsModal(false);
|
|
101
|
+
Alert.alert("Review received", "Thank you for your review");
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.log("Couldn't add review", errorMessage(error));
|
|
104
|
+
Alert.alert("couldn't add review", errorMessage(error));
|
|
105
|
+
}
|
|
106
|
+
setLoading(false);
|
|
107
|
+
};
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<View style={styles.root}>
|
|
111
|
+
{[...Array(5)].map((_, index) => (
|
|
112
|
+
<TouchableOpacity
|
|
113
|
+
key={index}
|
|
114
|
+
activeOpacity={0.9}
|
|
115
|
+
onPress={() => {
|
|
116
|
+
onRate(index);
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<Ionicons
|
|
120
|
+
style={{ marginLeft: 10 }}
|
|
121
|
+
name={index < rate ? "star" : "star-outline"}
|
|
122
|
+
size={size}
|
|
123
|
+
color={colors(themeState.value).primary.light}
|
|
124
|
+
/>
|
|
125
|
+
</TouchableOpacity>
|
|
126
|
+
))}
|
|
127
|
+
</View>
|
|
128
|
+
<Popup
|
|
129
|
+
sheet
|
|
130
|
+
port
|
|
131
|
+
open={showReviewsModal}
|
|
132
|
+
onClose={() => {
|
|
133
|
+
setShowReviewsModal(false);
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<View
|
|
137
|
+
style={{
|
|
138
|
+
alignItems: "center",
|
|
139
|
+
marginBottom: 5,
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<StarRating rating={rate} size={24} />
|
|
143
|
+
</View>
|
|
144
|
+
<Typography
|
|
145
|
+
align="center"
|
|
146
|
+
fontWeight={700}
|
|
147
|
+
variant="h5"
|
|
148
|
+
gutterBottom={20}
|
|
149
|
+
>
|
|
150
|
+
Add to your review
|
|
151
|
+
</Typography>
|
|
152
|
+
|
|
153
|
+
<View style={styles.inputCon}>
|
|
154
|
+
<TextInput
|
|
155
|
+
style={styles.input}
|
|
156
|
+
multiline
|
|
157
|
+
value={review}
|
|
158
|
+
onChangeText={(text) => setReview(text)}
|
|
159
|
+
placeholder="Type review here.."
|
|
160
|
+
/>
|
|
161
|
+
</View>
|
|
162
|
+
<Button
|
|
163
|
+
gutterBottom={40}
|
|
164
|
+
title="Submit Review"
|
|
165
|
+
loading={loading}
|
|
166
|
+
disabled={loading}
|
|
167
|
+
onPress={() => {
|
|
168
|
+
onSubmit();
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
</Popup>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
@@ -276,6 +276,7 @@ export const TextField2: React.FC<TextFieldProps> = ({
|
|
|
276
276
|
style = {},
|
|
277
277
|
inputStyles = {},
|
|
278
278
|
gutterBottom = 8,
|
|
279
|
+
placeholder,
|
|
279
280
|
end,
|
|
280
281
|
options,
|
|
281
282
|
...props
|
|
@@ -343,6 +344,11 @@ export const TextField2: React.FC<TextFieldProps> = ({
|
|
|
343
344
|
color: colors.dark.light,
|
|
344
345
|
paddingLeft: moderateScale(10),
|
|
345
346
|
},
|
|
347
|
+
placeholder: {
|
|
348
|
+
fontSize: "14@ms",
|
|
349
|
+
color: colors.textSecondary.main,
|
|
350
|
+
paddingLeft: moderateScale(10),
|
|
351
|
+
},
|
|
346
352
|
label: {},
|
|
347
353
|
helperText: {
|
|
348
354
|
paddingHorizontal: "15@s",
|
|
@@ -408,9 +414,15 @@ export const TextField2: React.FC<TextFieldProps> = ({
|
|
|
408
414
|
|
|
409
415
|
{options ? (
|
|
410
416
|
<>
|
|
411
|
-
|
|
412
|
-
{
|
|
413
|
-
|
|
417
|
+
{value ? (
|
|
418
|
+
<Typography style={styles.inputText}>
|
|
419
|
+
{options.find((cur) => cur.value === value)?.label}
|
|
420
|
+
</Typography>
|
|
421
|
+
) : (
|
|
422
|
+
<Typography style={styles.placeholder}>
|
|
423
|
+
{placeholder}
|
|
424
|
+
</Typography>
|
|
425
|
+
)}
|
|
414
426
|
<Ionicons
|
|
415
427
|
name="chevron-down"
|
|
416
428
|
size={24}
|
|
@@ -433,6 +445,7 @@ export const TextField2: React.FC<TextFieldProps> = ({
|
|
|
433
445
|
keyboardType={keyboardType}
|
|
434
446
|
placeholderTextColor={colors.textSecondary.main}
|
|
435
447
|
editable={!disabled}
|
|
448
|
+
placeholder={placeholder}
|
|
436
449
|
selectTextOnFocus={!disabled}
|
|
437
450
|
onSubmitEditing={onSubmitEditing}
|
|
438
451
|
{...formProps}
|
package/src/types.ts
CHANGED
|
@@ -293,3 +293,13 @@ export interface OTPInputProps {
|
|
|
293
293
|
spacing?: number;
|
|
294
294
|
size?: number;
|
|
295
295
|
}
|
|
296
|
+
|
|
297
|
+
export interface RatingStarsProps {
|
|
298
|
+
rating: number;
|
|
299
|
+
size: number;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface RatingInputProps {
|
|
303
|
+
rating: number;
|
|
304
|
+
size: number;
|
|
305
|
+
}
|