@connect-soft/form-generator 1.0.0-alpha
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/LICENSE.md +14 -0
- package/MIGRATION.md +503 -0
- package/README.md +62 -0
- package/dist/index.js +3607 -0
- package/dist/index.js.map +1 -0
- package/dist/index.m.js +3555 -0
- package/dist/index.m.js.map +1 -0
- package/dist/styles/globals.css +2 -0
- package/dist/types/components/form/field-renderer.d.ts +12 -0
- package/dist/types/components/form/field-renderer.d.ts.map +1 -0
- package/dist/types/components/form/form-generator.d.ts +14 -0
- package/dist/types/components/form/form-generator.d.ts.map +1 -0
- package/dist/types/components/form/index.d.ts +5 -0
- package/dist/types/components/form/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/field-registry.d.ts +114 -0
- package/dist/types/lib/field-registry.d.ts.map +1 -0
- package/dist/types/lib/field-types.d.ts +50 -0
- package/dist/types/lib/field-types.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +8 -0
- package/dist/types/lib/index.d.ts.map +1 -0
- package/dist/types/setupTests.d.ts +2 -0
- package/dist/types/setupTests.d.ts.map +1 -0
- package/package.json +99 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# ISC License
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/ISC)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2023 Connect Soft s.r.o.
|
|
6
|
+
|
|
7
|
+
ISC License
|
|
8
|
+
|
|
9
|
+
Copyright 2023 Connect Soft s.r.o.
|
|
10
|
+
|
|
11
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
SOFTWARE.
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
# Migration Guide: v1.x (MUI) → v2.0 (Radix UI + Tailwind CSS)
|
|
2
|
+
|
|
3
|
+
This guide will help you migrate from `@connect-soft/mui-hook-form` v1.x to `@connect-soft/form-generator` v2.0.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
v2.0 is a **complete rewrite** with breaking changes:
|
|
8
|
+
|
|
9
|
+
- ❌ **Removed:** All Material-UI dependencies (@mui/material, @emotion/react, @emotion/styled)
|
|
10
|
+
- ✅ **Added:** Radix UI primitives + Tailwind CSS
|
|
11
|
+
- 🎨 **New:** Simplified, modern API
|
|
12
|
+
- 📦 **Result:** 50-60% smaller bundle size (<80 KB vs ~120-377 KB)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Breaking Changes
|
|
17
|
+
|
|
18
|
+
### 1. Package Name Changed
|
|
19
|
+
|
|
20
|
+
**v1.x:**
|
|
21
|
+
```bash
|
|
22
|
+
npm install @connect-soft/mui-hook-form
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**v2.0:**
|
|
26
|
+
```bash
|
|
27
|
+
npm install @connect-soft/form-generator
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Peer Dependencies Changed
|
|
31
|
+
|
|
32
|
+
**v1.x required:**
|
|
33
|
+
- `@mui/material` v7.x
|
|
34
|
+
- `@mui/icons-material` v7.x
|
|
35
|
+
- `@mui/x-date-pickers` v8.x
|
|
36
|
+
- `@emotion/react` v11.x
|
|
37
|
+
- `@emotion/styled` v11.x
|
|
38
|
+
- `dayjs` v1.x
|
|
39
|
+
|
|
40
|
+
**v2.0 requires:**
|
|
41
|
+
- `react` v19.x
|
|
42
|
+
- `react-dom` v19.x
|
|
43
|
+
- `zod` v4.x
|
|
44
|
+
- **No MUI or Emotion dependencies!**
|
|
45
|
+
|
|
46
|
+
### 3. Tailwind CSS Required
|
|
47
|
+
|
|
48
|
+
v2.0 uses Tailwind CSS for styling. You must set up Tailwind in your project:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install -D tailwindcss postcss autoprefixer
|
|
52
|
+
npx tailwindcss init -p
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**tailwind.config.js:**
|
|
56
|
+
```javascript
|
|
57
|
+
module.exports = {
|
|
58
|
+
content: [
|
|
59
|
+
'./src/**/*.{js,ts,jsx,tsx}',
|
|
60
|
+
'./node_modules/@connect-soft/form-generator/dist/**/*.{js,mjs}',
|
|
61
|
+
],
|
|
62
|
+
// ... rest of config
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Import global CSS:**
|
|
67
|
+
```typescript
|
|
68
|
+
// In your main file (e.g., App.tsx, index.tsx)
|
|
69
|
+
import '@connect-soft/form-generator/dist/styles.css';
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Field Type Definitions Changed
|
|
73
|
+
|
|
74
|
+
The field definition structure has been simplified.
|
|
75
|
+
|
|
76
|
+
#### v1.x Field Structure:
|
|
77
|
+
```typescript
|
|
78
|
+
const v1Field = {
|
|
79
|
+
type: 'textField',
|
|
80
|
+
props: {
|
|
81
|
+
name: 'email',
|
|
82
|
+
label: 'Email Address',
|
|
83
|
+
required: true,
|
|
84
|
+
placeholder: 'Enter your email',
|
|
85
|
+
type: 'email',
|
|
86
|
+
},
|
|
87
|
+
display: (values) => values.showEmail,
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### v2.0 Field Structure:
|
|
92
|
+
```typescript
|
|
93
|
+
const v2Field = {
|
|
94
|
+
type: 'text',
|
|
95
|
+
name: 'email',
|
|
96
|
+
label: 'Email Address',
|
|
97
|
+
required: true,
|
|
98
|
+
placeholder: 'Enter your email',
|
|
99
|
+
fieldType: 'email',
|
|
100
|
+
// No nested 'props'!
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Field Type Mapping
|
|
107
|
+
|
|
108
|
+
| v1.x Type | v2.0 Type | Notes |
|
|
109
|
+
|-----------|-----------|-------|
|
|
110
|
+
| `textField` | `text` | Use `fieldType` for email, password, etc. |
|
|
111
|
+
| `textArea` | `textarea` | - |
|
|
112
|
+
| `numberField` | `number` | - |
|
|
113
|
+
| `checkBox` | `checkbox` | - |
|
|
114
|
+
| `switch` | `switch` | - |
|
|
115
|
+
| `select` | `select` | Options format unchanged |
|
|
116
|
+
| `radioGroup` | `radio` | Options format unchanged |
|
|
117
|
+
| `datePicker` | `date` | Now uses react-day-picker |
|
|
118
|
+
| `dateRangePicker` | `dateRange` | Now uses react-day-picker |
|
|
119
|
+
| `timePicker` | `time` | - |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Migration Strategies
|
|
124
|
+
|
|
125
|
+
### Strategy 1: Gradual Migration with Adapter (Recommended)
|
|
126
|
+
|
|
127
|
+
Use the built-in v1→v2 adapter to convert old field configs automatically:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { FormGenerator } from '@connect-soft/form-generator';
|
|
131
|
+
import { adaptV1FieldsToV2 } from '@connect-soft/form-generator/adapters';
|
|
132
|
+
|
|
133
|
+
// Your existing v1 fields
|
|
134
|
+
const v1Fields = [
|
|
135
|
+
{
|
|
136
|
+
type: 'textField',
|
|
137
|
+
props: { name: 'email', label: 'Email', required: true },
|
|
138
|
+
},
|
|
139
|
+
// ... more v1 fields
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
// Auto-convert to v2
|
|
143
|
+
const v2Fields = adaptV1FieldsToV2(v1Fields);
|
|
144
|
+
|
|
145
|
+
function MyForm() {
|
|
146
|
+
return (
|
|
147
|
+
<FormGenerator
|
|
148
|
+
fields={v2Fields}
|
|
149
|
+
onSubmit={(values) => console.log(values)}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Strategy 2: Complete Rewrite
|
|
156
|
+
|
|
157
|
+
Rewrite your field definitions using the new v2 API:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { FormGenerator, Field } from '@connect-soft/form-generator';
|
|
161
|
+
|
|
162
|
+
const fields: Field[] = [
|
|
163
|
+
{
|
|
164
|
+
type: 'text',
|
|
165
|
+
name: 'email',
|
|
166
|
+
label: 'Email',
|
|
167
|
+
fieldType: 'email',
|
|
168
|
+
required: true,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: 'select',
|
|
172
|
+
name: 'country',
|
|
173
|
+
label: 'Country',
|
|
174
|
+
options: [
|
|
175
|
+
{ label: 'USA', value: 'us' },
|
|
176
|
+
{ label: 'UK', value: 'uk' },
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
] as const;
|
|
180
|
+
|
|
181
|
+
function MyForm() {
|
|
182
|
+
return (
|
|
183
|
+
<FormGenerator
|
|
184
|
+
fields={fields}
|
|
185
|
+
onSubmit={(values) => {
|
|
186
|
+
// values is fully typed!
|
|
187
|
+
console.log(values.email, values.country);
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## API Changes
|
|
197
|
+
|
|
198
|
+
### FormGenerator Props
|
|
199
|
+
|
|
200
|
+
#### Removed Props:
|
|
201
|
+
- ❌ `sx` (MUI styling)
|
|
202
|
+
- ❌ `theme` (MUI theme)
|
|
203
|
+
- ❌ `muiProps` (MUI-specific props)
|
|
204
|
+
|
|
205
|
+
#### New Props:
|
|
206
|
+
- ✅ `className` (Tailwind classes)
|
|
207
|
+
- ✅ `submitButtonVariant` (Button style variants)
|
|
208
|
+
|
|
209
|
+
#### Unchanged Props:
|
|
210
|
+
- ✅ `fields`
|
|
211
|
+
- ✅ `onSubmit`
|
|
212
|
+
- ✅ `defaultValues`
|
|
213
|
+
- ✅ `mode`
|
|
214
|
+
- ✅ `disabled`
|
|
215
|
+
|
|
216
|
+
### Type Inference (Maintained!)
|
|
217
|
+
|
|
218
|
+
v2.0 maintains the same powerful TypeScript inference from v1.x:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const fields = [
|
|
222
|
+
{ type: 'text', name: 'email', fieldType: 'email' },
|
|
223
|
+
{ type: 'number', name: 'age' },
|
|
224
|
+
{ type: 'checkbox', name: 'subscribe' },
|
|
225
|
+
] as const;
|
|
226
|
+
|
|
227
|
+
<FormGenerator
|
|
228
|
+
fields={fields}
|
|
229
|
+
onSubmit={(values) => {
|
|
230
|
+
// ✅ values.email: string
|
|
231
|
+
// ✅ values.age: number
|
|
232
|
+
// ✅ values.subscribe: boolean
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Styling Changes
|
|
240
|
+
|
|
241
|
+
### v1.x (MUI)
|
|
242
|
+
```typescript
|
|
243
|
+
<FormGenerator
|
|
244
|
+
fields={fields}
|
|
245
|
+
sx={{ padding: 2, backgroundColor: 'primary.main' }}
|
|
246
|
+
/>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### v2.0 (Tailwind CSS)
|
|
250
|
+
```typescript
|
|
251
|
+
<FormGenerator
|
|
252
|
+
fields={fields}
|
|
253
|
+
className="p-4 bg-primary"
|
|
254
|
+
/>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
To customize component styles, you can:
|
|
258
|
+
|
|
259
|
+
1. **Use Tailwind classes** on individual fields:
|
|
260
|
+
```typescript
|
|
261
|
+
{
|
|
262
|
+
type: 'text',
|
|
263
|
+
name: 'email',
|
|
264
|
+
className: 'bg-blue-50 border-blue-300',
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
2. **Override Tailwind theme** in `tailwind.config.js`:
|
|
269
|
+
```javascript
|
|
270
|
+
module.exports = {
|
|
271
|
+
theme: {
|
|
272
|
+
extend: {
|
|
273
|
+
colors: {
|
|
274
|
+
primary: '#your-color',
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
3. **Use CSS variables** (defined in globals.css):
|
|
282
|
+
```css
|
|
283
|
+
:root {
|
|
284
|
+
--primary: 222.2 47.4% 11.2%;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Complex Components
|
|
291
|
+
|
|
292
|
+
### ColorPicker
|
|
293
|
+
|
|
294
|
+
**v1.x:**
|
|
295
|
+
```typescript
|
|
296
|
+
import { ColorPicker } from '@connect-soft/mui-hook-form';
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**v2.0:**
|
|
300
|
+
```typescript
|
|
301
|
+
import { ColorPicker } from '@connect-soft/form-generator/advanced';
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### MultiSelect
|
|
305
|
+
|
|
306
|
+
**v1.x:**
|
|
307
|
+
```typescript
|
|
308
|
+
// Used MUI Autocomplete
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**v2.0:**
|
|
312
|
+
```typescript
|
|
313
|
+
import { MultiSelect } from '@connect-soft/form-generator/advanced';
|
|
314
|
+
|
|
315
|
+
<MultiSelect
|
|
316
|
+
options={[
|
|
317
|
+
{ label: 'Option 1', value: '1' },
|
|
318
|
+
{ label: 'Option 2', value: '2' },
|
|
319
|
+
]}
|
|
320
|
+
value={selected}
|
|
321
|
+
onChange={setSelected}
|
|
322
|
+
/>
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### TransferList
|
|
326
|
+
|
|
327
|
+
**v1.x:**
|
|
328
|
+
```typescript
|
|
329
|
+
// Used MUI List/ListItem
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
**v2.0:**
|
|
333
|
+
```typescript
|
|
334
|
+
import { TransferList } from '@connect-soft/form-generator/advanced';
|
|
335
|
+
|
|
336
|
+
<TransferList
|
|
337
|
+
options={allOptions}
|
|
338
|
+
value={selectedValues}
|
|
339
|
+
onChange={setSelectedValues}
|
|
340
|
+
searchable={true}
|
|
341
|
+
/>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Date Pickers
|
|
347
|
+
|
|
348
|
+
### Major Change: MUI X Date Pickers → react-day-picker
|
|
349
|
+
|
|
350
|
+
**v1.x:**
|
|
351
|
+
- Used `@mui/x-date-pickers`
|
|
352
|
+
- Required `dayjs` as peer dependency
|
|
353
|
+
- Used MUI's LocalizationProvider
|
|
354
|
+
|
|
355
|
+
**v2.0:**
|
|
356
|
+
- Uses `react-day-picker` v9
|
|
357
|
+
- Uses `date-fns` for formatting
|
|
358
|
+
- No provider needed!
|
|
359
|
+
|
|
360
|
+
### Migration Example:
|
|
361
|
+
|
|
362
|
+
**v1.x:**
|
|
363
|
+
```typescript
|
|
364
|
+
import { LocalizationProvider } from '@mui/x-date-pickers';
|
|
365
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
366
|
+
|
|
367
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
368
|
+
<FormGenerator fields={fields} />
|
|
369
|
+
</LocalizationProvider>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**v2.0:**
|
|
373
|
+
```typescript
|
|
374
|
+
// No provider needed!
|
|
375
|
+
<FormGenerator fields={fields} />
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Testing Considerations
|
|
381
|
+
|
|
382
|
+
### Update Test Setup
|
|
383
|
+
|
|
384
|
+
If you were mocking MUI components in tests, you'll need to update:
|
|
385
|
+
|
|
386
|
+
**v1.x:**
|
|
387
|
+
```typescript
|
|
388
|
+
jest.mock('@mui/material/TextField', () => ({
|
|
389
|
+
__esModule: true,
|
|
390
|
+
default: jest.fn(),
|
|
391
|
+
}));
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**v2.0:**
|
|
395
|
+
```typescript
|
|
396
|
+
// Mock Radix UI components if needed
|
|
397
|
+
jest.mock('@radix-ui/react-select', () => ({
|
|
398
|
+
Root: jest.fn(),
|
|
399
|
+
Trigger: jest.fn(),
|
|
400
|
+
// ...
|
|
401
|
+
}));
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Snapshot Tests
|
|
405
|
+
|
|
406
|
+
All snapshots will change due to:
|
|
407
|
+
- Different DOM structure (Radix vs MUI)
|
|
408
|
+
- Different class names (Tailwind vs MUI)
|
|
409
|
+
- **Action Required:** Regenerate all snapshots
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Bundle Size Impact
|
|
414
|
+
|
|
415
|
+
### Before (v1.x with MUI):
|
|
416
|
+
- Full bundle: ~377 KB
|
|
417
|
+
- With tree-shaking: ~120 KB
|
|
418
|
+
- Runtime: CSS-in-JS overhead
|
|
419
|
+
|
|
420
|
+
### After (v2.0 with Radix + Tailwind):
|
|
421
|
+
- Target: <80 KB gzipped
|
|
422
|
+
- **50-60% reduction**
|
|
423
|
+
- No runtime CSS overhead (Tailwind is build-time)
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## Step-by-Step Migration Checklist
|
|
428
|
+
|
|
429
|
+
- [ ] 1. Install v2.0: `npm install @connect-soft/form-generator`
|
|
430
|
+
- [ ] 2. Set up Tailwind CSS in your project
|
|
431
|
+
- [ ] 3. Import global CSS: `import '@connect-soft/form-generator/dist/styles.css'`
|
|
432
|
+
- [ ] 4. Update imports: `@connect-soft/mui-hook-form` → `@connect-soft/form-generator`
|
|
433
|
+
- [ ] 5. Use adapter for existing v1 fields OR rewrite field definitions
|
|
434
|
+
- [ ] 6. Remove MUI peer dependencies
|
|
435
|
+
- [ ] 7. Update styling (sx → className)
|
|
436
|
+
- [ ] 8. Remove LocalizationProvider if used
|
|
437
|
+
- [ ] 9. Update tests and regenerate snapshots
|
|
438
|
+
- [ ] 10. Test thoroughly in development
|
|
439
|
+
- [ ] 11. Uninstall v1.x: `npm uninstall @connect-soft/mui-hook-form`
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Troubleshooting
|
|
444
|
+
|
|
445
|
+
### Issue: "Module not found: Can't resolve '@radix-ui/react-*'"
|
|
446
|
+
|
|
447
|
+
**Solution:** Make sure you installed the package correctly:
|
|
448
|
+
```bash
|
|
449
|
+
npm install @connect-soft/form-generator
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Issue: "Styles not appearing"
|
|
453
|
+
|
|
454
|
+
**Solution:**
|
|
455
|
+
1. Ensure Tailwind CSS is configured in your project
|
|
456
|
+
2. Import the global CSS file
|
|
457
|
+
3. Add the package path to Tailwind's content array
|
|
458
|
+
|
|
459
|
+
### Issue: "Type inference not working"
|
|
460
|
+
|
|
461
|
+
**Solution:** Use `as const` assertion on your fields array:
|
|
462
|
+
```typescript
|
|
463
|
+
const fields = [...] as const;
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Issue: "Adapter not converting fields correctly"
|
|
467
|
+
|
|
468
|
+
**Solution:** Check if your v1 fields follow the correct structure:
|
|
469
|
+
```typescript
|
|
470
|
+
// Correct v1 structure
|
|
471
|
+
{ type: 'textField', props: { name: 'field1' } }
|
|
472
|
+
|
|
473
|
+
// Incorrect
|
|
474
|
+
{ fieldType: 'text', name: 'field1' } // Wrong!
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## Support
|
|
480
|
+
|
|
481
|
+
If you encounter issues during migration:
|
|
482
|
+
|
|
483
|
+
1. Check this guide thoroughly
|
|
484
|
+
2. Review the [CHANGELOG.md](./CHANGELOG.md)
|
|
485
|
+
3. Open an issue: https://gitlab.com/connect-soft/components/form-generator/issues
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## Summary
|
|
490
|
+
|
|
491
|
+
**v2.0 Benefits:**
|
|
492
|
+
- ✅ 50-60% smaller bundle
|
|
493
|
+
- ✅ No runtime CSS-in-JS overhead
|
|
494
|
+
- ✅ Simpler, cleaner API
|
|
495
|
+
- ✅ Modern UI with Radix + Tailwind
|
|
496
|
+
- ✅ Maintained TypeScript type safety
|
|
497
|
+
|
|
498
|
+
**Migration Effort:**
|
|
499
|
+
- **Small projects (< 10 forms):** 1-2 hours
|
|
500
|
+
- **Medium projects (10-50 forms):** 1-2 days
|
|
501
|
+
- **Large projects (50+ forms):** 1 week
|
|
502
|
+
|
|
503
|
+
The migration is worth the effort for improved performance and developer experience!
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @connect-soft/form-generator
|
|
2
|
+
|
|
3
|
+
> Type-safe form generator with Radix UI, Tailwind CSS, and react-hook-form
|
|
4
|
+
|
|
5
|
+
**v2.0.0** - Complete rewrite with Radix UI + Tailwind CSS
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- ✨ Modern UI with Radix primitives + Tailwind CSS
|
|
10
|
+
- 📦 50-60% smaller bundle (<80 KB gzipped)
|
|
11
|
+
- 🎯 Full TypeScript type inference
|
|
12
|
+
- 🔧 10+ field types with extensible API
|
|
13
|
+
- ♿ Built-in accessibility
|
|
14
|
+
- 🎨 Easy Tailwind customization
|
|
15
|
+
- 🚀 Zero runtime CSS overhead
|
|
16
|
+
- 🔄 v1→v2 migration adapter included
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @connect-soft/form-generator react-hook-form zod
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { FormGenerator } from '@connect-soft/form-generator';
|
|
28
|
+
|
|
29
|
+
const fields = [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
name: 'email',
|
|
33
|
+
label: 'Email',
|
|
34
|
+
fieldType: 'email',
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'number',
|
|
39
|
+
name: 'age',
|
|
40
|
+
label: 'Age',
|
|
41
|
+
min: 18,
|
|
42
|
+
},
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
export const MyForm = () => (
|
|
46
|
+
<FormGenerator
|
|
47
|
+
fields={fields}
|
|
48
|
+
onSubmit={(values) => {
|
|
49
|
+
// values is fully typed!
|
|
50
|
+
console.log(values);
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
See [main README](../../README.md) for full documentation.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
ISC © Connect Soft
|