config-driven-form 1.1.2 → 1.2.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 +47 -1
- package/dist/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +318 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +318 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,51 @@ export default function AdvancedForm() {
|
|
|
139
139
|
|
|
140
140
|
---
|
|
141
141
|
|
|
142
|
+
## 🎨 Deep Customization with Tailwind CSS (New!)
|
|
143
|
+
|
|
144
|
+
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.
|
|
145
|
+
|
|
146
|
+
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`!
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import React from 'react';
|
|
150
|
+
import { SchemaForm, JSONSchema } from 'config-driven-form';
|
|
151
|
+
// Note: You can skip importing the default CSS if you want pure Tailwind styling
|
|
152
|
+
|
|
153
|
+
const schema: JSONSchema = {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
email: { type: 'string', format: 'email', title: 'Email Address' },
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export default function TailwindForm() {
|
|
161
|
+
return (
|
|
162
|
+
<SchemaForm
|
|
163
|
+
schema={schema}
|
|
164
|
+
classNames={{
|
|
165
|
+
container: 'max-w-xl mx-auto p-6 bg-white rounded-xl shadow-md',
|
|
166
|
+
label: 'block text-sm font-medium text-gray-700 mb-1',
|
|
167
|
+
input:
|
|
168
|
+
'w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500',
|
|
169
|
+
submitButton: 'w-full bg-blue-600 text-white py-2 rounded-md hover:bg-blue-700 transition',
|
|
170
|
+
}}
|
|
171
|
+
// You can override specific fields!
|
|
172
|
+
uiSchema={{
|
|
173
|
+
email: {
|
|
174
|
+
'ui:classNames': {
|
|
175
|
+
input: 'border-red-500 bg-red-50', // e.g. force error state styling statically
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}}
|
|
179
|
+
onSubmit={(data) => console.log(data)}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
142
187
|
## 📚 Supported Field Types
|
|
143
188
|
|
|
144
189
|
The library automatically inspects the `type`, `format`, and `enum` properties of your JSON Schema to render the correct UI component:
|
|
@@ -166,9 +211,10 @@ The library automatically inspects the `type`, `format`, and `enum` properties o
|
|
|
166
211
|
| :-------------- | :------------------------- | :------: | :-------------------------------------------------------------------------------------- |
|
|
167
212
|
| `schema` | `JSONSchema` | Yes | The standard JSON Schema defining your data. |
|
|
168
213
|
| `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
|
|
214
|
+
| `uiSchema` | `Record<string, UISchema>` | No | Controls UI-specific rendering (widgets, column spans, field-level classNames). |
|
|
170
215
|
| `columns` | `1 \| 2 \| 3 \| 4` | No | Defines the global CSS Grid columns for the form layout. Default: `1`. |
|
|
171
216
|
| `theme` | `Object` | No | An object to override CSS variables (`primary`, `background`, `text`, `error`, etc.). |
|
|
217
|
+
| `classNames` | `FormClassNames` | No | An object mapping internal elements to custom CSS classes (e.g., Tailwind CSS support). |
|
|
172
218
|
| `defaultValues` | `Object` | No | Initial data to populate the form fields before rendering. |
|
|
173
219
|
|
|
174
220
|
---
|
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,4 @@ 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
|
+
export { type FieldFormat, FieldRenderer, type FieldType, 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,4 @@ 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
|
+
export { type FieldFormat, FieldRenderer, type FieldType, type FormClassNames, type JSONSchema, SchemaForm, type UISchema };
|