@hitesh0009/react-native-basic-form 1.3.4 → 1.3.6

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/dist/Form.js CHANGED
@@ -2,23 +2,39 @@ import { View } from "react-native";
2
2
  import React from "react";
3
3
  import InputText from "./components/InputText";
4
4
  import Buttons from "./components/Buttons";
5
+ import FormText from "./components/Text";
5
6
  export const Form = ({ schema = [] }) => {
6
- const RenderField = (field, index) => {
7
+ const renderField = (field, index) => {
8
+ var _a, _b;
7
9
  switch (field.type) {
10
+ case "text":
11
+ return (<FormText key={index} label={field.label} style={field.labelStyle}/>);
8
12
  case "button":
9
- return (<Buttons key={index} label={field.label} style={field.style} textStyle={field.textStyle} spacing={field.spacing} labelStyle={field.labelStyle} {...(field.buttonProps || {})}/>);
13
+ return (<View key={index} style={{ gap: (_a = field.spacing) !== null && _a !== void 0 ? _a : 13 }}>
14
+ {field.label && (<FormText label={field.label} style={field.labelStyle}/>)}
15
+ <Buttons style={field.style} textStyle={field.textStyle} {...(field.buttonProps || {})}/>
16
+ </View>);
10
17
  case "input":
11
- return (<InputText key={index} label={field.label} style={field.style} spacing={field.spacing} labelStyle={field.labelStyle} {...(field.inputProps || {})}/>);
18
+ return (<View key={index} style={{ gap: (_b = field.spacing) !== null && _b !== void 0 ? _b : 13 }}>
19
+ {field.label && (<FormText label={field.label} style={field.labelStyle}/>)}
20
+ <InputText style={field.style} {...(field.inputProps || {})}/>
21
+ </View>);
12
22
  default:
13
23
  return null;
14
24
  }
15
25
  };
16
26
  return (<>
17
- {schema.map((block, blockIndex) => (<View key={blockIndex} style={[{
18
- flexDirection: block.layout || "column",
19
- gap: block.spacing || 20,
20
- }, block.style]}>
21
- {block.children.map(RenderField)}
22
- </View>))}
27
+ {schema.map((block, blockIndex) => {
28
+ var _a, _b;
29
+ return (<View key={blockIndex} style={[
30
+ {
31
+ flexDirection: (_a = block.layout) !== null && _a !== void 0 ? _a : "column",
32
+ gap: (_b = block.spacing) !== null && _b !== void 0 ? _b : 20,
33
+ },
34
+ block.style,
35
+ ]}>
36
+ {block.children.map(renderField)}
37
+ </View>);
38
+ })}
23
39
  </>);
24
40
  };
@@ -1,10 +1,7 @@
1
1
  import { Text, TouchableOpacity, View } from "react-native";
2
2
  import React from "react";
3
- import FormText from "./Text";
4
3
  const Buttons = ({ label, buttonText, onPress, style, textStyle, spacing, labelStyle, ...touchableProps }) => {
5
- return (<View style={{ gap: spacing !== null && spacing !== void 0 ? spacing : 13 }}>
6
- <FormText label={label || " "} style={labelStyle}/>
7
-
4
+ return (<View style={{}}>
8
5
  <TouchableOpacity {...touchableProps} onPress={onPress} style={[
9
6
  {
10
7
  backgroundColor: "#2563eb",
@@ -1,9 +1,7 @@
1
1
  import { StyleSheet, TextInput, View } from 'react-native';
2
2
  import React from 'react';
3
- import FormText from './Text';
4
- const InputText = ({ label, style, spacing = 13, labelStyle, ...textInputProps }) => {
5
- return (<View style={{ gap: spacing || 13 }}>
6
- <FormText label={label || ' '} style={labelStyle}/>
3
+ const InputText = ({ label, style, labelStyle, ...textInputProps }) => {
4
+ return (<View>
7
5
  <TextInput {...textInputProps} // 👈 forward EVERYTHING
8
6
  style={style}/>
9
7
  </View>);
@@ -1,4 +1,4 @@
1
- import React from 'react';
2
- import { TextProps } from '../types';
3
- declare const FormText: React.FC<TextProps>;
1
+ import React from "react";
2
+ import { FormTextProps } from "../types";
3
+ declare const FormText: React.FC<FormTextProps>;
4
4
  export default FormText;
@@ -1,14 +1,14 @@
1
- import { StyleSheet, Text, View } from 'react-native';
2
- import React from 'react';
3
- const FormText = ({ label, style }) => {
1
+ import { StyleSheet, Text, View } from "react-native";
2
+ import React from "react";
3
+ const FormText = ({ label, style, ...textProps }) => {
4
4
  return (<View>
5
- <Text style={[
5
+ <Text {...textProps} style={[
6
6
  {
7
- color: '#000',
7
+ color: "#000",
8
8
  },
9
9
  style,
10
10
  ]}>
11
- {label || ' '}
11
+ {label || " "}
12
12
  </Text>
13
13
  </View>);
14
14
  };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ImageProps, ImageStyle, TextInputProps, TextStyle, TouchableOpacityProps, ViewStyle } from 'react-native';
1
+ import type { ImageProps, ImageStyle, TextInputProps, TextProps, TextStyle, TouchableOpacityProps, ViewStyle } from "react-native";
2
2
  type BaseField = {
3
3
  label?: string;
4
4
  spacing?: number;
@@ -6,23 +6,27 @@ type BaseField = {
6
6
  labelStyle?: TextStyle;
7
7
  };
8
8
  export type FormInput = BaseField & {
9
- type: 'input';
9
+ type: "input";
10
10
  inputProps?: TextInputProps;
11
11
  };
12
+ export type FormText = BaseField & {
13
+ type: "text";
14
+ textProps?: TextProps;
15
+ };
12
16
  export type FormButton = BaseField & {
13
- type: 'button';
17
+ type: "button";
14
18
  textStyle?: TextStyle;
15
19
  buttonProps?: {
16
20
  buttonText?: string;
17
- onPress?: TouchableOpacityProps['onPress'];
21
+ onPress?: TouchableOpacityProps["onPress"];
18
22
  };
19
23
  };
20
- export type FormField = FormInput | FormButton;
24
+ export type FormField = FormInput | FormButton | FormText;
21
25
  export type FormItem = {
22
- layout?: ViewStyle['flexDirection'];
26
+ layout?: ViewStyle["flexDirection"];
23
27
  spacing?: number;
28
+ style?: ViewStyle;
24
29
  children: FormField[];
25
- style: ViewStyle;
26
30
  };
27
31
  export type FormProps = {
28
32
  schema: FormItem[];
@@ -37,19 +41,19 @@ export type ButtonProps = {
37
41
  } & TouchableOpacityProps;
38
42
  export type InputProps = {
39
43
  label?: string;
40
- style?: TextInputProps['style'];
44
+ style?: TextInputProps["style"];
41
45
  spacing?: number;
42
46
  labelStyle?: TextStyle;
43
- placeholder?: TextInputProps['placeholder'];
44
- value?: TextInputProps['value'];
45
- onChangeText?: TextInputProps['onChangeText'];
47
+ placeholder?: TextInputProps["placeholder"];
48
+ value?: TextInputProps["value"];
49
+ onChangeText?: TextInputProps["onChangeText"];
46
50
  } & TextInputProps;
47
51
  export type IconProps = {
48
- icon?: ImageProps['source'];
52
+ icon?: ImageProps["source"];
49
53
  style?: ImageStyle;
50
54
  };
51
- export type TextProps = {
55
+ export type FormTextProps = {
52
56
  label?: string;
53
57
  style?: TextStyle;
54
- };
58
+ } & TextProps;
55
59
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitesh0009/react-native-basic-form",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "A lightweight, data-driven form renderer for React Native with fully controlled inputs and flexible styling.",
5
5
  "keywords": [
6
6
  "react-native",
package/src/Form.tsx CHANGED
@@ -3,33 +3,45 @@ import React from "react";
3
3
  import InputText from "./components/InputText";
4
4
  import Buttons from "./components/Buttons";
5
5
  import { FormField, FormProps } from "./types";
6
+ import FormText from "./components/Text";
6
7
 
7
8
  export const Form: React.FC<FormProps> = ({ schema = [] }) => {
8
- const RenderField = (field: FormField, index: number) => {
9
+ const renderField = (field: FormField, index: number) => {
9
10
  switch (field.type) {
10
- case "button":
11
+ case "text":
11
12
  return (
12
- <Buttons
13
+ <FormText
13
14
  key={index}
14
15
  label={field.label}
15
- style={field.style}
16
- textStyle={field.textStyle}
17
- spacing={field.spacing}
18
- labelStyle={field.labelStyle}
19
- {...(field.buttonProps || {})}
16
+ style={field.labelStyle}
20
17
  />
21
18
  );
22
19
 
20
+ case "button":
21
+ return (
22
+ <View key={index} style={{ gap: field.spacing ?? 13 }}>
23
+ {field.label && (
24
+ <FormText label={field.label} style={field.labelStyle} />
25
+ )}
26
+ <Buttons
27
+ style={field.style}
28
+ textStyle={field.textStyle}
29
+ {...(field.buttonProps || {})}
30
+ />
31
+ </View>
32
+ );
33
+
23
34
  case "input":
24
35
  return (
25
- <InputText
26
- key={index}
27
- label={field.label}
28
- style={field.style}
29
- spacing={field.spacing}
30
- labelStyle={field.labelStyle}
31
- {...(field.inputProps || {})}
32
- />
36
+ <View key={index} style={{ gap: field.spacing ?? 13 }}>
37
+ {field.label && (
38
+ <FormText label={field.label} style={field.labelStyle} />
39
+ )}
40
+ <InputText
41
+ style={field.style}
42
+ {...(field.inputProps || {})}
43
+ />
44
+ </View>
33
45
  );
34
46
 
35
47
  default:
@@ -42,12 +54,15 @@ export const Form: React.FC<FormProps> = ({ schema = [] }) => {
42
54
  {schema.map((block, blockIndex) => (
43
55
  <View
44
56
  key={blockIndex}
45
- style={[{
46
- flexDirection: block.layout || "column",
47
- gap: block.spacing || 20,
48
- },block.style]}
57
+ style={[
58
+ {
59
+ flexDirection: block.layout ?? "column",
60
+ gap: block.spacing ?? 20,
61
+ },
62
+ block.style,
63
+ ]}
49
64
  >
50
- {block.children.map(RenderField)}
65
+ {block.children.map(renderField)}
51
66
  </View>
52
67
  ))}
53
68
  </>
@@ -14,9 +14,7 @@ const Buttons: React.FC<ButtonProps> = ({
14
14
  ...touchableProps
15
15
  }) => {
16
16
  return (
17
- <View style={{ gap: spacing ?? 13 }}>
18
- <FormText label={label || " "} style={labelStyle} />
19
-
17
+ <View style={{ }}>
20
18
  <TouchableOpacity
21
19
  {...touchableProps}
22
20
  onPress={onPress}
@@ -6,13 +6,11 @@ import { InputProps } from '../types';
6
6
  const InputText:React.FC<InputProps> = ({
7
7
  label,
8
8
  style,
9
- spacing = 13,
10
9
  labelStyle,
11
10
  ...textInputProps
12
11
  }) => {
13
12
  return (
14
- <View style={{ gap: spacing || 13 }}>
15
- <FormText label={label || ' '} style={labelStyle} />
13
+ <View>
16
14
  <TextInput
17
15
  {...textInputProps} // 👈 forward EVERYTHING
18
16
  style={style}
@@ -1,19 +1,20 @@
1
- import { StyleSheet, Text, View } from 'react-native';
2
- import React from 'react';
3
- import { TextProps } from '../types';
1
+ import { StyleSheet, Text, View } from "react-native";
2
+ import React from "react";
3
+ import { FormTextProps } from "../types";
4
4
 
5
- const FormText:React.FC<TextProps> = ({ label, style }) => {
5
+ const FormText: React.FC<FormTextProps> = ({ label, style, ...textProps }) => {
6
6
  return (
7
7
  <View>
8
8
  <Text
9
+ {...textProps}
9
10
  style={[
10
11
  {
11
- color: '#000',
12
+ color: "#000",
12
13
  },
13
14
  style,
14
15
  ]}
15
16
  >
16
- {label || ' '}
17
+ {label || " "}
17
18
  </Text>
18
19
  </View>
19
20
  );
package/src/types.ts CHANGED
@@ -2,10 +2,11 @@ import type {
2
2
  ImageProps,
3
3
  ImageStyle,
4
4
  TextInputProps,
5
+ TextProps,
5
6
  TextStyle,
6
7
  TouchableOpacityProps,
7
8
  ViewStyle,
8
- } from 'react-native';
9
+ } from "react-native";
9
10
 
10
11
  type BaseField = {
11
12
  label?: string;
@@ -15,33 +16,36 @@ type BaseField = {
15
16
  };
16
17
 
17
18
  export type FormInput = BaseField & {
18
- type: 'input';
19
+ type: "input";
19
20
  inputProps?: TextInputProps;
20
21
  };
22
+ export type FormText = BaseField & {
23
+ type: "text";
24
+ textProps?: TextProps;
25
+ };
21
26
 
22
27
  export type FormButton = BaseField & {
23
- type: 'button';
28
+ type: "button";
24
29
  textStyle?: TextStyle;
25
30
  buttonProps?: {
26
31
  buttonText?: string;
27
- onPress?: TouchableOpacityProps['onPress'];
32
+ onPress?: TouchableOpacityProps["onPress"];
28
33
  };
29
34
  };
30
35
 
31
- export type FormField = FormInput | FormButton;
36
+ export type FormField = FormInput | FormButton | FormText;
32
37
 
33
38
  export type FormItem = {
34
- layout?: ViewStyle['flexDirection'];
39
+ layout?: ViewStyle["flexDirection"];
35
40
  spacing?: number;
41
+ style?: ViewStyle;
36
42
  children: FormField[];
37
- style:ViewStyle
38
43
  };
39
44
 
40
45
  export type FormProps = {
41
46
  schema: FormItem[];
42
47
  };
43
48
 
44
-
45
49
  // Buttons.types.ts
46
50
  export type ButtonProps = {
47
51
  label?: string;
@@ -55,22 +59,22 @@ export type ButtonProps = {
55
59
  // Input.types.ts
56
60
  export type InputProps = {
57
61
  label?: string;
58
- style?: TextInputProps['style'];
62
+ style?: TextInputProps["style"];
59
63
  spacing?: number;
60
64
  labelStyle?: TextStyle;
61
- placeholder?:TextInputProps['placeholder'],
62
- value?:TextInputProps['value'],
63
- onChangeText?:TextInputProps['onChangeText'],
64
- }& TextInputProps;
65
+ placeholder?: TextInputProps["placeholder"];
66
+ value?: TextInputProps["value"];
67
+ onChangeText?: TextInputProps["onChangeText"];
68
+ } & TextInputProps;
65
69
 
66
70
  // Icon.types.ts
67
71
  export type IconProps = {
68
- icon?: ImageProps['source'];
72
+ icon?: ImageProps["source"];
69
73
  style?: ImageStyle;
70
74
  };
71
75
 
72
76
  // Text.types.ts
73
- export type TextProps = {
77
+ export type FormTextProps = {
74
78
  label?: string;
75
79
  style?: TextStyle;
76
- };
80
+ } & TextProps;