@hoddy-ui/core 1.0.44 → 1.0.46

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoddy-ui/core",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
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": {
@@ -22,7 +22,7 @@ export const Popup: React.FC<PopupProps> = ({
22
22
  container: {
23
23
  marginTop: sheet ? "auto" : "50%",
24
24
  paddingBottom: sheet ? "30@ms" : 0,
25
- minHeight: sheet,
25
+ minHeight: typeof sheet === "number" ? sheet : undefined,
26
26
  maxHeight: "80%",
27
27
  backgroundColor: colors.white[2],
28
28
  borderTopLeftRadius: 20,
@@ -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
+ };
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
+ }