@hitesh0009/react-native-basic-form 1.3.6 → 1.3.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/README.md +35 -9
- package/basic_usage/example.js +45 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ The renderer stays the same — **only the JSON changes**.
|
|
|
13
13
|
|
|
14
14
|
## ❌ The Problem
|
|
15
15
|
|
|
16
|
-
- Forms are
|
|
16
|
+
- Forms are tightly coupled to JSX
|
|
17
17
|
- Layout changes require code changes
|
|
18
18
|
- Reusing forms across screens is painful
|
|
19
19
|
- Dynamic or server-driven forms are difficult
|
|
20
|
-
- UI logic and
|
|
20
|
+
- UI logic and structure get mixed together
|
|
21
21
|
|
|
22
22
|
As a result, forms often become one of the **least maintainable parts** of an app.
|
|
23
23
|
|
|
@@ -28,6 +28,7 @@ As a result, forms often become one of the **least maintainable parts** of an ap
|
|
|
28
28
|
**React Native Basic Form** lets you control **everything about a form through JSON**:
|
|
29
29
|
|
|
30
30
|
- what fields exist
|
|
31
|
+
- how they are grouped
|
|
31
32
|
- how they are laid out
|
|
32
33
|
- how they behave
|
|
33
34
|
- how they look
|
|
@@ -45,7 +46,7 @@ A **schema-driven, fully customizable form renderer for React Native**.
|
|
|
45
46
|
## 🎯 Who This Is For
|
|
46
47
|
|
|
47
48
|
- Apps with many forms
|
|
48
|
-
- Admin panels
|
|
49
|
+
- Admin panels & dashboards
|
|
49
50
|
- Server-driven or config-based UIs
|
|
50
51
|
- Teams that want consistent form behavior
|
|
51
52
|
- Developers who prefer data-driven UI
|
|
@@ -95,8 +96,13 @@ const formSchema = [
|
|
|
95
96
|
{
|
|
96
97
|
layout: 'column',
|
|
97
98
|
spacing: 20,
|
|
98
|
-
style: { padding: 16 }, //
|
|
99
|
+
style: { padding: 16 }, // block-level styling
|
|
99
100
|
children: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
label: 'Contact Information',
|
|
104
|
+
labelStyle: { fontSize: 18, fontWeight: '600' },
|
|
105
|
+
},
|
|
100
106
|
{
|
|
101
107
|
type: 'input',
|
|
102
108
|
label: 'Contact Person Name',
|
|
@@ -157,7 +163,7 @@ The form renderer handles **how** it is rendered.
|
|
|
157
163
|
|
|
158
164
|
### 2. Layout Blocks
|
|
159
165
|
|
|
160
|
-
Each schema block controls
|
|
166
|
+
Each schema block controls grouping and layout.
|
|
161
167
|
|
|
162
168
|
```ts
|
|
163
169
|
{
|
|
@@ -177,10 +183,11 @@ Supported layouts:
|
|
|
177
183
|
|
|
178
184
|
### 3. Fields
|
|
179
185
|
|
|
180
|
-
Each
|
|
186
|
+
Each item inside `children` is a **field**.
|
|
181
187
|
|
|
182
188
|
Supported field types:
|
|
183
189
|
|
|
190
|
+
* `text`
|
|
184
191
|
* `input`
|
|
185
192
|
* `button`
|
|
186
193
|
|
|
@@ -188,6 +195,25 @@ Supported field types:
|
|
|
188
195
|
|
|
189
196
|
## 🧩 Field Types
|
|
190
197
|
|
|
198
|
+
### 🔹 Text Field (Label / Header / Helper)
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
{
|
|
202
|
+
type: 'text',
|
|
203
|
+
label: 'Preferred Train Type',
|
|
204
|
+
labelStyle: { fontSize: 16, fontWeight: '500' },
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Used for:
|
|
209
|
+
|
|
210
|
+
* section headers
|
|
211
|
+
* group labels
|
|
212
|
+
* instructions
|
|
213
|
+
* helper text
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
191
217
|
### 🔹 Input Field
|
|
192
218
|
|
|
193
219
|
```ts
|
|
@@ -267,7 +293,7 @@ No translation logic is included.
|
|
|
267
293
|
|
|
268
294
|
## 🧱 TypeScript Support
|
|
269
295
|
|
|
270
|
-
The library exposes a **strict schema contract**.
|
|
296
|
+
The library exposes a **strict, typed schema contract**.
|
|
271
297
|
|
|
272
298
|
```ts
|
|
273
299
|
export type FormItem = {
|
|
@@ -300,7 +326,7 @@ TypeScript will:
|
|
|
300
326
|
|
|
301
327
|
## 🔧 Extending the Form
|
|
302
328
|
|
|
303
|
-
To add new field types (e.g. `
|
|
329
|
+
To add new field types (e.g. `checkbox`, `radioGroup`, `select`):
|
|
304
330
|
|
|
305
331
|
1. Extend the schema type
|
|
306
332
|
2. Add a case in the renderer
|
|
@@ -320,7 +346,7 @@ It focuses on **rendering**, not logic.
|
|
|
320
346
|
|
|
321
347
|
---
|
|
322
348
|
|
|
323
|
-
## 🛣 Roadmap
|
|
349
|
+
## 🛣 Roadmap
|
|
324
350
|
|
|
325
351
|
* Conditional rendering
|
|
326
352
|
* Repeatable field groups
|
package/basic_usage/example.js
CHANGED
|
@@ -3,43 +3,69 @@ import { View } from "react-native";
|
|
|
3
3
|
import { Form } from "react-native-basic-form";
|
|
4
4
|
|
|
5
5
|
export default function App() {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* ✅ Form state is owned by YOU
|
|
8
|
+
* This library is intentionally stateless.
|
|
9
|
+
*/
|
|
8
10
|
const [name, setName] = useState("");
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* ✅ Schema controls the entire form UI
|
|
14
|
+
* Change this JSON → the form UI updates automatically
|
|
15
|
+
*/
|
|
12
16
|
const formSchema = [
|
|
13
17
|
{
|
|
14
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Layout block
|
|
20
|
+
* Controls grouping, direction, and spacing
|
|
21
|
+
*/
|
|
15
22
|
layout: "column",
|
|
16
|
-
spacing: 16,
|
|
23
|
+
spacing: 16,
|
|
17
24
|
|
|
18
|
-
// Children = actual form fields
|
|
19
25
|
children: [
|
|
20
26
|
{
|
|
21
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Text field
|
|
29
|
+
* Used for headings, labels, instructions, or helper text
|
|
30
|
+
*/
|
|
31
|
+
type: "text",
|
|
32
|
+
label: "User Information",
|
|
33
|
+
labelStyle: {
|
|
34
|
+
fontSize: 18,
|
|
35
|
+
fontWeight: "600",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
{
|
|
40
|
+
/**
|
|
41
|
+
* Input field
|
|
42
|
+
*/
|
|
22
43
|
type: "input",
|
|
23
44
|
label: "Name",
|
|
24
45
|
|
|
25
|
-
|
|
46
|
+
/**
|
|
47
|
+
* All TextInput behavior lives inside inputProps
|
|
48
|
+
*/
|
|
26
49
|
inputProps: {
|
|
27
50
|
placeholder: "Enter your name",
|
|
28
|
-
value: name,
|
|
29
|
-
onChangeText: setName
|
|
51
|
+
value: name,
|
|
52
|
+
onChangeText: setName,
|
|
30
53
|
},
|
|
31
54
|
},
|
|
32
55
|
|
|
33
56
|
{
|
|
34
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Button field
|
|
59
|
+
*/
|
|
35
60
|
type: "button",
|
|
36
61
|
label: "Submit",
|
|
37
62
|
|
|
38
|
-
|
|
63
|
+
/**
|
|
64
|
+
* All TouchableOpacity behavior lives inside buttonProps
|
|
65
|
+
*/
|
|
39
66
|
buttonProps: {
|
|
40
67
|
buttonText: "Submit",
|
|
41
68
|
onPress: () => {
|
|
42
|
-
// Access state directly
|
|
43
69
|
console.log("Name:", name);
|
|
44
70
|
},
|
|
45
71
|
},
|
|
@@ -50,9 +76,11 @@ export default function App() {
|
|
|
50
76
|
|
|
51
77
|
return (
|
|
52
78
|
<View style={{ padding: 16 }}>
|
|
53
|
-
{/*
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
{/*
|
|
80
|
+
✅ Form is just a renderer
|
|
81
|
+
- No internal state
|
|
82
|
+
- No validation
|
|
83
|
+
- No logic
|
|
56
84
|
*/}
|
|
57
85
|
<Form schema={formSchema} />
|
|
58
86
|
</View>
|
package/package.json
CHANGED