@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.
Files changed (2) hide show
  1. package/README.md +280 -114
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,67 @@
1
- # react-native-basic-form
1
+ # πŸš€ React Native Basic Form
2
2
 
3
- A lightweight, data-driven form renderer for React Native with fully controlled inputs and flexible styling.
3
+ ### Control your entire form using JSON β€” not JSX.
4
4
 
5
- This library helps you render simple forms using a declarative data structure, without managing internal state or enforcing opinions about validation or submission.
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
- * πŸ“¦ No native code (JS-only)
12
- * πŸŽ› Fully controlled inputs
13
- * 🧩 Data-driven rendering
14
- * 🎨 Flexible style overrides
15
- * 🧠 Unopinionated & extendable
16
- * ⚑ Rendered using `FlatList` for performance
17
- * 🧰 Pass-through props for `FlatList`, `TextInput`, `Text`, and `Image`
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
- # or
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
- ## πŸš€ Basic Usage
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
- const data = [
37
- {
38
- id: '1',
39
- label: 'Full Name',
40
- input: {
41
- value: name,
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
- id: '3',
58
- button: {
59
- label: 'Submit',
60
- onPress: handleSubmit,
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
- <Form data={data} />;
133
+ ```tsx
134
+ <Form schema={formSchema} />
66
135
  ```
67
136
 
137
+ That’s it.
138
+
68
139
  ---
69
140
 
70
- ## 🧩 Data Structure
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
- import type { KeyboardType } from 'react-native';
148
+ {
149
+ type: 'input',
150
+ label: 'Name'
151
+ }
152
+ ```
74
153
 
75
- export type FormItem = {
76
- id: string; // must be unique
77
- label?: string;
78
- input?: {
79
- value: string;
80
- onChangeText: (text: string) => void;
81
- placeholder?: string;
82
- keyboardType?: KeyboardType;
83
- multiline?: boolean;
84
- textAlignVertical?: 'auto' | 'top' | 'center' | 'bottom';
85
- };
86
- button?: {
87
- label: string;
88
- onPress: () => void;
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
- ## 🧠 Header Support (Optional)
177
+ ### 3. Fields
96
178
 
97
- ```tsx
98
- <Form
99
- headerIcon={Images.user}
100
- headerText="Contact Information"
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
- ## 🧰 Props Reference
209
+ ### πŸ”Ή Button Field
107
210
 
108
- ### Core Props
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
- | Prop | Type | Description |
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
- ### Style Props
229
+ ## 🎨 Styling & Spacing
230
+
231
+ Styling is **fully user-controlled**.
119
232
 
120
- | Prop | Applies To |
121
- | ---------------------- | ---------------- |
122
- | `containerStyle` | Root container |
123
- | `headerContainerStyle` | Header wrapper |
124
- | `labelStyle` | Label text |
125
- | `inputTextStyle` | TextInput |
126
- | `buttonContainerStyle` | Button container |
127
- | `buttonTextStyle` | Button text |
128
- | `headerIconStyle` | Header image |
129
- | `headerTextStyle` | Header text |
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
- ## πŸ”Œ Pass-through Props (Advanced)
251
+ ## 🌍 Internationalization (i18n)
134
252
 
135
- ### `flatlistProps`
253
+ This library is **language-agnostic**.
136
254
 
137
- ```tsx
138
- <Form
139
- flatlistProps={{
140
- scrollEnabled: false,
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
- ### `textInputProps`
261
+ No translation logic is included.
148
262
 
149
- ```tsx
150
- <Form
151
- textInputProps={{
152
- autoCapitalize: 'none',
153
- returnKeyType: 'done',
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
- ## ⚠️ Important Notes
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
- * This library does not manage state
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
- ## 🧠 Design Philosophy
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
- Forms should be declarative, flexible, and boring.
315
+ ---
316
+
317
+ ## πŸ§ͺ What This Library Is NOT
173
318
 
174
- This library intentionally avoids:
319
+ * ❌ Not a validation framework
320
+ * ❌ Not a form state manager
321
+ * ❌ Not a UI kit
175
322
 
176
- * Hidden internal state
177
- * Opinionated validation rules
178
- * Forced UX decisions
323
+ It focuses on **rendering**, not logic.
324
+
325
+ ---
179
326
 
180
- Instead, it provides:
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
- * A predictable rendering layer
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitesh0009/react-native-basic-form",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "A lightweight, data-driven form renderer for React Native with fully controlled inputs and flexible styling.",
5
5
  "keywords": [
6
6
  "react-native",