react-form-dto 0.0.5 → 0.0.6

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 +111 -51
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,41 +1,49 @@
1
1
  # React Form DTO
2
2
 
3
- A **dynamic, DTO-driven form builder** built with **React, TypeScript, and Material UI (MUI v7)**.
4
- This library lets you define forms declaratively using JSON DTOs (`FormDTO`, `SectionDTO`, `FieldDTO`) and automatically renders responsive, accessible forms with MUI components.
3
+ **Schema-first, DTO-driven form builder for React and Material UI (MUI v7)**
4
+
5
+ React Form DTO helps you build complex, responsive, and accessible forms using declarative JSON/TypeScript DTOs instead of verbose JSX. It is designed for enterprise-grade applications, internal tools, admin panels, and workflows where forms are dynamic, configurable, and data-driven.
5
6
 
6
7
  ---
7
8
 
8
- ## Features
9
+ ## Why React Form DTO?
9
10
 
10
- - **DTO-driven**: Define forms entirely in JSON/TypeScript objects.
11
- - **Material UI integration**: Uses MUI v7 components for consistent design and accessibility.
12
- - **Responsive grid layout**: 12-column system mapped to MUI’s `Grid` with `size` props.
13
- - **Conditional rendering**: Show/hide fields or sections based on other field values.
14
- - **Custom renderers**: Override default MUI inputs with your own components.
15
- - **TypeScript support**: Strongly typed DTOs for safety and autocompletion.
16
- - **Composable architecture**: `FormBuilder`, `Section`, and `Field` components.
17
- - **Built-in validation**: Use `useFormBuilder` hook and validation utilities for field and form validation.
11
+ Most form libraries focus on low-level state management. React Form DTO operates at a **higher abstraction level**.
18
12
 
19
- ---
13
+ **Use this library when:**
20
14
 
21
- 📘 Documentation
15
+ - Your forms are generated from backend schemas or configurations
16
+ - You want to avoid duplicating UI logic across applications
17
+ - You need imperative control over form state (wizards, modals, async flows)
18
+ - Your project is built on Material UI
22
19
 
23
- Comprehensive documentation is available here
20
+ **Key advantages:**
24
21
 
25
- 👉 [Documentation](https://shakir-afridi.github.io/react-form-dto/docs)
22
+ - 📄 **DTO-first design** – define forms entirely in JSON or TypeScript
23
+ - 🎨 **Material UI v7 native** – consistent design & accessibility
24
+ - 🧱 **Composable architecture** – Form → Section → Field
25
+ - 🎯 **Imperative API** – programmatic access via refs
26
+ - 🔀 **Conditional rendering** – show/hide fields dynamically
27
+ - 🧩 **Custom renderers** – plug in your own components
28
+ - 🛡️ **Strong TypeScript typing** – predictable, safe APIs
26
29
 
27
30
  ---
28
31
 
29
- ## 📘 Storybook
32
+ ## How It Compares
30
33
 
31
- Explore it interactively on Storybook:
32
- 👉 [Live Demo](https://shakir-afridi.github.io/react-form-dto/storybook)
34
+ | Feature | React Form DTO | React Hook Form | Formik |
35
+ |------|---------------|----------------|--------|
36
+ | Schema/DTO driven | ✅ Native | ❌ Manual | ❌ Manual |
37
+ | MUI-first | ✅ Yes | ⚠️ Partial | ⚠️ Partial |
38
+ | Imperative API | ✅ First-class | ⚠️ Limited | ⚠️ Limited |
39
+ | Large dynamic forms | ✅ Excellent | ⚠️ Medium | ❌ Poor |
40
+ | Boilerplate | ✅ Minimal | ❌ High | ❌ High |
33
41
 
34
- ---
42
+ > React Form DTO is **not a replacement** for React Hook Form. It is a higher-level abstraction for schema-driven UI generation.
35
43
 
36
- ## 📦 Installation
44
+ ---
37
45
 
38
- Clone the repo and install dependencies:
46
+ ## Installation
39
47
 
40
48
  ```bash
41
49
  git clone https://github.com/Shakir-Afridi/react-form-dto.git
@@ -43,16 +51,15 @@ cd react-form-dto
43
51
  npm install
44
52
  ```
45
53
 
46
- > **Requirements:**
47
- > - Node.js >= 18
48
- > - React >= 19
49
- > - Material UI >= 7
54
+ ### Requirements
50
55
 
51
- ---
56
+ - Node.js >= 18
57
+ - React >= 19
58
+ - Material UI >= 7
52
59
 
53
- ## 🏗️ Usage
60
+ ---
54
61
 
55
- Import and use the form builder in your React app:
62
+ ## Minimal Example
56
63
 
57
64
  ```tsx
58
65
  import { FormBuilder, type FormBuilderHandle } from 'react-form-dto';
@@ -79,11 +86,9 @@ return (
79
86
  );
80
87
  ```
81
88
 
82
- Refer to the documentation and examples for DTO structure and customization.
83
-
84
89
  ---
85
90
 
86
- ### 📋 Example
91
+ ## 📋 Example Form rendered
87
92
 
88
93
  ![Form Example](./example.png)
89
94
 
@@ -187,28 +192,50 @@ const profileForm: FormDTO = {
187
192
 
188
193
  ---
189
194
 
190
- ### Supported Field Types & Renderers
195
+ ## Supported Field Types
191
196
 
192
- - **TextInput**: text, number, date
193
- - **SelectInput**: select/dropdown
194
- - **CheckBoxInput**: boolean/checkbox
195
- - **AutoCompleteField**: single autocomplete
196
- - **MultiAutoCompleteField**: multi-select autocomplete
197
+ ### Text Inputs
197
198
 
198
- You can provide a custom renderer for any field via the DTO:
199
+ - `text`
200
+ - `number`
201
+ - `date`
202
+ - `email`
203
+ - `password`
199
204
 
200
- ```tsx
205
+ ### Selection Inputs
206
+
207
+ - `select`
208
+ - `autocomplete`
209
+ - `multi-autocomplete`
210
+
211
+ ### Boolean Inputs
212
+
213
+ - `checkbox`
214
+
215
+ ---
216
+
217
+ ## Custom Field Renderers
218
+
219
+ Override any default renderer by supplying your own component:
220
+
221
+ ```ts
201
222
  {
202
- // ...existing field DTO...
203
- renderer: MyCustomComponent
223
+ id: "salary",
224
+ type: "number",
225
+ label: "Salary",
226
+ renderer: CurrencyInput
204
227
  }
205
228
  ```
206
229
 
207
- ### Validation
230
+ This makes the library extensible without modifying core logic.
231
+
232
+ ---
208
233
 
209
- The `useFormBuilder` hook provides the following API for managing form state and validation:
234
+ ## Validation API
210
235
 
211
- ```tsx
236
+ Validation is handled through the `useFormBuilder` hook and the imperative form handle.
237
+
238
+ ```ts
212
239
  const {
213
240
  handleChange, // Function to update a field value: (id, value) => void
214
241
  validateAll, // Function to validate all fields: () => Record<string, string[]>
@@ -218,13 +245,42 @@ const {
218
245
  } = useFormBuilder(myFormDTO);
219
246
  ```
220
247
 
221
- - `handleChange(id, value)`: Update a field value.
222
- - `validateAll()`: Validate all fields and return errors.
223
- - `validateField(id)`: Validate a specific field and return errors for that field.
224
- - `getValues()`: Get all form values.
225
- - `getErrors()`: Get all form errors.
248
+ ### Validation Rules
249
+
250
+ ```ts
251
+ validations: {
252
+ required: "This field is required",
253
+ validate: (value) => value.length < 2 ? "Minimum 2 characters" : null
254
+ }
255
+ ```
256
+
257
+ > Recommendation: Standardize validation return values to `string[]` for predictable handling in large applications.
226
258
 
227
- Refer to the documentation and examples for DTO structure and customization.
259
+ ---
260
+
261
+ ## Documentation & Demo
262
+
263
+ - 📘 **Documentation:** See full DTO reference, APIs, and advanced examples [Documentation](https://shakir-afridi.github.io/react-form-dto/docs)
264
+ - 📗 **Storybook:** Interactive component playground and live demos [Live Demo](https://shakir-afridi.github.io/react-form-dto/storybook)
265
+
266
+ ---
267
+
268
+ ## Ideal Use Cases
269
+
270
+ - Admin dashboards
271
+ - Internal enterprise tools
272
+ - Multi-step onboarding flows
273
+ - Config-driven forms from APIs
274
+ - Rapid UI scaffolding for MUI projects
275
+
276
+ ---
277
+
278
+ ## Roadmap (Suggested)
279
+
280
+ - Field registry API (`registerFieldType`)
281
+ - Async validation support
282
+ - Form-level conditional logic
283
+ - Schema import (JSON Schema / OpenAPI)
228
284
 
229
285
  ---
230
286
 
@@ -240,4 +296,8 @@ Refer to the documentation and examples for DTO structure and customization.
240
296
 
241
297
  ## 📜 License
242
298
 
243
- MIT License © 2025 Shakir Ullah
299
+ MIT
300
+
301
+ ---
302
+
303
+ **React Form DTO — Schema-first forms for Material UI**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-form-dto",
3
3
  "description": "A React library for building forms using DTOs with MUI and TypeScript.",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "main": "dist/react-form-dto.umd.js",
6
6
  "module": "dist/react-form-dto.es.js",
7
7
  "types": "dist/index.d.ts",