config-driven-form 1.1.2 → 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 CHANGED
@@ -16,6 +16,7 @@ Stop writing thousands of lines of boilerplate form code. Define your data struc
16
16
  - 🎨 **Beautiful by Default:** Includes a stunning, modern glassmorphic design system out of the box.
17
17
  - 🏗️ **Multi-Column Layouts:** Easily build complex 2, 3, or 4-column grid layouts using the `uiSchema`.
18
18
  - 🧩 **Rich Field Types:** Natively supports Text, Numbers, Passwords, Dropdowns, Radios, Checkboxes, File Uploads, and a Tiptap Rich Text Editor!
19
+ - 🏗️ **Visual Form Builder:** Includes a powerful, Strapi-like Drag-and-Drop builder to visually construct schemas and UI schemas without writing code!
19
20
 
20
21
  ---
21
22
 
@@ -139,6 +140,90 @@ export default function AdvancedForm() {
139
140
 
140
141
  ---
141
142
 
143
+ ## 🎨 Deep Customization with Tailwind CSS (New!)
144
+
145
+ If you want to use **Tailwind CSS** (or any other class-based framework) to completely reskin the form, `config-driven-form` exposes a deeply nested `classNames` API.
146
+
147
+ This is a zero-dependency, standard headless UI approach. You can pass global classes via the `classNames` prop on `<SchemaForm>`, and even override specific individual fields using `ui:classNames` in your `uiSchema`!
148
+
149
+ ```tsx
150
+ import React from 'react';
151
+ import { SchemaForm, JSONSchema } from 'config-driven-form';
152
+ // Note: You can skip importing the default CSS if you want pure Tailwind styling
153
+
154
+ const schema: JSONSchema = {
155
+ type: 'object',
156
+ properties: {
157
+ email: { type: 'string', format: 'email', title: 'Email Address' },
158
+ },
159
+ };
160
+
161
+ export default function TailwindForm() {
162
+ return (
163
+ <SchemaForm
164
+ schema={schema}
165
+ classNames={{
166
+ container: 'max-w-xl mx-auto p-6 bg-white rounded-xl shadow-md',
167
+ label: 'block text-sm font-medium text-gray-700 mb-1',
168
+ input:
169
+ 'w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500',
170
+ submitButton: 'w-full bg-blue-600 text-white py-2 rounded-md hover:bg-blue-700 transition',
171
+ }}
172
+ // You can override specific fields!
173
+ uiSchema={{
174
+ email: {
175
+ 'ui:classNames': {
176
+ input: 'border-red-500 bg-red-50', // e.g. force error state styling statically
177
+ },
178
+ },
179
+ }}
180
+ onSubmit={(data) => console.log(data)}
181
+ />
182
+ );
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## 🏗️ Visual Form Builder (New!)
189
+
190
+ Tired of writing JSON by hand? We've built a world-class, **Drag-and-Drop Visual Form Builder** directly into the library!
191
+
192
+ You can embed this builder into your own admin panels, let users visually construct their forms, set validation rules, pick themes, and then save the output as standard `JSONSchema` to store in your database!
193
+
194
+ ```tsx
195
+ import React from 'react';
196
+ import { FormBuilder } from 'config-driven-form';
197
+ import 'config-driven-form/dist/index.css';
198
+
199
+ export default function AdminFormBuilder() {
200
+ return (
201
+ <div style={{ height: '100vh', width: '100vw' }}>
202
+ <FormBuilder
203
+ // Optional: Pass existing schemas to edit them!
204
+ // initialSchema={existingSchema}
205
+ // initialUiSchema={existingUiSchema}
206
+ onSave={(schema, uiSchema, formSettings) => {
207
+ console.log('Generated Schema:', schema);
208
+ console.log('Generated UI Schema:', uiSchema);
209
+ console.log('Global Form Settings:', formSettings);
210
+
211
+ // Save to your database here!
212
+ }}
213
+ />
214
+ </div>
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### Builder Features:
220
+
221
+ - **Drag & Drop Canvas:** Powered by `@dnd-kit` for buttery smooth reordering.
222
+ - **Live Preview Mode:** Toggle between Editor and Preview mode to test validation instantly.
223
+ - **Global Theme & Layout Controls:** Let your users pick their brand colors and column layouts visually.
224
+
225
+ ---
226
+
142
227
  ## 📚 Supported Field Types
143
228
 
144
229
  The library automatically inspects the `type`, `format`, and `enum` properties of your JSON Schema to render the correct UI component:
@@ -166,13 +251,14 @@ The library automatically inspects the `type`, `format`, and `enum` properties o
166
251
  | :-------------- | :------------------------- | :------: | :-------------------------------------------------------------------------------------- |
167
252
  | `schema` | `JSONSchema` | Yes | The standard JSON Schema defining your data. |
168
253
  | `onSubmit` | `(data: any) => void` | Yes | Callback function triggered when the form is valid and submitted. |
169
- | `uiSchema` | `Record<string, UISchema>` | No | Controls UI-specific rendering (widgets, column spans) without altering data structure. |
254
+ | `uiSchema` | `Record<string, UISchema>` | No | Controls UI-specific rendering (widgets, column spans, field-level classNames). |
170
255
  | `columns` | `1 \| 2 \| 3 \| 4` | No | Defines the global CSS Grid columns for the form layout. Default: `1`. |
171
256
  | `theme` | `Object` | No | An object to override CSS variables (`primary`, `background`, `text`, `error`, etc.). |
257
+ | `classNames` | `FormClassNames` | No | An object mapping internal elements to custom CSS classes (e.g., Tailwind CSS support). |
172
258
  | `defaultValues` | `Object` | No | Initial data to populate the form fields before rendering. |
173
259
 
174
260
  ---
175
261
 
176
262
  ## 🤝 Contributing
177
263
 
178
- We welcome contributions! If you want to fix a bug, add a new field type, or improve the documentation, please read our [Developer's Guide (CONTRIBUTING.md)](./CONTRIBUTING.md) to get started with your local development environment.
264
+ We welcome contributions! If you want to fix a bug, add a new field type, or improve the documentation, please read our [Developer's Guide (CONTRIBUTING.md)](https://github.com/Aaditya-Rana/config-driven-form/blob/main/CONTRIBUTING.md) to get started with your local development environment.
package/dist/index.d.mts CHANGED
@@ -18,9 +18,30 @@ interface JSONSchema {
18
18
  items?: JSONSchema | JSONSchema[];
19
19
  default?: any;
20
20
  }
21
+ interface FormClassNames {
22
+ container?: string;
23
+ title?: string;
24
+ description?: string;
25
+ form?: string;
26
+ fieldGroup?: string;
27
+ label?: string;
28
+ input?: string;
29
+ inputError?: string;
30
+ errorText?: string;
31
+ submitButton?: string;
32
+ radioGroup?: string;
33
+ radioLabel?: string;
34
+ radioInput?: string;
35
+ checkboxGroup?: string;
36
+ checkboxLabel?: string;
37
+ checkboxInput?: string;
38
+ fileWrapper?: string;
39
+ fileText?: string;
40
+ }
21
41
  interface UISchema {
22
42
  'ui:widget'?: 'radio' | 'checkboxes' | 'textarea' | 'color' | string;
23
43
  'ui:columnSpan'?: number;
44
+ 'ui:classNames'?: FormClassNames;
24
45
  [key: string]: any;
25
46
  }
26
47
 
@@ -38,6 +59,7 @@ interface SchemaFormProps {
38
59
  surface?: string;
39
60
  border?: string;
40
61
  };
62
+ classNames?: FormClassNames;
41
63
  }
42
64
  declare const SchemaForm: React.FC<SchemaFormProps>;
43
65
 
@@ -49,4 +71,23 @@ interface FieldRendererProps {
49
71
  }
50
72
  declare const FieldRenderer: React.FC<FieldRendererProps>;
51
73
 
52
- export { type FieldFormat, FieldRenderer, type FieldType, type JSONSchema, SchemaForm, type UISchema };
74
+ interface FormSettings {
75
+ columns: 1 | 2 | 3 | 4;
76
+ theme: {
77
+ primary?: string;
78
+ background?: string;
79
+ text?: string;
80
+ error?: string;
81
+ };
82
+ }
83
+
84
+ interface FormBuilderProps {
85
+ initialSchema?: JSONSchema;
86
+ initialUiSchema?: Record<string, UISchema>;
87
+ initialColumns?: 1 | 2 | 3 | 4;
88
+ initialTheme?: FormSettings['theme'];
89
+ onSave?: (schema: JSONSchema, uiSchema: Record<string, UISchema>, formSettings: FormSettings) => void;
90
+ }
91
+ declare const FormBuilder: React.FC<FormBuilderProps>;
92
+
93
+ export { type FieldFormat, FieldRenderer, type FieldType, FormBuilder, type FormClassNames, type JSONSchema, SchemaForm, type UISchema };
package/dist/index.d.ts CHANGED
@@ -18,9 +18,30 @@ interface JSONSchema {
18
18
  items?: JSONSchema | JSONSchema[];
19
19
  default?: any;
20
20
  }
21
+ interface FormClassNames {
22
+ container?: string;
23
+ title?: string;
24
+ description?: string;
25
+ form?: string;
26
+ fieldGroup?: string;
27
+ label?: string;
28
+ input?: string;
29
+ inputError?: string;
30
+ errorText?: string;
31
+ submitButton?: string;
32
+ radioGroup?: string;
33
+ radioLabel?: string;
34
+ radioInput?: string;
35
+ checkboxGroup?: string;
36
+ checkboxLabel?: string;
37
+ checkboxInput?: string;
38
+ fileWrapper?: string;
39
+ fileText?: string;
40
+ }
21
41
  interface UISchema {
22
42
  'ui:widget'?: 'radio' | 'checkboxes' | 'textarea' | 'color' | string;
23
43
  'ui:columnSpan'?: number;
44
+ 'ui:classNames'?: FormClassNames;
24
45
  [key: string]: any;
25
46
  }
26
47
 
@@ -38,6 +59,7 @@ interface SchemaFormProps {
38
59
  surface?: string;
39
60
  border?: string;
40
61
  };
62
+ classNames?: FormClassNames;
41
63
  }
42
64
  declare const SchemaForm: React.FC<SchemaFormProps>;
43
65
 
@@ -49,4 +71,23 @@ interface FieldRendererProps {
49
71
  }
50
72
  declare const FieldRenderer: React.FC<FieldRendererProps>;
51
73
 
52
- export { type FieldFormat, FieldRenderer, type FieldType, type JSONSchema, SchemaForm, type UISchema };
74
+ interface FormSettings {
75
+ columns: 1 | 2 | 3 | 4;
76
+ theme: {
77
+ primary?: string;
78
+ background?: string;
79
+ text?: string;
80
+ error?: string;
81
+ };
82
+ }
83
+
84
+ interface FormBuilderProps {
85
+ initialSchema?: JSONSchema;
86
+ initialUiSchema?: Record<string, UISchema>;
87
+ initialColumns?: 1 | 2 | 3 | 4;
88
+ initialTheme?: FormSettings['theme'];
89
+ onSave?: (schema: JSONSchema, uiSchema: Record<string, UISchema>, formSettings: FormSettings) => void;
90
+ }
91
+ declare const FormBuilder: React.FC<FormBuilderProps>;
92
+
93
+ export { type FieldFormat, FieldRenderer, type FieldType, FormBuilder, type FormClassNames, type JSONSchema, SchemaForm, type UISchema };