@hitesh0009/react-native-basic-form 1.2.8 โ 1.3.0
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 +282 -114
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
````md
|
|
2
|
+
# ๐ React Native Basic Form
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
### Control your entire form using JSON โ not JSX.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
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.
|
|
7
|
+
|
|
8
|
+
**React Native Basic Form solves this problem by turning forms into data.**
|
|
9
|
+
|
|
10
|
+
Instead of hardcoding inputs, buttons, and layouts, you describe your form using a **JSON schema**.
|
|
11
|
+
The renderer stays the same โ **only the JSON changes**.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## โ The Problem
|
|
16
|
+
|
|
17
|
+
- Forms are hardcoded with JSX
|
|
18
|
+
- Layout changes require code changes
|
|
19
|
+
- Reusing forms across screens is painful
|
|
20
|
+
- Dynamic or server-driven forms are difficult
|
|
21
|
+
- UI logic and form structure get tightly coupled
|
|
22
|
+
|
|
23
|
+
As a result, forms often become one of the **least maintainable parts** of an app.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## โ
The Solution
|
|
28
|
+
|
|
29
|
+
**React Native Basic Form** lets you control **everything about a form through JSON**:
|
|
30
|
+
|
|
31
|
+
- what fields exist
|
|
32
|
+
- how they are laid out
|
|
33
|
+
- how they behave
|
|
34
|
+
- how they look
|
|
35
|
+
|
|
36
|
+
Change the JSON โ the form changes.
|
|
37
|
+
No JSX rewrites. No duplicated components.
|
|
38
|
+
|
|
39
|
+
A **schema-driven, fully customizable form renderer for React Native**.
|
|
40
|
+
|
|
41
|
+
> This library does **not** manage form state, validation, or translations.
|
|
42
|
+
> It only renders what you describe.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## ๐ฏ Who This Is For
|
|
47
|
+
|
|
48
|
+
- Apps with many forms
|
|
49
|
+
- Admin panels or dashboards
|
|
50
|
+
- Server-driven or config-based UIs
|
|
51
|
+
- Teams that want consistent form behavior
|
|
52
|
+
- Developers who prefer data-driven UI
|
|
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,286 @@ 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**.
|
|
232
|
+
|
|
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 |
|
|
119
241
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `buttonContainerStyle` | Button container |
|
|
127
|
-
| `buttonTextStyle` | Button text |
|
|
128
|
-
| `headerIconStyle` | Header image |
|
|
129
|
-
| `headerTextStyle` | Header text |
|
|
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.
|
|
314
|
+
|
|
315
|
+
---
|
|
171
316
|
|
|
172
|
-
|
|
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
|
-
* Opinionated validation rules
|
|
178
|
-
* Forced UX decisions
|
|
323
|
+
It focuses on **rendering**, not logic.
|
|
179
324
|
|
|
180
|
-
|
|
325
|
+
---
|
|
326
|
+
|
|
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.
|
|
181
340
|
|
|
182
|
-
|
|
183
|
-
* Maximum control over behavior and styles
|
|
184
|
-
* Easy integration with your existing logic
|
|
341
|
+
Please keep PRs:
|
|
185
342
|
|
|
343
|
+
* simple
|
|
344
|
+
* schema-driven
|
|
345
|
+
* backward-compatible
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## ๐ License
|
|
350
|
+
|
|
351
|
+
MIT
|
|
352
|
+
|
|
353
|
+
```
|
|
186
354
|
|
package/package.json
CHANGED