@hoddy-ui/core 1.0.35 → 1.0.37

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/index.ts CHANGED
@@ -19,6 +19,7 @@ export { default as Spinner } from "./src/Components/Spinner";
19
19
  export * from "./src/Components/TextField";
20
20
  export { default as TextField } from "./src/Components/TextField";
21
21
  export { default as Typography } from "./src/Components/Typography";
22
+ export * from "./src/Components/OTPInput";
22
23
  // Others
23
24
  // export * from "./src/config";
24
25
  export * from "./src/hooks";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoddy-ui/core",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "Core rich react native components written in typescript",
5
5
  "main": "index.ts",
6
6
  "repository": {
@@ -1,47 +1,82 @@
1
- import React, { useState } from "react";
2
- import { View, TextInput, StyleSheet, Button } from "react-native";
1
+ import React, { FC, useMemo, useState } from "react";
2
+ import { TextInput, View } from "react-native";
3
+ import { ScaledSheet, ms } from "react-native-size-matters";
4
+ import { useColors } from "../hooks";
5
+ import { OTPInputProps } from "../types";
3
6
 
4
- export const OTPInput = () => {
5
- const [numFields, setNumFields] = useState(1);
6
- const [inputTexts, setInputTexts] = useState(Array(numFields).fill(""));
7
-
8
- const handleInputChange = (text, index) => {
9
- const updatedInputTexts = [...inputTexts];
10
- updatedInputTexts[index] = text;
11
- setInputTexts(updatedInputTexts);
12
- };
7
+ export const OTPInput: FC<OTPInputProps> = ({
8
+ length = 6,
9
+ onChange = () => {},
10
+ value = "",
11
+ variant = "outlined",
12
+ spacing = 1,
13
+ size = 45,
14
+ }) => {
15
+ const inputRefs = useMemo(
16
+ () =>
17
+ Array(length)
18
+ .fill(0)
19
+ .map((_) => React.createRef<TextInput>()),
20
+ [length]
21
+ );
13
22
 
14
- const addField = () => {
15
- setNumFields(numFields + 1);
16
- setInputTexts([...inputTexts, ""]);
17
- };
23
+ const colors = useColors();
24
+ const styles = ScaledSheet.create({
25
+ root: {},
26
+ container: { flexDirection: "row" },
27
+ input: {
28
+ height: ms(size),
29
+ width: ms(size),
30
+ borderColor: colors.white[5],
31
+ backgroundColor: variant === "contained" ? colors.white[3] : undefined,
32
+ borderWidth: variant === "outlined" ? 1 : 0,
33
+ borderBottomWidth: variant === "contained" ? 0 : 1,
34
+ marginHorizontal: ms(spacing * 5),
35
+ textAlign: "center",
36
+ borderRadius: variant === "text" ? 0 : 10,
37
+ color: colors.dark.main,
38
+ fontSize: ms(size * 0.5),
39
+ },
40
+ });
18
41
 
19
42
  return (
20
- <View style={styles.container}>
21
- {inputTexts.map((inputText, index) => (
22
- <TextInput
23
- key={index}
24
- style={styles.input}
25
- placeholder={`Enter text ${index + 1}`}
26
- value={inputText}
27
- onChangeText={(text) => handleInputChange(text, index)}
28
- />
29
- ))}
30
- <Button title="Add Field" onPress={addField} />
43
+ <View style={styles.root}>
44
+ <View style={styles.container}>
45
+ {[...Array(length)].map((_, index) => (
46
+ <TextInput
47
+ ref={inputRefs[index]}
48
+ onChangeText={(val) => {
49
+ if (val.length === 1) {
50
+ if (index !== length - 1) inputRefs[index + 1].current?.focus();
51
+ let text = value;
52
+
53
+ text = text.slice(0, index) + val + text.slice(index + 1);
54
+ onChange(text);
55
+ } else if (val.length === 0) {
56
+ if (index !== 0) {
57
+ inputRefs[index - 1].current?.focus();
58
+ let text = value;
59
+
60
+ text = text.slice(0, index);
61
+ onChange(text);
62
+ } else onChange("");
63
+ } else {
64
+ let text = val.replace(/\D/g, "").slice(0, length);
65
+ onChange(text);
66
+ inputRefs[
67
+ text.length < length - 1 ? text.length : length - 1
68
+ ]?.current?.focus();
69
+ }
70
+ }}
71
+ value={value[index] || ""}
72
+ // maxLength={1}
73
+ blurOnSubmit={false}
74
+ keyboardType="number-pad"
75
+ key={index}
76
+ style={[styles.input]}
77
+ />
78
+ ))}
79
+ </View>
31
80
  </View>
32
81
  );
33
82
  };
34
-
35
- const styles = StyleSheet.create({
36
- container: {
37
- marginTop: 20,
38
- paddingHorizontal: 16,
39
- },
40
- input: {
41
- height: 40,
42
- borderColor: "gray",
43
- borderWidth: 1,
44
- paddingHorizontal: 10,
45
- marginBottom: 10,
46
- },
47
- });
@@ -395,7 +395,7 @@ export const TextField2: React.FC<TextFieldProps> = ({
395
395
  <>
396
396
  <View style={styles.root}>
397
397
  {label && (
398
- <Typography variant="body1" gutterBottom={7}>
398
+ <Typography variant="body1" color="textSecondary" gutterBottom={7}>
399
399
  {label}
400
400
  </Typography>
401
401
  )}
@@ -22,7 +22,6 @@ function themeReducer(
22
22
  state: ThemeState,
23
23
  { type, payload }: ThemeActionTypes
24
24
  ): ThemeState {
25
- console.log(type, payload);
26
25
  // Platform
27
26
  if (payload === "dark" || type === "dark") {
28
27
  SystemUI.setBackgroundColorAsync("#000000");
package/src/types.ts CHANGED
@@ -283,3 +283,12 @@ export interface SelectMenuProps {
283
283
  secondary?: string;
284
284
  helperText?: string;
285
285
  }
286
+
287
+ export interface OTPInputProps {
288
+ length?: number;
289
+ onChange: (value: string) => void;
290
+ value: string;
291
+ variant?: "outlined" | "text" | "contained";
292
+ spacing?: number;
293
+ size?: number;
294
+ }