@hitesh0009/react-native-basic-form 1.3.1 → 1.3.3
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/README.md +0 -2
- package/basic_usage/example.js +48 -17
- package/dist/Form.js +2 -2
- package/dist/components/Buttons.js +2 -2
- package/dist/components/InputText.js +3 -10
- package/dist/types.d.ts +2 -3
- package/package.json +1 -1
- package/src/Form.tsx +4 -2
- package/src/components/Buttons.tsx +2 -0
- package/src/components/InputText.tsx +5 -17
- package/src/types.ts +5 -6
package/README.md
CHANGED
package/basic_usage/example.js
CHANGED
|
@@ -3,27 +3,58 @@ import { View } from "react-native";
|
|
|
3
3
|
import { Form } from "react-native-basic-form";
|
|
4
4
|
|
|
5
5
|
export default function App() {
|
|
6
|
+
// 👉 Form state is owned by YOU, not by the Form component
|
|
7
|
+
// The library is stateless by design
|
|
6
8
|
const [name, setName] = useState("");
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
// 👉 Schema controls the entire form UI
|
|
11
|
+
// Changing this JSON changes the form
|
|
12
|
+
const formSchema = [
|
|
13
|
+
{
|
|
14
|
+
// Layout block: controls how children are arranged
|
|
15
|
+
layout: "column",
|
|
16
|
+
spacing: 16, // space between fields
|
|
17
|
+
|
|
18
|
+
// Children = actual form fields
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
// Input field
|
|
22
|
+
type: "input",
|
|
23
|
+
label: "Name",
|
|
24
|
+
|
|
25
|
+
// All TextInput behavior goes inside inputProps
|
|
26
|
+
inputProps: {
|
|
27
|
+
placeholder: "Enter your name",
|
|
28
|
+
value: name, // controlled value
|
|
29
|
+
onChangeText: setName // update state
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
// Button field
|
|
35
|
+
type: "button",
|
|
36
|
+
label: "Submit",
|
|
37
|
+
|
|
38
|
+
// Button behavior goes inside buttonProps
|
|
39
|
+
buttonProps: {
|
|
40
|
+
buttonText: "Submit",
|
|
41
|
+
onPress: () => {
|
|
42
|
+
// Access state directly
|
|
43
|
+
console.log("Name:", name);
|
|
23
44
|
},
|
|
24
45
|
},
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View style={{ padding: 16 }}>
|
|
53
|
+
{/*
|
|
54
|
+
👉 Form only renders what the schema describes
|
|
55
|
+
👉 No internal state, no validation, no logic
|
|
56
|
+
*/}
|
|
57
|
+
<Form schema={formSchema} />
|
|
27
58
|
</View>
|
|
28
59
|
);
|
|
29
60
|
}
|
package/dist/Form.js
CHANGED
|
@@ -6,9 +6,9 @@ export const Form = ({ schema = [] }) => {
|
|
|
6
6
|
const RenderField = (field, index) => {
|
|
7
7
|
switch (field.type) {
|
|
8
8
|
case "button":
|
|
9
|
-
return (<Buttons key={index} label={field.label} style={field.style} textStyle={field.textStyle} spacing={field.spacing} {...(field.buttonProps || {})}/>);
|
|
9
|
+
return (<Buttons key={index} label={field.label} style={field.style} textStyle={field.textStyle} spacing={field.spacing} labelStyle={field.labelStyle} {...(field.buttonProps || {})}/>);
|
|
10
10
|
case "input":
|
|
11
|
-
return (<InputText key={index} label={field.label} style={field.style} spacing={field.spacing} {...(field.inputProps || {})}/>);
|
|
11
|
+
return (<InputText key={index} label={field.label} style={field.style} spacing={field.spacing} labelStyle={field.labelStyle} {...(field.inputProps || {})}/>);
|
|
12
12
|
default:
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Text, TouchableOpacity, View } from "react-native";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import FormText from "./Text";
|
|
4
|
-
const Buttons = ({ label, buttonText, onPress, style, textStyle, spacing, labelStyle, }) => {
|
|
4
|
+
const Buttons = ({ label, buttonText, onPress, style, textStyle, spacing, labelStyle, ...touchableProps }) => {
|
|
5
5
|
return (<View style={{ gap: spacing !== null && spacing !== void 0 ? spacing : 13 }}>
|
|
6
6
|
<FormText label={label || " "} style={labelStyle}/>
|
|
7
7
|
|
|
8
|
-
<TouchableOpacity onPress={onPress} style={[
|
|
8
|
+
<TouchableOpacity {...touchableProps} onPress={onPress} style={[
|
|
9
9
|
{
|
|
10
10
|
backgroundColor: "#2563eb",
|
|
11
11
|
padding: 14,
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { StyleSheet, TextInput, View } from 'react-native';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import FormText from './Text';
|
|
4
|
-
const InputText = ({ label,
|
|
4
|
+
const InputText = ({ label, style, spacing = 13, labelStyle, ...textInputProps }) => {
|
|
5
5
|
return (<View style={{ gap: spacing || 13 }}>
|
|
6
6
|
<FormText label={label || ' '} style={labelStyle}/>
|
|
7
|
-
<TextInput
|
|
8
|
-
|
|
9
|
-
borderWidth: 1,
|
|
10
|
-
borderColor: '#ccc',
|
|
11
|
-
padding: 10,
|
|
12
|
-
borderRadius: 6,
|
|
13
|
-
},
|
|
14
|
-
style,
|
|
15
|
-
]}/>
|
|
7
|
+
<TextInput {...textInputProps} // 👈 forward EVERYTHING
|
|
8
|
+
style={style}/>
|
|
16
9
|
</View>);
|
|
17
10
|
};
|
|
18
11
|
export default InputText;
|
package/dist/types.d.ts
CHANGED
|
@@ -29,12 +29,11 @@ export type FormProps = {
|
|
|
29
29
|
export type ButtonProps = {
|
|
30
30
|
label?: string;
|
|
31
31
|
buttonText?: string;
|
|
32
|
-
onPress?: TouchableOpacityProps['onPress'];
|
|
33
32
|
style?: ViewStyle;
|
|
34
33
|
textStyle?: TextStyle;
|
|
35
34
|
spacing?: number;
|
|
36
35
|
labelStyle?: TextStyle;
|
|
37
|
-
};
|
|
36
|
+
} & TouchableOpacityProps;
|
|
38
37
|
export type InputProps = {
|
|
39
38
|
label?: string;
|
|
40
39
|
style?: TextInputProps['style'];
|
|
@@ -43,7 +42,7 @@ export type InputProps = {
|
|
|
43
42
|
placeholder?: TextInputProps['placeholder'];
|
|
44
43
|
value?: TextInputProps['value'];
|
|
45
44
|
onChangeText?: TextInputProps['onChangeText'];
|
|
46
|
-
};
|
|
45
|
+
} & TextInputProps;
|
|
47
46
|
export type IconProps = {
|
|
48
47
|
icon?: ImageProps['source'];
|
|
49
48
|
style?: ImageStyle;
|
package/package.json
CHANGED
package/src/Form.tsx
CHANGED
|
@@ -4,8 +4,8 @@ import InputText from "./components/InputText";
|
|
|
4
4
|
import Buttons from "./components/Buttons";
|
|
5
5
|
import { FormField, FormProps } from "./types";
|
|
6
6
|
|
|
7
|
-
export const Form:React.FC<FormProps> = ({ schema = [] }) => {
|
|
8
|
-
const RenderField = (field:FormField, index:number) => {
|
|
7
|
+
export const Form: React.FC<FormProps> = ({ schema = [] }) => {
|
|
8
|
+
const RenderField = (field: FormField, index: number) => {
|
|
9
9
|
switch (field.type) {
|
|
10
10
|
case "button":
|
|
11
11
|
return (
|
|
@@ -15,6 +15,7 @@ export const Form:React.FC<FormProps> = ({ schema = [] }) => {
|
|
|
15
15
|
style={field.style}
|
|
16
16
|
textStyle={field.textStyle}
|
|
17
17
|
spacing={field.spacing}
|
|
18
|
+
labelStyle={field.labelStyle}
|
|
18
19
|
{...(field.buttonProps || {})}
|
|
19
20
|
/>
|
|
20
21
|
);
|
|
@@ -26,6 +27,7 @@ export const Form:React.FC<FormProps> = ({ schema = [] }) => {
|
|
|
26
27
|
label={field.label}
|
|
27
28
|
style={field.style}
|
|
28
29
|
spacing={field.spacing}
|
|
30
|
+
labelStyle={field.labelStyle}
|
|
29
31
|
{...(field.inputProps || {})}
|
|
30
32
|
/>
|
|
31
33
|
);
|
|
@@ -11,12 +11,14 @@ const Buttons: React.FC<ButtonProps> = ({
|
|
|
11
11
|
textStyle,
|
|
12
12
|
spacing,
|
|
13
13
|
labelStyle,
|
|
14
|
+
...touchableProps
|
|
14
15
|
}) => {
|
|
15
16
|
return (
|
|
16
17
|
<View style={{ gap: spacing ?? 13 }}>
|
|
17
18
|
<FormText label={label || " "} style={labelStyle} />
|
|
18
19
|
|
|
19
20
|
<TouchableOpacity
|
|
21
|
+
{...touchableProps}
|
|
20
22
|
onPress={onPress}
|
|
21
23
|
style={[
|
|
22
24
|
{
|
|
@@ -4,30 +4,18 @@ import FormText from './Text';
|
|
|
4
4
|
import { InputProps } from '../types';
|
|
5
5
|
|
|
6
6
|
const InputText:React.FC<InputProps> = ({
|
|
7
|
-
|
|
8
|
-
placeholder,
|
|
9
|
-
value,
|
|
10
|
-
onChangeText,
|
|
7
|
+
label,
|
|
11
8
|
style,
|
|
12
|
-
spacing,
|
|
9
|
+
spacing = 13,
|
|
13
10
|
labelStyle,
|
|
11
|
+
...textInputProps
|
|
14
12
|
}) => {
|
|
15
13
|
return (
|
|
16
14
|
<View style={{ gap: spacing || 13 }}>
|
|
17
15
|
<FormText label={label || ' '} style={labelStyle} />
|
|
18
16
|
<TextInput
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
onChangeText={onChangeText}
|
|
22
|
-
style={[
|
|
23
|
-
{
|
|
24
|
-
borderWidth: 1,
|
|
25
|
-
borderColor: '#ccc',
|
|
26
|
-
padding: 10,
|
|
27
|
-
borderRadius: 6,
|
|
28
|
-
},
|
|
29
|
-
style,
|
|
30
|
-
]}
|
|
17
|
+
{...textInputProps} // 👈 forward EVERYTHING
|
|
18
|
+
style={style}
|
|
31
19
|
/>
|
|
32
20
|
</View>
|
|
33
21
|
);
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// types.ts
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ImageProps,
|
|
3
|
+
ImageStyle,
|
|
5
4
|
TextInputProps,
|
|
6
5
|
TextStyle,
|
|
7
6
|
TouchableOpacityProps,
|
|
@@ -41,16 +40,16 @@ export type FormProps = {
|
|
|
41
40
|
schema: FormItem[];
|
|
42
41
|
};
|
|
43
42
|
|
|
43
|
+
|
|
44
44
|
// Buttons.types.ts
|
|
45
45
|
export type ButtonProps = {
|
|
46
46
|
label?: string;
|
|
47
47
|
buttonText?: string;
|
|
48
|
-
onPress?: TouchableOpacityProps['onPress'];
|
|
49
48
|
style?: ViewStyle;
|
|
50
49
|
textStyle?: TextStyle;
|
|
51
50
|
spacing?: number;
|
|
52
51
|
labelStyle?: TextStyle;
|
|
53
|
-
};
|
|
52
|
+
} & TouchableOpacityProps;
|
|
54
53
|
|
|
55
54
|
// Input.types.ts
|
|
56
55
|
export type InputProps = {
|
|
@@ -61,7 +60,7 @@ export type InputProps = {
|
|
|
61
60
|
placeholder?:TextInputProps['placeholder'],
|
|
62
61
|
value?:TextInputProps['value'],
|
|
63
62
|
onChangeText?:TextInputProps['onChangeText'],
|
|
64
|
-
};
|
|
63
|
+
}& TextInputProps;
|
|
65
64
|
|
|
66
65
|
// Icon.types.ts
|
|
67
66
|
export type IconProps = {
|