@towsila/expo-ui-library 1.10.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towsila/expo-ui-library",
3
- "version": "1.10.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -20,6 +20,7 @@ interface ReportProps {
20
20
  error?: string;
21
21
  textLabel?: string;
22
22
  selectLabel?:string;
23
+ t?: (key: string) => string;
23
24
  }
24
25
 
25
26
  export default function AddReport({
@@ -33,6 +34,7 @@ export default function AddReport({
33
34
  error,
34
35
  textLabel,
35
36
  selectLabel,
37
+ t,
36
38
  }: ReportProps) {
37
39
  const form = useSubmitReport({ onSubmit });
38
40
  const { colors } = useAppTheme();
@@ -90,7 +92,7 @@ export default function AddReport({
90
92
  );
91
93
  })}
92
94
  </View>
93
- {form.errors.target && <ErrorMessage message={form.errors.target} />}
95
+ {form.errors.target && <ErrorMessage message={t?.(form.errors.target) || form.errors.target} />}
94
96
  </View>
95
97
 
96
98
  {/* Details textarea */}
@@ -109,7 +111,7 @@ export default function AddReport({
109
111
  numberOfLines={4}
110
112
  textAlignVertical="top"
111
113
  height={100}
112
- error={form.errors.reason}
114
+ error={form.errors.reason ? t?.(form.errors.reason) : ""}
113
115
  onClearError={() => form.clearError("reason")}
114
116
  bgColor={colors.background.main}
115
117
  />
@@ -15,6 +15,7 @@ interface ForgetPwScreenProps {
15
15
  inputLabel?:string;
16
16
  inputPlaceholder: string;
17
17
  onBack: ()=>void;
18
+ t?: (key:string) => string;
18
19
  }
19
20
 
20
21
  export default function ForgotPwScreen({
@@ -26,6 +27,7 @@ export default function ForgotPwScreen({
26
27
  inputLabel,
27
28
  inputPlaceholder,
28
29
  onBack,
30
+ t,
29
31
  }: ForgetPwScreenProps) {
30
32
 
31
33
  const form = useForgotPasswordForm({onSubmit});
@@ -47,7 +49,7 @@ export default function ForgotPwScreen({
47
49
  label={inputLabel}
48
50
  keyboardType="email-address"
49
51
  iconLeft={(color) => <Email width={18} height={18} color={color}/>}
50
- error={form.errors.input}
52
+ error={form.errors.input ? t?.(form.errors.input) : ""}
51
53
  autoCapitalize="none"
52
54
  autoComplete="email"
53
55
  textContentType="emailAddress"
@@ -30,6 +30,7 @@ interface LoginScreenProps {
30
30
  noAccountLabel?: string;
31
31
  signUpLabel?: string;
32
32
  googleLabel?: string;
33
+ t?: (key: string) => string;
33
34
  }
34
35
 
35
36
  export default function LoginScreen({
@@ -50,6 +51,7 @@ export default function LoginScreen({
50
51
  noAccountLabel = "Don't have an account?",
51
52
  signUpLabel = "Create one",
52
53
  googleLabel,
54
+ t,
53
55
  }: LoginScreenProps) {
54
56
  const { colors, isDark } = useAppTheme();
55
57
  const form = useLoginForm({ onLogin });
@@ -67,7 +69,7 @@ export default function LoginScreen({
67
69
  onChangeText={(text)=>form.setValue("email", text)}
68
70
  placeholder={emailPlaceholder}
69
71
  keyboardType="email-address"
70
- error={form.errors.email}
72
+ error={form.errors.email ? t?.(form.errors.email) : ""}
71
73
  autoCapitalize="none"
72
74
  autoComplete="email"
73
75
  textContentType="emailAddress"
@@ -88,7 +90,7 @@ export default function LoginScreen({
88
90
  secureTextEntry={!form.showPassword}
89
91
  textContentType="password"
90
92
  returnKeyType="done"
91
- error={form.errors.password}
93
+ error={form.errors.password ? t?.(form.errors.password) : ""}
92
94
  onClearError={() => form.clearError("password")}
93
95
  iconLeft={(color)=><LockClosed width={18} height={18} color={color}/>}
94
96
  />
@@ -21,6 +21,7 @@ interface ResetPasswordScreenProps {
21
21
  includeOldPassword?: boolean;
22
22
  onReset: (password: string, oldPassword?: string) => Promise<void>;
23
23
  errorMessage?: string;
24
+ t?: (key: string) => string;
24
25
  }
25
26
 
26
27
  export default function ResetPasswordScreen({
@@ -39,6 +40,7 @@ export default function ResetPasswordScreen({
39
40
  includeOldPassword = false,
40
41
  onReset,
41
42
  errorMessage,
43
+ t,
42
44
  }: ResetPasswordScreenProps) {
43
45
  const form = useResetPasswordForm({ onReset , includeOldPassword});
44
46
 
@@ -67,7 +69,7 @@ export default function ResetPasswordScreen({
67
69
  secureTextEntry={!form.showOldPassword}
68
70
  textContentType="password"
69
71
  returnKeyType="next"
70
- error={form.errors.oldPassword}
72
+ error={form.errors.oldPassword ? t?.(form.errors.oldPassword) : ""}
71
73
  onClearError={() => form.clearError("oldPassword")}
72
74
  />
73
75
  )}
@@ -82,7 +84,7 @@ export default function ResetPasswordScreen({
82
84
  secureTextEntry={!form.showPassword}
83
85
  textContentType="password"
84
86
  returnKeyType="next"
85
- error={form.errors.password}
87
+ error={form.errors.password ? t?.(form.errors.password) : ""}
86
88
  onClearError={() => form.clearError("password")}
87
89
  />
88
90
  {cardItems && (
@@ -104,7 +106,7 @@ export default function ResetPasswordScreen({
104
106
  secureTextEntry={!form.showConfirmPassword}
105
107
  textContentType="password"
106
108
  returnKeyType="done"
107
- error={form.errors.confirmPassword}
109
+ error={form.errors.confirmPassword ? t?.(form.errors.confirmPassword) : ""}
108
110
  onClearError={() => form.clearError("confirmPassword")}
109
111
  />
110
112
  </TemplateSubPage>
@@ -28,6 +28,7 @@ generalTerms: string[];
28
28
  dialogTitle:string;
29
29
  dialogDescription: string;
30
30
  dialogButton: string;
31
+ t?: (key: string) => string;
31
32
  }
32
33
  export default function SignupPage({
33
34
  title,
@@ -46,7 +47,8 @@ export default function SignupPage({
46
47
  generalTerms,
47
48
  dialogTitle,
48
49
  dialogDescription,
49
- dialogButton
50
+ dialogButton,
51
+ t,
50
52
  }: SignupProps) {
51
53
  const [showTerms, setShowTerms] = useState(true);
52
54
  const {colors} = useAppTheme();
@@ -74,6 +76,7 @@ export default function SignupPage({
74
76
  nextLabel={nextLabel}
75
77
  backLabel={backLabel}
76
78
  setErrors={setErrors}
79
+ translator={t}
77
80
  />
78
81
  {isLastStep && (
79
82
  <SharpButton
@@ -16,6 +16,7 @@ interface Props {
16
16
  onStepChange?: (step: number, total: number) => void;
17
17
  nextLabel?: string;
18
18
  backLabel?: string;
19
+ translator?: (key: string) => string;
19
20
  }
20
21
 
21
22
  function splitIntoSteps(fields: Field[]): Field[][] {
@@ -49,6 +50,7 @@ export const SharpDynamicForm: React.FC<Props> = ({
49
50
  onStepChange,
50
51
  nextLabel,
51
52
  backLabel,
53
+ translator,
52
54
  }) => {
53
55
  const [showPasswordField, setShowPasswordField] = useState<Record<string, boolean>>({});
54
56
  const [currentStep, setCurrentStep] = useState(0);
@@ -96,7 +98,7 @@ export const SharpDynamicForm: React.FC<Props> = ({
96
98
  }
97
99
  secureTextEntry={field.secureTextEntry && !showPasswordField[field.name]}
98
100
  returnKeyType="next"
99
- error={errors[field.name]}
101
+ error={errors[field.name] ? translator?.(errors[field.name]) : ""}
100
102
  onClearError={() => clearError(field.name)}
101
103
  label={field.label}
102
104
  />
@@ -2,30 +2,29 @@ import { registerValidator } from "../../utils/inputValidator/registerValidator"
2
2
 
3
3
  registerValidator("text", (value, field) => {
4
4
  if (field.required !== false && !value.trim())
5
- return `${field.label ?? field.name} is required`;
5
+ return "errors.required";
6
6
  return "";
7
7
  });
8
8
 
9
9
  registerValidator("email", (value) => {
10
- if (!value.trim()) return "Email is required";
10
+ if (!value.trim()) return "errors.required";
11
11
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
12
- if (!emailRegex.test(value.trim())) return "Invalid email address";
12
+ if (!emailRegex.test(value.trim())) return "errors.email";
13
13
  return "";
14
14
  });
15
15
 
16
16
  registerValidator("password", (value, field, formState) => {
17
- if (!value) return "Please enter a password";
18
- if (value.length < 8) return "Password must be at least 8 characters";
19
- if (field.name === "confirmPassword" && value !== formState["password"]) {
20
- console.log("PASSWORD MISMATCH:", value, "!==", formState["password"]); // ✓ Add this
21
- return "Passwords do not match";
17
+ if (!value) return "errors.required";
18
+ if (value.length < 8) return "errors.passwordShort";
19
+ if (field.name === "confirmPassword" && value !== formState["password"]) {
20
+ return "errors.passwordMismatch";
22
21
  }
23
22
  return "";
24
23
  });
25
24
 
26
25
  registerValidator("phone", (value, field) => {
27
- if (!value.trim()) return `${field.label ?? "Phone"} is required`;
26
+ if (!value.trim()) return "errors.required";
28
27
  const phoneRegex = /^0[567]\d{8}$/;
29
- if (!phoneRegex.test(value.trim())) return "Invalid phone number";
28
+ if (!phoneRegex.test(value.trim())) return "errors.phoneInvalid";
30
29
  return "";
31
30
  });