@hitesh0009/react-native-basic-form 1.2.8 β 1.2.9
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 +280 -114
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# π React Native Basic Form
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### Control your entire form using JSON β not JSX.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Building forms in React Native usually means writing repetitive JSX, duplicating layouts, and touching UI code for every small change. As apps grow, forms become hard to maintain, hard to reuse, and hard to scale.
|
|
6
|
+
|
|
7
|
+
**React Native Basic Form solves this problem by turning forms into data.**
|
|
8
|
+
|
|
9
|
+
Instead of hardcoding inputs, buttons, and layouts, you describe your form using a **JSON schema**.
|
|
10
|
+
The renderer stays the same β **only the JSON changes**.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## β The Problem
|
|
15
|
+
|
|
16
|
+
- Forms are hardcoded with JSX
|
|
17
|
+
- Layout changes require code changes
|
|
18
|
+
- Reusing forms across screens is painful
|
|
19
|
+
- Dynamic or server-driven forms are difficult
|
|
20
|
+
- UI logic and form structure get tightly coupled
|
|
21
|
+
|
|
22
|
+
As a result, forms become one of the **least maintainable parts** of an app.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## β
The Solution
|
|
27
|
+
|
|
28
|
+
**React Native Basic Form** lets you control **everything about a form through JSON**:
|
|
29
|
+
|
|
30
|
+
- what fields exist
|
|
31
|
+
- how they are laid out
|
|
32
|
+
- how they behave
|
|
33
|
+
- how they look
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Change this JSONβ¦
|
|
37
|
+
{
|
|
38
|
+
type: 'input',
|
|
39
|
+
label: 'Phone Number'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// β¦and the UI updates automatically
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
A **schema-driven, fully customizable form renderer for React Native**.
|
|
47
|
+
|
|
48
|
+
This library allows you to build forms using a **JSON schema** instead of hardcoded JSX.
|
|
49
|
+
Layouts, inputs, and buttons are described declaratively and rendered consistently.
|
|
50
|
+
|
|
51
|
+
> This library does **not** manage form state, validation, or translations.
|
|
52
|
+
> It only renders what you describe.
|
|
6
53
|
|
|
7
54
|
---
|
|
8
55
|
|
|
9
56
|
## β¨ Features
|
|
10
57
|
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
58
|
+
* π§© **Schema-based rendering**
|
|
59
|
+
* π **Row / Column layouts**
|
|
60
|
+
* π¨ **Fully customizable styles**
|
|
61
|
+
* π§ **No internal state** (you control values & handlers)
|
|
62
|
+
* π **Language-agnostic** (i18n handled by user)
|
|
63
|
+
* π‘ **Type-safe** with TypeScript
|
|
64
|
+
* π§± **Easily extensible** (add new field types)
|
|
18
65
|
|
|
19
66
|
---
|
|
20
67
|
|
|
@@ -22,165 +69,284 @@ This library helps you render simple forms using a declarative data structure, w
|
|
|
22
69
|
|
|
23
70
|
```sh
|
|
24
71
|
npm install @hitesh0009/react-native-basic-form
|
|
25
|
-
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
or
|
|
75
|
+
|
|
76
|
+
```sh
|
|
26
77
|
yarn add @hitesh0009/react-native-basic-form
|
|
27
78
|
```
|
|
28
79
|
|
|
29
80
|
---
|
|
30
81
|
|
|
31
|
-
## π
|
|
82
|
+
## π Quick Start
|
|
83
|
+
|
|
84
|
+
### 1οΈβ£ Import the `Form` component
|
|
32
85
|
|
|
33
86
|
```tsx
|
|
34
87
|
import { Form } from '@hitesh0009/react-native-basic-form';
|
|
88
|
+
```
|
|
35
89
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
onChangeText: setName,
|
|
43
|
-
placeholder: 'Enter your full name',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: '2',
|
|
48
|
-
label: 'Phone Number',
|
|
49
|
-
input: {
|
|
50
|
-
value: phone,
|
|
51
|
-
onChangeText: setPhone,
|
|
52
|
-
placeholder: 'Enter phone number',
|
|
53
|
-
keyboardType: 'numeric',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### 2οΈβ£ Create a schema
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const formSchema = [
|
|
56
96
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
97
|
+
layout: 'column',
|
|
98
|
+
spacing: 20,
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
type: 'input',
|
|
102
|
+
label: 'Contact Person Name',
|
|
103
|
+
inputProps: {
|
|
104
|
+
placeholder: "Enter contact person's full name",
|
|
105
|
+
onChangeText: text => console.log(text),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'input',
|
|
110
|
+
label: 'Phone Number',
|
|
111
|
+
inputProps: {
|
|
112
|
+
placeholder: '+91 Enter phone number',
|
|
113
|
+
keyboardType: 'phone-pad',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: 'button',
|
|
118
|
+
label: 'Save',
|
|
119
|
+
buttonProps: {
|
|
120
|
+
buttonText: 'Save',
|
|
121
|
+
onPress: () => console.log('Submitted'),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
62
125
|
},
|
|
63
126
|
];
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### 3οΈβ£ Render the form
|
|
64
132
|
|
|
65
|
-
|
|
133
|
+
```tsx
|
|
134
|
+
<Form schema={formSchema} />
|
|
66
135
|
```
|
|
67
136
|
|
|
137
|
+
Thatβs it.
|
|
138
|
+
|
|
68
139
|
---
|
|
69
140
|
|
|
70
|
-
##
|
|
141
|
+
## π§ Core Concepts
|
|
142
|
+
|
|
143
|
+
### 1. Schema-Driven UI
|
|
144
|
+
|
|
145
|
+
You describe **what** the UI should look like:
|
|
71
146
|
|
|
72
147
|
```ts
|
|
73
|
-
|
|
148
|
+
{
|
|
149
|
+
type: 'input',
|
|
150
|
+
label: 'Name'
|
|
151
|
+
}
|
|
152
|
+
```
|
|
74
153
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
};
|
|
154
|
+
The form renderer handles **how** it is rendered.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### 2. Layout Blocks
|
|
159
|
+
|
|
160
|
+
Each schema block controls layout only.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
{
|
|
164
|
+
layout: 'row',
|
|
165
|
+
spacing: 12,
|
|
166
|
+
children: [...]
|
|
167
|
+
}
|
|
91
168
|
```
|
|
92
169
|
|
|
170
|
+
Supported layouts:
|
|
171
|
+
|
|
172
|
+
* `column`
|
|
173
|
+
* `row`
|
|
174
|
+
|
|
93
175
|
---
|
|
94
176
|
|
|
95
|
-
|
|
177
|
+
### 3. Fields
|
|
96
178
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
179
|
+
Each `child` inside a block is a **field**.
|
|
180
|
+
|
|
181
|
+
Supported field types:
|
|
182
|
+
|
|
183
|
+
* `input`
|
|
184
|
+
* `button`
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## π§© Field Types
|
|
189
|
+
|
|
190
|
+
### πΉ Input Field
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
{
|
|
194
|
+
type: 'input',
|
|
195
|
+
label: 'Age',
|
|
196
|
+
spacing: 8,
|
|
197
|
+
inputProps: {
|
|
198
|
+
placeholder: 'Enter age',
|
|
199
|
+
keyboardType: 'numeric',
|
|
200
|
+
onChangeText: text => console.log(text),
|
|
201
|
+
},
|
|
202
|
+
}
|
|
102
203
|
```
|
|
103
204
|
|
|
205
|
+
All standard **React Native `TextInputProps`** are supported via `inputProps`.
|
|
206
|
+
|
|
104
207
|
---
|
|
105
208
|
|
|
106
|
-
|
|
209
|
+
### πΉ Button Field
|
|
107
210
|
|
|
108
|
-
|
|
211
|
+
```ts
|
|
212
|
+
{
|
|
213
|
+
type: 'button',
|
|
214
|
+
label: 'Submit',
|
|
215
|
+
spacing: 12,
|
|
216
|
+
style: { backgroundColor: '#2563eb' },
|
|
217
|
+
textStyle: { fontSize: 16 },
|
|
218
|
+
buttonProps: {
|
|
219
|
+
buttonText: 'Submit',
|
|
220
|
+
onPress: () => console.log('Pressed'),
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
```
|
|
109
224
|
|
|
110
|
-
|
|
111
|
-
| ------------------ | ------------ | ----------------------------------------- |
|
|
112
|
-
| `data` | `FormItem[]` | Required form definition |
|
|
113
|
-
| `gap_bwt_keyValue` | `number` | Gap between label and input (default: 10) |
|
|
114
|
-
| `gap_bwt_keys` | `number` | Gap between form rows (default: 12) |
|
|
225
|
+
All standard **`TouchableOpacity` behavior** is supported via `buttonProps`.
|
|
115
226
|
|
|
116
227
|
---
|
|
117
228
|
|
|
118
|
-
|
|
229
|
+
## π¨ Styling & Spacing
|
|
230
|
+
|
|
231
|
+
Styling is **fully user-controlled**.
|
|
119
232
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
|
|
129
|
-
|
|
233
|
+
### Field-level props
|
|
234
|
+
|
|
235
|
+
| Prop | Description |
|
|
236
|
+
| ------------ | ---------------------------------------- |
|
|
237
|
+
| `style` | Container style |
|
|
238
|
+
| `textStyle` | Button text style |
|
|
239
|
+
| `labelStyle` | Label text style |
|
|
240
|
+
| `spacing` | Vertical spacing between label and field |
|
|
241
|
+
|
|
242
|
+
### Block-level props
|
|
243
|
+
|
|
244
|
+
| Prop | Description |
|
|
245
|
+
| --------- | -------------------- |
|
|
246
|
+
| `layout` | `row` or `column` |
|
|
247
|
+
| `spacing` | Space between fields |
|
|
130
248
|
|
|
131
249
|
---
|
|
132
250
|
|
|
133
|
-
##
|
|
251
|
+
## π Internationalization (i18n)
|
|
134
252
|
|
|
135
|
-
|
|
253
|
+
This library is **language-agnostic**.
|
|
136
254
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
showsVerticalScrollIndicator: false,
|
|
142
|
-
contentContainerStyle: { paddingBottom: 40 },
|
|
143
|
-
}}
|
|
144
|
-
/>
|
|
255
|
+
You can pass translated strings directly:
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
label: t('contact_name')
|
|
145
259
|
```
|
|
146
260
|
|
|
147
|
-
|
|
261
|
+
No translation logic is included.
|
|
148
262
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## π§± TypeScript Support
|
|
266
|
+
|
|
267
|
+
The library exposes a **strict schema contract**.
|
|
268
|
+
|
|
269
|
+
### Types Overview
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
export type FormField = FormInput | FormButton;
|
|
273
|
+
|
|
274
|
+
export type FormItem = {
|
|
275
|
+
layout?: 'row' | 'column';
|
|
276
|
+
spacing?: number;
|
|
277
|
+
children: FormField[];
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export type FormProps = {
|
|
281
|
+
schema: FormItem[];
|
|
282
|
+
};
|
|
156
283
|
```
|
|
157
284
|
|
|
285
|
+
TypeScript will:
|
|
286
|
+
|
|
287
|
+
* prevent invalid schemas
|
|
288
|
+
* autocomplete valid props
|
|
289
|
+
* catch mistakes at compile time
|
|
290
|
+
|
|
158
291
|
---
|
|
159
292
|
|
|
160
|
-
##
|
|
293
|
+
## π§ Design Philosophy
|
|
294
|
+
|
|
295
|
+
* β No internal form state
|
|
296
|
+
* β No validation logic
|
|
297
|
+
* β No opinionated UI
|
|
298
|
+
* β
You control values & handlers
|
|
299
|
+
* β
Schema is the single source of truth
|
|
161
300
|
|
|
162
|
-
|
|
163
|
-
* All inputs are fully controlled
|
|
164
|
-
* Validation and submission logic are your responsibility
|
|
165
|
-
* `id` must always be a string
|
|
166
|
-
* Avoid nesting inside `ScrollView` unless scrolling is disabled via `flatlistProps`
|
|
301
|
+
> **This library is a render engine, not a form framework.**
|
|
167
302
|
|
|
168
303
|
---
|
|
169
304
|
|
|
170
|
-
##
|
|
305
|
+
## π§ Extending the Form
|
|
306
|
+
|
|
307
|
+
To add new field types (e.g. `text`, `checkbox`, `select`):
|
|
308
|
+
|
|
309
|
+
1. Extend the schema type
|
|
310
|
+
2. Add a case in the renderer
|
|
311
|
+
3. Plug in your component
|
|
312
|
+
|
|
313
|
+
No breaking changes required.
|
|
171
314
|
|
|
172
|
-
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## π§ͺ What This Library Is NOT
|
|
173
318
|
|
|
174
|
-
|
|
319
|
+
* β Not a validation framework
|
|
320
|
+
* β Not a form state manager
|
|
321
|
+
* β Not a UI kit
|
|
175
322
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
323
|
+
It focuses on **rendering**, not logic.
|
|
324
|
+
|
|
325
|
+
---
|
|
179
326
|
|
|
180
|
-
|
|
327
|
+
## π£ Roadmap (Optional)
|
|
328
|
+
|
|
329
|
+
* Conditional rendering
|
|
330
|
+
* Repeatable field groups
|
|
331
|
+
* Grid layouts
|
|
332
|
+
* Validation helpers
|
|
333
|
+
* Visual form builder
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## π€ Contributing
|
|
338
|
+
|
|
339
|
+
Contributions are welcome.
|
|
340
|
+
|
|
341
|
+
Please keep PRs:
|
|
342
|
+
|
|
343
|
+
* simple
|
|
344
|
+
* schema-driven
|
|
345
|
+
* backward-compatible
|
|
346
|
+
|
|
347
|
+
---
|
|
181
348
|
|
|
182
|
-
|
|
183
|
-
* Maximum control over behavior and styles
|
|
184
|
-
* Easy integration with your existing logic
|
|
349
|
+
## π License
|
|
185
350
|
|
|
351
|
+
MIT
|
|
186
352
|
|
package/package.json
CHANGED