@hitesh0009/react-native-basic-form 1.2.6 → 1.2.7
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.d.ts +2 -1
- package/dist/Form.js +23 -104
- package/dist/components/Buttons.d.ts +4 -0
- package/dist/components/Buttons.js +23 -0
- package/dist/components/Icon.d.ts +4 -0
- package/dist/components/Icon.js +13 -0
- package/dist/components/InputText.d.ts +4 -0
- package/dist/components/InputText.js +19 -0
- package/dist/components/Text.d.ts +4 -0
- package/dist/components/Text.js +16 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/types.d.ts +47 -64
- package/package.json +1 -1
- package/src/Form.tsx +48 -220
- package/src/components/Buttons.tsx +39 -0
- package/src/components/Icon.tsx +22 -0
- package/src/components/InputText.tsx +38 -0
- package/src/components/Text.tsx +24 -0
- package/src/index.ts +9 -3
- package/src/types.ts +54 -73
package/dist/Form.d.ts
CHANGED
package/dist/Form.js
CHANGED
|
@@ -1,105 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{item.button && (<View style={ButtonContainerStyle}>
|
|
26
|
-
<TouchableOpacity {...touchableOpacityProp} onPress={item.button.onPress} style={[styles.button_container, buttonContainerStyle]}>
|
|
27
|
-
<Text style={[styles.button_text, buttonTextStyle]}>
|
|
28
|
-
{item.button.label}
|
|
29
|
-
</Text>
|
|
30
|
-
</TouchableOpacity>
|
|
31
|
-
</View>)}
|
|
32
|
-
|
|
33
|
-
{item.buttonGroup && (<View style={[
|
|
34
|
-
{ flexDirection: "row", gap: 10 },
|
|
35
|
-
buttonGroupContainerStyle,
|
|
36
|
-
]}>
|
|
37
|
-
{item.buttonGroup.map((btn, index) => (<TouchableOpacity key={index} onPress={btn.onPress} style={[styles.button_container, buttonGroupStyle]}>
|
|
38
|
-
<Text style={[styles.button_text, buttonGroupTextStyle]}>
|
|
39
|
-
{btn.label}
|
|
40
|
-
</Text>
|
|
41
|
-
</TouchableOpacity>))}
|
|
42
|
-
</View>)}
|
|
43
|
-
|
|
44
|
-
{item.inputButtonGroup && (<View style={[
|
|
45
|
-
{ flexDirection: "row", gap: 10 },
|
|
46
|
-
inputButtonGroupContainerStyle,
|
|
47
|
-
]}>
|
|
48
|
-
<View style={[inputTextContainerStyle, { gap: gap_bwt_keyValue }]}>
|
|
49
|
-
<Text style={[styles.lable, lableStyle]}>
|
|
50
|
-
{item.inputButtonGroup.input.header}
|
|
51
|
-
</Text>
|
|
52
|
-
|
|
53
|
-
<TextInput {...textInputProps} style={[styles.inputtext, inputButtonGroupInputStyle]} placeholder={item.inputButtonGroup.input.placeholder} value={item.inputButtonGroup.input.value} onChangeText={item.inputButtonGroup.input.onChangeText} keyboardType={item.inputButtonGroup.input.keyboardType}/>
|
|
54
|
-
</View>
|
|
55
|
-
|
|
56
|
-
<View style={{ gap: gap_bwt_keyValue }}>
|
|
57
|
-
<Text style={[styles.lable, lableStyle]}>
|
|
58
|
-
{item.inputButtonGroup.button.header}
|
|
59
|
-
</Text>
|
|
60
|
-
|
|
61
|
-
<TouchableOpacity onPress={item.inputButtonGroup.button.onPress} style={[
|
|
62
|
-
styles.button_container,
|
|
63
|
-
inputButtonGroupButtonStyle,
|
|
64
|
-
]}>
|
|
65
|
-
<Text style={[
|
|
66
|
-
styles.button_text,
|
|
67
|
-
inputButtonGroupButtonTextStyle,
|
|
68
|
-
]}>
|
|
69
|
-
{item.inputButtonGroup.button.label}
|
|
70
|
-
</Text>
|
|
71
|
-
</TouchableOpacity>
|
|
72
|
-
</View>
|
|
73
|
-
</View>)}
|
|
74
|
-
</View>)}/>
|
|
75
|
-
</View>);
|
|
1
|
+
import { View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import InputText from "./components/InputText";
|
|
4
|
+
import Buttons from "./components/Buttons";
|
|
5
|
+
export const Form = ({ schema = [] }) => {
|
|
6
|
+
const RenderField = (field, index) => {
|
|
7
|
+
switch (field.type) {
|
|
8
|
+
case "button":
|
|
9
|
+
return (<Buttons key={index} label={field.label} style={field.style} textStyle={field.textStyle} gap={13} {...(field.buttonProps || {})}/>);
|
|
10
|
+
case "input":
|
|
11
|
+
return (<InputText key={index} label={field.label} style={field.style} gap={13} {...(field.inputProps || {})}/>);
|
|
12
|
+
default:
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return (<>
|
|
17
|
+
{schema.map((block, blockIndex) => (<View key={blockIndex} style={{
|
|
18
|
+
flexDirection: block.layout || "column",
|
|
19
|
+
gap: block.gap || 20,
|
|
20
|
+
}}>
|
|
21
|
+
{block.children.map(RenderField)}
|
|
22
|
+
</View>))}
|
|
23
|
+
</>);
|
|
76
24
|
};
|
|
77
|
-
const styles = StyleSheet.create({
|
|
78
|
-
lable: {
|
|
79
|
-
color: "#000",
|
|
80
|
-
fontSize: 14,
|
|
81
|
-
},
|
|
82
|
-
inputtext: {
|
|
83
|
-
color: "#000",
|
|
84
|
-
fontSize: 12,
|
|
85
|
-
borderWidth: 1,
|
|
86
|
-
borderColor: "#b1b0b0",
|
|
87
|
-
borderRadius: 10,
|
|
88
|
-
padding: 10,
|
|
89
|
-
},
|
|
90
|
-
button_container: {},
|
|
91
|
-
button_text: {
|
|
92
|
-
color: "#000",
|
|
93
|
-
fontSize: 14,
|
|
94
|
-
},
|
|
95
|
-
headericon: {
|
|
96
|
-
height: 30,
|
|
97
|
-
width: 30,
|
|
98
|
-
resizeMode: "contain",
|
|
99
|
-
},
|
|
100
|
-
headertext: {
|
|
101
|
-
color: "#000",
|
|
102
|
-
fontSize: 18,
|
|
103
|
-
fontWeight: "400",
|
|
104
|
-
},
|
|
105
|
-
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Text, TouchableOpacity, View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import FormText from "./Text";
|
|
4
|
+
const Buttons = ({ label, buttonText, onPress, style, textStyle, gap, labelStyle, }) => {
|
|
5
|
+
return (<View style={{ gap: gap !== null && gap !== void 0 ? gap : 13 }}>
|
|
6
|
+
<FormText label={label || " "} style={labelStyle}/>
|
|
7
|
+
|
|
8
|
+
<TouchableOpacity onPress={onPress} style={[
|
|
9
|
+
{
|
|
10
|
+
backgroundColor: "#2563eb",
|
|
11
|
+
padding: 14,
|
|
12
|
+
borderRadius: 8,
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
},
|
|
15
|
+
style,
|
|
16
|
+
]}>
|
|
17
|
+
<Text style={[{ color: "#fff", fontWeight: "600" }, textStyle]}>
|
|
18
|
+
{buttonText !== null && buttonText !== void 0 ? buttonText : label}
|
|
19
|
+
</Text>
|
|
20
|
+
</TouchableOpacity>
|
|
21
|
+
</View>);
|
|
22
|
+
};
|
|
23
|
+
export default Buttons;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Image, StyleSheet, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
const Icon = ({ icon, style }) => {
|
|
4
|
+
return (<View>
|
|
5
|
+
<Image style={[{
|
|
6
|
+
height: 30,
|
|
7
|
+
width: 30,
|
|
8
|
+
objectFit: 'contain',
|
|
9
|
+
}, style]} source={icon}/>
|
|
10
|
+
</View>);
|
|
11
|
+
};
|
|
12
|
+
export default Icon;
|
|
13
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StyleSheet, TextInput, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import FormText from './Text';
|
|
4
|
+
const InputText = ({ label, placeholder, value, onChangeText, style, gap, labelStyle, }) => {
|
|
5
|
+
return (<View style={{ gap: gap || 13 }}>
|
|
6
|
+
<FormText label={label || ' '} style={labelStyle}/>
|
|
7
|
+
<TextInput placeholder={placeholder} value={value} onChangeText={onChangeText} style={[
|
|
8
|
+
{
|
|
9
|
+
borderWidth: 1,
|
|
10
|
+
borderColor: '#ccc',
|
|
11
|
+
padding: 10,
|
|
12
|
+
borderRadius: 6,
|
|
13
|
+
},
|
|
14
|
+
style,
|
|
15
|
+
]}/>
|
|
16
|
+
</View>);
|
|
17
|
+
};
|
|
18
|
+
export default InputText;
|
|
19
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
const FormText = ({ label, style }) => {
|
|
4
|
+
return (<View>
|
|
5
|
+
<Text style={[
|
|
6
|
+
{
|
|
7
|
+
color: '#000',
|
|
8
|
+
},
|
|
9
|
+
style,
|
|
10
|
+
]}>
|
|
11
|
+
{label || ' '}
|
|
12
|
+
</Text>
|
|
13
|
+
</View>);
|
|
14
|
+
};
|
|
15
|
+
export default FormText;
|
|
16
|
+
const styles = StyleSheet.create({});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Form } from
|
|
2
|
-
export { FormProps, FormItem, FormInput, FormButton } from
|
|
1
|
+
export { Form } from "./Form";
|
|
2
|
+
export { FormProps, FormItem, FormInput, FormButton, ButtonProps, InputProps, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Form } from
|
|
1
|
+
export { Form } from "./Form";
|
package/dist/types.d.ts
CHANGED
|
@@ -1,72 +1,55 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
textAlignVertical?: TextInputProps["textAlignVertical"];
|
|
8
|
-
keyboardType?: TextInputProps["keyboardType"];
|
|
1
|
+
import type { ImageProps, ImageStyle, TextInputProps, TextStyle, TouchableOpacityProps, ViewStyle } from 'react-native';
|
|
2
|
+
type BaseField = {
|
|
3
|
+
label?: string;
|
|
4
|
+
gap?: number;
|
|
5
|
+
style?: ViewStyle;
|
|
6
|
+
labelStyle?: TextStyle;
|
|
9
7
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export type FormInput = BaseField & {
|
|
9
|
+
type: 'input';
|
|
10
|
+
inputProps?: TextInputProps;
|
|
13
11
|
};
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
keyboardType?: TextInputProps["keyboardType"];
|
|
12
|
+
export type FormButton = BaseField & {
|
|
13
|
+
type: 'button';
|
|
14
|
+
textStyle?: TextStyle;
|
|
15
|
+
buttonProps?: {
|
|
16
|
+
buttonText?: string;
|
|
17
|
+
onPress?: TouchableOpacityProps['onPress'];
|
|
18
|
+
};
|
|
22
19
|
};
|
|
23
|
-
export type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
export type FormField = FormInput | FormButton;
|
|
21
|
+
export type FormItem = {
|
|
22
|
+
layout?: ViewStyle['flexDirection'];
|
|
23
|
+
gap?: number;
|
|
24
|
+
children: FormField[];
|
|
27
25
|
};
|
|
28
|
-
export type
|
|
29
|
-
|
|
30
|
-
button: ForminputButtonGroupButton;
|
|
26
|
+
export type FormProps = {
|
|
27
|
+
schema: FormItem[];
|
|
31
28
|
};
|
|
32
|
-
export type
|
|
33
|
-
id: string;
|
|
29
|
+
export type ButtonProps = {
|
|
34
30
|
label?: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
buttonText?: string;
|
|
32
|
+
onPress?: TouchableOpacityProps['onPress'];
|
|
33
|
+
style?: ViewStyle;
|
|
34
|
+
textStyle?: TextStyle;
|
|
35
|
+
gap?: number;
|
|
36
|
+
labelStyle?: TextStyle;
|
|
40
37
|
};
|
|
41
|
-
export type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
headerContainerStyle?: ViewStyle;
|
|
58
|
-
containerStyle?: ViewStyle;
|
|
59
|
-
textInputProps?: TextInputProps;
|
|
60
|
-
imageContainerStyle?: ViewStyle;
|
|
61
|
-
touchableOpacityProp?: TouchableOpacityProps;
|
|
62
|
-
inputTextContainerStyle?: ViewStyle;
|
|
63
|
-
ButtonContainerStyle?: ViewStyle;
|
|
64
|
-
buttonGroupContainerStyle?: ViewStyle;
|
|
65
|
-
buttonGroupStyle?: ViewStyle;
|
|
66
|
-
inputTextGroupContainerStyle?: ViewStyle;
|
|
67
|
-
inputButtonGroupContainerStyle?: ViewStyle;
|
|
68
|
-
inputButtonGroupInputStyle?: ViewStyle;
|
|
69
|
-
inputButtonGroupButtonStyle?: ViewStyle;
|
|
70
|
-
inputButtonGroupButtonTextStyle?: ViewStyle;
|
|
71
|
-
buttonGroupTextStyle?: TextStyle;
|
|
38
|
+
export type InputProps = {
|
|
39
|
+
label?: string;
|
|
40
|
+
style?: TextInputProps['style'];
|
|
41
|
+
gap?: number;
|
|
42
|
+
labelStyle?: TextStyle;
|
|
43
|
+
placeholder?: TextInputProps['placeholder'];
|
|
44
|
+
value?: TextInputProps['value'];
|
|
45
|
+
onChangeText?: TextInputProps['onChangeText'];
|
|
46
|
+
};
|
|
47
|
+
export type IconProps = {
|
|
48
|
+
icon?: ImageProps['source'];
|
|
49
|
+
style?: ImageStyle;
|
|
50
|
+
};
|
|
51
|
+
export type TextProps = {
|
|
52
|
+
label?: string;
|
|
53
|
+
style?: TextStyle;
|
|
72
54
|
};
|
|
55
|
+
export {};
|
package/package.json
CHANGED
package/src/Form.tsx
CHANGED
|
@@ -1,225 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import InputText from "./components/InputText";
|
|
4
|
+
import Buttons from "./components/Buttons";
|
|
5
|
+
import { FormField, FormProps } from "./types";
|
|
6
|
+
|
|
7
|
+
export const Form:React.FC<FormProps> = ({ schema = [] }) => {
|
|
8
|
+
const RenderField = (field:FormField, index:number) => {
|
|
9
|
+
switch (field.type) {
|
|
10
|
+
case "button":
|
|
11
|
+
return (
|
|
12
|
+
<Buttons
|
|
13
|
+
key={index}
|
|
14
|
+
label={field.label}
|
|
15
|
+
style={field.style}
|
|
16
|
+
textStyle={field.textStyle}
|
|
17
|
+
gap={13}
|
|
18
|
+
{...(field.buttonProps || {})}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
case "input":
|
|
23
|
+
return (
|
|
24
|
+
<InputText
|
|
25
|
+
key={index}
|
|
26
|
+
label={field.label}
|
|
27
|
+
style={field.style}
|
|
28
|
+
gap={13}
|
|
29
|
+
{...(field.inputProps || {})}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
default:
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
11
37
|
|
|
12
|
-
export const Form: React.FC<FormProps> = ({
|
|
13
|
-
data,
|
|
14
|
-
gap_bwt_keyValue = 10,
|
|
15
|
-
gap_bwt_keys = 12,
|
|
16
|
-
lableStyle,
|
|
17
|
-
inputTextStyle,
|
|
18
|
-
buttonContainerStyle,
|
|
19
|
-
buttonTextStyle,
|
|
20
|
-
headerIcon,
|
|
21
|
-
|
|
22
|
-
headerIconStyle,
|
|
23
|
-
headerTextStyle,
|
|
24
|
-
|
|
25
|
-
imageProps,
|
|
26
|
-
flatlistProps,
|
|
27
|
-
textInputProps,
|
|
28
|
-
textProp,
|
|
29
|
-
headerText,
|
|
30
|
-
headerContainerStyle,
|
|
31
|
-
containerStyle,
|
|
32
|
-
imageContainerStyle,
|
|
33
|
-
touchableOpacityProp,
|
|
34
|
-
|
|
35
|
-
inputTextContainerStyle,
|
|
36
|
-
inputTextGroupContainerStyle,
|
|
37
|
-
|
|
38
|
-
ButtonContainerStyle,
|
|
39
|
-
|
|
40
|
-
buttonGroupContainerStyle,
|
|
41
|
-
buttonGroupStyle,
|
|
42
|
-
buttonGroupTextStyle,
|
|
43
|
-
|
|
44
|
-
inputButtonGroupContainerStyle,
|
|
45
|
-
inputButtonGroupInputStyle,
|
|
46
|
-
inputButtonGroupButtonStyle,
|
|
47
|
-
inputButtonGroupButtonTextStyle,
|
|
48
|
-
}) => {
|
|
49
38
|
return (
|
|
50
|
-
|
|
51
|
-
{(
|
|
52
|
-
<View
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</View>
|
|
61
|
-
)}
|
|
62
|
-
{headerText && (
|
|
63
|
-
<Text style={[styles.headertext, headerTextStyle]} {...textProp}>
|
|
64
|
-
{headerText}
|
|
65
|
-
</Text>
|
|
66
|
-
)}
|
|
39
|
+
<>
|
|
40
|
+
{schema.map((block, blockIndex) => (
|
|
41
|
+
<View
|
|
42
|
+
key={blockIndex}
|
|
43
|
+
style={{
|
|
44
|
+
flexDirection: block.layout || "column",
|
|
45
|
+
gap: block.gap || 20,
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{block.children.map(RenderField)}
|
|
67
49
|
</View>
|
|
68
|
-
)}
|
|
69
|
-
|
|
70
|
-
<FlatList<FormItem>
|
|
71
|
-
data={data}
|
|
72
|
-
{...flatlistProps}
|
|
73
|
-
ItemSeparatorComponent={() => <View style={{ height: gap_bwt_keys }} />}
|
|
74
|
-
renderItem={({ item }) => (
|
|
75
|
-
<View style={{ gap: gap_bwt_keyValue }}>
|
|
76
|
-
{item.label && (
|
|
77
|
-
<Text style={[styles.lable, lableStyle]}>{item.label}</Text>
|
|
78
|
-
)}
|
|
79
|
-
|
|
80
|
-
{item.input && (
|
|
81
|
-
<View style={inputTextContainerStyle}>
|
|
82
|
-
<TextInput
|
|
83
|
-
{...textInputProps}
|
|
84
|
-
style={[styles.inputtext, inputTextStyle]}
|
|
85
|
-
placeholder={item.input.placeholder}
|
|
86
|
-
value={item.input.value}
|
|
87
|
-
onChangeText={item.input.onChangeText}
|
|
88
|
-
keyboardType={item.input.keyboardType}
|
|
89
|
-
/>
|
|
90
|
-
</View>
|
|
91
|
-
)}
|
|
92
|
-
|
|
93
|
-
{item.inputTextGroup &&
|
|
94
|
-
item.inputTextGroup.map((inp, index) => (
|
|
95
|
-
<View key={index} style={inputTextGroupContainerStyle}>
|
|
96
|
-
<TextInput
|
|
97
|
-
{...textInputProps}
|
|
98
|
-
style={[styles.inputtext, inputTextStyle]}
|
|
99
|
-
placeholder={inp.placeholder}
|
|
100
|
-
value={inp.value}
|
|
101
|
-
onChangeText={inp.onChangeText}
|
|
102
|
-
keyboardType={inp.keyboardType}
|
|
103
|
-
/>
|
|
104
|
-
</View>
|
|
105
|
-
))}
|
|
106
|
-
|
|
107
|
-
{item.button && (
|
|
108
|
-
<View style={ButtonContainerStyle}>
|
|
109
|
-
<TouchableOpacity
|
|
110
|
-
{...touchableOpacityProp}
|
|
111
|
-
onPress={item.button.onPress}
|
|
112
|
-
style={[styles.button_container, buttonContainerStyle]}
|
|
113
|
-
>
|
|
114
|
-
<Text style={[styles.button_text, buttonTextStyle]}>
|
|
115
|
-
{item.button.label}
|
|
116
|
-
</Text>
|
|
117
|
-
</TouchableOpacity>
|
|
118
|
-
</View>
|
|
119
|
-
)}
|
|
120
|
-
|
|
121
|
-
{item.buttonGroup && (
|
|
122
|
-
<View
|
|
123
|
-
style={[
|
|
124
|
-
{ flexDirection: "row", gap: 10 },
|
|
125
|
-
buttonGroupContainerStyle,
|
|
126
|
-
]}
|
|
127
|
-
>
|
|
128
|
-
{item.buttonGroup.map((btn, index) => (
|
|
129
|
-
<TouchableOpacity
|
|
130
|
-
key={index}
|
|
131
|
-
onPress={btn.onPress}
|
|
132
|
-
style={[styles.button_container, buttonGroupStyle]}
|
|
133
|
-
>
|
|
134
|
-
<Text style={[styles.button_text, buttonGroupTextStyle]}>
|
|
135
|
-
{btn.label}
|
|
136
|
-
</Text>
|
|
137
|
-
</TouchableOpacity>
|
|
138
|
-
))}
|
|
139
|
-
</View>
|
|
140
|
-
)}
|
|
141
|
-
|
|
142
|
-
{item.inputButtonGroup && (
|
|
143
|
-
<View
|
|
144
|
-
style={[
|
|
145
|
-
{ flexDirection: "row", gap: 10 },
|
|
146
|
-
inputButtonGroupContainerStyle,
|
|
147
|
-
]}
|
|
148
|
-
>
|
|
149
|
-
<View
|
|
150
|
-
style={[inputTextContainerStyle, { gap: gap_bwt_keyValue }]}
|
|
151
|
-
>
|
|
152
|
-
<Text style={[styles.lable, lableStyle]}>
|
|
153
|
-
{item.inputButtonGroup.input.header}
|
|
154
|
-
</Text>
|
|
155
|
-
|
|
156
|
-
<TextInput
|
|
157
|
-
{...textInputProps}
|
|
158
|
-
style={[styles.inputtext, inputButtonGroupInputStyle]}
|
|
159
|
-
placeholder={item.inputButtonGroup.input.placeholder}
|
|
160
|
-
value={item.inputButtonGroup.input.value}
|
|
161
|
-
onChangeText={item.inputButtonGroup.input.onChangeText}
|
|
162
|
-
keyboardType={item.inputButtonGroup.input.keyboardType}
|
|
163
|
-
/>
|
|
164
|
-
</View>
|
|
165
|
-
|
|
166
|
-
<View style={{ gap: gap_bwt_keyValue }}>
|
|
167
|
-
<Text style={[styles.lable, lableStyle]}>
|
|
168
|
-
{item.inputButtonGroup.button.header}
|
|
169
|
-
</Text>
|
|
170
|
-
|
|
171
|
-
<TouchableOpacity
|
|
172
|
-
onPress={item.inputButtonGroup.button.onPress}
|
|
173
|
-
style={[
|
|
174
|
-
styles.button_container,
|
|
175
|
-
inputButtonGroupButtonStyle,
|
|
176
|
-
]}
|
|
177
|
-
>
|
|
178
|
-
<Text
|
|
179
|
-
style={[
|
|
180
|
-
styles.button_text,
|
|
181
|
-
inputButtonGroupButtonTextStyle,
|
|
182
|
-
]}
|
|
183
|
-
>
|
|
184
|
-
{item.inputButtonGroup.button.label}
|
|
185
|
-
</Text>
|
|
186
|
-
</TouchableOpacity>
|
|
187
|
-
</View>
|
|
188
|
-
</View>
|
|
189
|
-
)}
|
|
190
|
-
</View>
|
|
191
|
-
)}
|
|
192
|
-
/>
|
|
193
|
-
</View>
|
|
50
|
+
))}
|
|
51
|
+
</>
|
|
194
52
|
);
|
|
195
53
|
};
|
|
196
|
-
|
|
197
|
-
const styles = StyleSheet.create({
|
|
198
|
-
lable: {
|
|
199
|
-
color: "#000",
|
|
200
|
-
fontSize: 14,
|
|
201
|
-
},
|
|
202
|
-
inputtext: {
|
|
203
|
-
color: "#000",
|
|
204
|
-
fontSize: 12,
|
|
205
|
-
borderWidth: 1,
|
|
206
|
-
borderColor: "#b1b0b0",
|
|
207
|
-
borderRadius: 10,
|
|
208
|
-
padding: 10,
|
|
209
|
-
},
|
|
210
|
-
button_container: {},
|
|
211
|
-
button_text: {
|
|
212
|
-
color: "#000",
|
|
213
|
-
fontSize: 14,
|
|
214
|
-
},
|
|
215
|
-
headericon: {
|
|
216
|
-
height: 30,
|
|
217
|
-
width: 30,
|
|
218
|
-
resizeMode: "contain",
|
|
219
|
-
},
|
|
220
|
-
headertext: {
|
|
221
|
-
color: "#000",
|
|
222
|
-
fontSize: 18,
|
|
223
|
-
fontWeight: "400",
|
|
224
|
-
},
|
|
225
|
-
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import FormText from "./Text";
|
|
4
|
+
import type { ButtonProps } from "../types";
|
|
5
|
+
|
|
6
|
+
const Buttons: React.FC<ButtonProps> = ({
|
|
7
|
+
label,
|
|
8
|
+
buttonText,
|
|
9
|
+
onPress,
|
|
10
|
+
style,
|
|
11
|
+
textStyle,
|
|
12
|
+
gap,
|
|
13
|
+
labelStyle,
|
|
14
|
+
}) => {
|
|
15
|
+
return (
|
|
16
|
+
<View style={{ gap: gap ?? 13 }}>
|
|
17
|
+
<FormText label={label || " "} style={labelStyle} />
|
|
18
|
+
|
|
19
|
+
<TouchableOpacity
|
|
20
|
+
onPress={onPress}
|
|
21
|
+
style={[
|
|
22
|
+
{
|
|
23
|
+
backgroundColor: "#2563eb",
|
|
24
|
+
padding: 14,
|
|
25
|
+
borderRadius: 8,
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
},
|
|
28
|
+
style,
|
|
29
|
+
]}
|
|
30
|
+
>
|
|
31
|
+
<Text style={[{ color: "#fff", fontWeight: "600" }, textStyle]}>
|
|
32
|
+
{buttonText ?? label}
|
|
33
|
+
</Text>
|
|
34
|
+
</TouchableOpacity>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default Buttons;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Image, StyleSheet, Text, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IconProps } from '../types';
|
|
4
|
+
|
|
5
|
+
const Icon:React.FC<IconProps> = ({ icon,style }) => {
|
|
6
|
+
return (
|
|
7
|
+
<View>
|
|
8
|
+
<Image
|
|
9
|
+
style={[{
|
|
10
|
+
height: 30,
|
|
11
|
+
width: 30,
|
|
12
|
+
objectFit: 'contain',
|
|
13
|
+
},style]}
|
|
14
|
+
source={icon}
|
|
15
|
+
/>
|
|
16
|
+
</View>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default Icon;
|
|
21
|
+
|
|
22
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { StyleSheet, Text, TextInput, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import FormText from './Text';
|
|
4
|
+
import { InputProps } from '../types';
|
|
5
|
+
|
|
6
|
+
const InputText:React.FC<InputProps> = ({
|
|
7
|
+
label,
|
|
8
|
+
placeholder,
|
|
9
|
+
value,
|
|
10
|
+
onChangeText,
|
|
11
|
+
style,
|
|
12
|
+
gap,
|
|
13
|
+
labelStyle,
|
|
14
|
+
}) => {
|
|
15
|
+
return (
|
|
16
|
+
<View style={{ gap: gap || 13 }}>
|
|
17
|
+
<FormText label={label || ' '} style={labelStyle} />
|
|
18
|
+
<TextInput
|
|
19
|
+
placeholder={placeholder}
|
|
20
|
+
value={value}
|
|
21
|
+
onChangeText={onChangeText}
|
|
22
|
+
style={[
|
|
23
|
+
{
|
|
24
|
+
borderWidth: 1,
|
|
25
|
+
borderColor: '#ccc',
|
|
26
|
+
padding: 10,
|
|
27
|
+
borderRadius: 6,
|
|
28
|
+
},
|
|
29
|
+
style,
|
|
30
|
+
]}
|
|
31
|
+
/>
|
|
32
|
+
</View>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default InputText;
|
|
37
|
+
|
|
38
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TextProps } from '../types';
|
|
4
|
+
|
|
5
|
+
const FormText:React.FC<TextProps> = ({ label, style }) => {
|
|
6
|
+
return (
|
|
7
|
+
<View>
|
|
8
|
+
<Text
|
|
9
|
+
style={[
|
|
10
|
+
{
|
|
11
|
+
color: '#000',
|
|
12
|
+
},
|
|
13
|
+
style,
|
|
14
|
+
]}
|
|
15
|
+
>
|
|
16
|
+
{label || ' '}
|
|
17
|
+
</Text>
|
|
18
|
+
</View>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default FormText;
|
|
23
|
+
|
|
24
|
+
const styles = StyleSheet.create({});
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,95 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
// types.ts
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ImageSourcePropType,
|
|
6
|
-
ImageStyle,
|
|
3
|
+
ImageProps,
|
|
4
|
+
ImageStyle,
|
|
7
5
|
TextInputProps,
|
|
8
|
-
TextProps,
|
|
9
6
|
TextStyle,
|
|
10
7
|
TouchableOpacityProps,
|
|
11
8
|
ViewStyle,
|
|
12
|
-
} from
|
|
9
|
+
} from 'react-native';
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
textAlignVertical?: TextInputProps["textAlignVertical"];
|
|
20
|
-
keyboardType?: TextInputProps["keyboardType"];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type FormButton = {
|
|
24
|
-
label: string;
|
|
25
|
-
onPress: () => void;
|
|
11
|
+
type BaseField = {
|
|
12
|
+
label?: string;
|
|
13
|
+
gap?: number;
|
|
14
|
+
style?: ViewStyle;
|
|
15
|
+
labelStyle?: TextStyle;
|
|
26
16
|
};
|
|
27
17
|
|
|
28
|
-
export type
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
value: string;
|
|
32
|
-
onChangeText: TextInputProps["onChangeText"];
|
|
33
|
-
multiline?: TextInputProps["multiline"];
|
|
34
|
-
textAlignVertical?: TextInputProps["textAlignVertical"];
|
|
35
|
-
keyboardType?: TextInputProps["keyboardType"];
|
|
18
|
+
export type FormInput = BaseField & {
|
|
19
|
+
type: 'input';
|
|
20
|
+
inputProps?: TextInputProps;
|
|
36
21
|
};
|
|
37
22
|
|
|
38
|
-
export type
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
export type FormButton = BaseField & {
|
|
24
|
+
type: 'button';
|
|
25
|
+
textStyle?: TextStyle;
|
|
26
|
+
buttonProps?: {
|
|
27
|
+
buttonText?: string;
|
|
28
|
+
onPress?: TouchableOpacityProps['onPress'];
|
|
29
|
+
};
|
|
42
30
|
};
|
|
43
31
|
|
|
44
|
-
export type
|
|
45
|
-
input: ForminputButtonGroupInput;
|
|
46
|
-
button: ForminputButtonGroupButton;
|
|
47
|
-
};
|
|
32
|
+
export type FormField = FormInput | FormButton;
|
|
48
33
|
|
|
49
34
|
export type FormItem = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
button?: FormButton;
|
|
54
|
-
buttonGroup?: FormButton[];
|
|
55
|
-
inputTextGroup?: FormInput[];
|
|
56
|
-
inputButtonGroup?: ForminputButtonGroup;
|
|
35
|
+
layout?: ViewStyle['flexDirection'];
|
|
36
|
+
gap?: number;
|
|
37
|
+
children: FormField[];
|
|
57
38
|
};
|
|
58
39
|
|
|
59
40
|
export type FormProps = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
gap_bwt_keyValue?: number;
|
|
63
|
-
gap_bwt_keys?: number;
|
|
41
|
+
schema: FormItem[];
|
|
42
|
+
};
|
|
64
43
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
// Buttons.types.ts
|
|
45
|
+
export type ButtonProps = {
|
|
46
|
+
label?: string;
|
|
47
|
+
buttonText?: string;
|
|
48
|
+
onPress?: TouchableOpacityProps['onPress'];
|
|
49
|
+
style?: ViewStyle;
|
|
50
|
+
textStyle?: TextStyle;
|
|
51
|
+
gap?: number;
|
|
52
|
+
labelStyle?: TextStyle;
|
|
53
|
+
};
|
|
69
54
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
// Input.types.ts
|
|
56
|
+
export type InputProps = {
|
|
57
|
+
label?: string;
|
|
58
|
+
style?: TextInputProps['style'];
|
|
59
|
+
gap?: number;
|
|
60
|
+
labelStyle?: TextStyle;
|
|
61
|
+
placeholder?:TextInputProps['placeholder'],
|
|
62
|
+
value?:TextInputProps['value'],
|
|
63
|
+
onChangeText?:TextInputProps['onChangeText'],
|
|
64
|
+
};
|
|
75
65
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
// Icon.types.ts
|
|
67
|
+
export type IconProps = {
|
|
68
|
+
icon?: ImageProps['source'];
|
|
69
|
+
style?: ImageStyle;
|
|
70
|
+
};
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
touchableOpacityProp?: TouchableOpacityProps;
|
|
85
|
-
inputTextContainerStyle?: ViewStyle;
|
|
86
|
-
ButtonContainerStyle?: ViewStyle;
|
|
87
|
-
buttonGroupContainerStyle?: ViewStyle;
|
|
88
|
-
buttonGroupStyle?: ViewStyle;
|
|
89
|
-
inputTextGroupContainerStyle?: ViewStyle;
|
|
90
|
-
inputButtonGroupContainerStyle?: ViewStyle;
|
|
91
|
-
inputButtonGroupInputStyle?:ViewStyle,
|
|
92
|
-
inputButtonGroupButtonStyle?:ViewStyle,
|
|
93
|
-
inputButtonGroupButtonTextStyle?:ViewStyle
|
|
94
|
-
buttonGroupTextStyle?:TextStyle
|
|
72
|
+
// Text.types.ts
|
|
73
|
+
export type TextProps = {
|
|
74
|
+
label?: string;
|
|
75
|
+
style?: TextStyle;
|
|
95
76
|
};
|