@connect-soft/form-generator 1.0.0 → 1.1.0-alpha2

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
@@ -2,367 +2,61 @@
2
2
 
3
3
  > Type-safe form generator with Radix UI, Tailwind CSS, and react-hook-form
4
4
 
5
- [![Version](https://img.shields.io/npm/v/@connect-soft/form-generator)](https://www.npmjs.com/package/@connect-soft/form-generator)
6
- [![License](https://img.shields.io/npm/l/@connect-soft/form-generator)](./LICENSE)
7
- [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@connect-soft/form-generator)](https://bundlephobia.com/package/@connect-soft/form-generator)
8
-
9
5
  **v2.0.0** - Complete rewrite with Radix UI + Tailwind CSS
10
- **50-60% smaller bundle** | **No runtime CSS overhead** | **Modern, accessible UI**
11
-
12
- ---
13
6
 
14
7
  ## Features
15
8
 
16
- **Modern UI Stack**: Radix UI primitives + Tailwind CSS (shadcn/ui approach)
17
- 📦 **Lightweight**: <80 KB gzipped (50-60% reduction from v1)
18
- 🎯 **Type-Safe**: Full TypeScript inference for form values
19
- 🔧 **Flexible**: 10+ field types with extensible API
20
- **Accessible**: Built on Radix UI's accessible primitives
21
- 🎨 **Customizable**: Easy styling with Tailwind classes
22
- 🚀 **Performance**: No runtime CSS-in-JS, field-level subscriptions
23
- 🔄 **Backward Compatible**: v1→v2 adapter included
24
-
25
- ---
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
26
17
 
27
18
  ## Installation
28
19
 
29
20
  ```bash
30
- npm install @connect-soft/form-generator react-hook-form zod
21
+ pnpm add @connect-soft/form-generator react-hook-form zod
31
22
  ```
32
23
 
33
- ### Peer Dependencies
34
-
35
- - `react` ^19.0.0
36
- - `react-dom` ^19.0.0
37
- - `zod` ^4.0.0
38
-
39
- ### Tailwind CSS Setup
40
-
41
- This library requires Tailwind CSS. If you don't have it set up:
42
-
43
- ```bash
44
- npm install -D tailwindcss postcss autoprefixer
45
- npx tailwindcss init -p
46
- ```
47
-
48
- **tailwind.config.js:**
49
- ```javascript
50
- module.exports = {
51
- content: [
52
- './src/**/*.{js,ts,jsx,tsx}',
53
- './node_modules/@connect-soft/form-generator/dist/**/*.{js,mjs}',
54
- ],
55
- theme: {
56
- extend: {
57
- // Your custom theme
58
- },
59
- },
60
- plugins: [],
61
- };
62
- ```
63
-
64
- **Import the styles in your main file:**
65
- ```typescript
66
- import '@connect-soft/form-generator/dist/styles.css';
67
- ```
68
-
69
- ---
70
-
71
24
  ## Quick Start
72
25
 
73
26
  ```typescript
74
- import { FormGenerator, Field } from '@connect-soft/form-generator';
27
+ import { FormGenerator } from '@connect-soft/form-generator';
75
28
 
76
- const fields: Field[] = [
29
+ const fields = [
77
30
  {
78
31
  type: 'text',
79
32
  name: 'email',
80
33
  label: 'Email',
81
34
  fieldType: 'email',
82
35
  required: true,
83
- placeholder: 'Enter your email',
84
36
  },
85
37
  {
86
38
  type: 'number',
87
39
  name: 'age',
88
40
  label: 'Age',
89
41
  min: 18,
90
- max: 120,
91
- },
92
- {
93
- type: 'select',
94
- name: 'country',
95
- label: 'Country',
96
- options: [
97
- { label: 'United States', value: 'us' },
98
- { label: 'United Kingdom', value: 'uk' },
99
- { label: 'Germany', value: 'de' },
100
- ],
101
- },
102
- {
103
- type: 'checkbox',
104
- name: 'subscribe',
105
- label: 'Subscribe to newsletter',
106
- },
107
- ] as const;
108
-
109
- function MyForm() {
110
- return (
111
- <FormGenerator
112
- fields={fields}
113
- onSubmit={(values) => {
114
- // ✅ values is fully typed!
115
- console.log(values.email); // string
116
- console.log(values.age); // number
117
- console.log(values.country); // string
118
- console.log(values.subscribe);// boolean
119
- }}
120
- submitText="Create Account"
121
- />
122
- );
123
- }
124
- ```
125
-
126
- ---
127
-
128
- ## Field Types
129
-
130
- | Type | Description | Value Type |
131
- |------|-------------|------------|
132
- | `text` | Text input (email, password, url, tel) | `string` |
133
- | `textarea` | Multi-line text input | `string` |
134
- | `number` | Number input with min/max/step | `number` |
135
- | `checkbox` | Checkbox input | `boolean` |
136
- | `switch` | Toggle switch | `boolean` |
137
- | `select` | Dropdown select | `string` |
138
- | `radio` | Radio button group | `string` |
139
- | `date` | Date picker (react-day-picker) | `Date` |
140
- | `dateRange` | Date range picker | `{from: Date, to?: Date}` |
141
- | `time` | Time picker (HH:mm) | `string` |
142
-
143
- ---
144
-
145
- ## Advanced Components
146
-
147
- ### MultiSelect
148
-
149
- ```typescript
150
- import { MultiSelect } from '@connect-soft/form-generator/advanced';
151
-
152
- <MultiSelect
153
- options={[
154
- { label: 'React', value: 'react' },
155
- { label: 'Vue', value: 'vue' },
156
- { label: 'Angular', value: 'angular' },
157
- ]}
158
- value={selected}
159
- onChange={setSelected}
160
- placeholder="Select frameworks..."
161
- />
162
- ```
163
-
164
- ### ColorPicker
165
-
166
- ```typescript
167
- import { ColorPicker } from '@connect-soft/form-generator/advanced';
168
-
169
- <ColorPicker
170
- value={color}
171
- onChange={setColor}
172
- />
173
- ```
174
-
175
- ### TransferList
176
-
177
- ```typescript
178
- import { TransferList } from '@connect-soft/form-generator/advanced';
179
-
180
- <TransferList
181
- options={allOptions}
182
- value={selectedValues}
183
- onChange={setSelectedValues}
184
- leftTitle="Available"
185
- rightTitle="Selected"
186
- searchable={true}
187
- />
188
- ```
189
-
190
- ---
191
-
192
- ## Custom Validation
193
-
194
- Use Zod for schema validation:
195
-
196
- ```typescript
197
- import { z } from 'zod';
198
-
199
- const fields = [
200
- {
201
- type: 'text',
202
- name: 'username',
203
- label: 'Username',
204
- validation: z.string().min(3).max(20).regex(/^[a-zA-Z0-9_]+$/),
205
- },
206
- {
207
- type: 'text',
208
- name: 'email',
209
- label: 'Email',
210
- fieldType: 'email',
211
- validation: z.string().email().endsWith('@company.com'),
212
- },
213
- {
214
- type: 'number',
215
- name: 'age',
216
- label: 'Age',
217
- validation: z.number().min(18).max(120),
218
42
  },
219
43
  ] as const;
220
- ```
221
-
222
- ---
223
44
 
224
- ## Styling
225
-
226
- ### Using Tailwind Classes
227
-
228
- ```typescript
229
- {
230
- type: 'text',
231
- name: 'email',
232
- className: 'bg-blue-50 border-blue-300 focus:ring-blue-500',
233
- }
45
+ export const MyForm = () => (
46
+ <FormGenerator
47
+ fields={fields}
48
+ onSubmit={(values) => {
49
+ // values is fully typed!
50
+ console.log(values);
51
+ }}
52
+ />
53
+ );
234
54
  ```
235
55
 
236
- ### Form-Level Styling
56
+ ## Documentation
237
57
 
238
- ```typescript
239
- <FormGenerator
240
- fields={fields}
241
- onSubmit={handleSubmit}
242
- className="max-w-md mx-auto p-6 bg-white rounded-lg shadow"
243
- />
244
- ```
245
-
246
- ### Custom Theme
247
-
248
- Override CSS variables in your global CSS:
249
-
250
- ```css
251
- :root {
252
- --primary: 220 90% 56%;
253
- --primary-foreground: 0 0% 100%;
254
- --radius: 0.5rem;
255
- }
256
- ```
257
-
258
- ---
259
-
260
- ## TypeScript Type Inference
261
-
262
- The library provides full type inference for form values:
263
-
264
- ```typescript
265
- const fields = [
266
- { type: 'text', name: 'email', fieldType: 'email' },
267
- { type: 'number', name: 'age' },
268
- { type: 'checkbox', name: 'terms' },
269
- { type: 'date', name: 'birthdate' },
270
- ] as const;
271
-
272
- <FormGenerator
273
- fields={fields}
274
- onSubmit={(values) => {
275
- // ✅ Fully typed!
276
- values.email; // string
277
- values.age; // number
278
- values.terms; // boolean
279
- values.birthdate; // Date
280
- }}
281
- />
282
- ```
283
-
284
- ---
285
-
286
- ## Migration from v1.x
287
-
288
- Migrating from `@connect-soft/mui-hook-form` v1.x? See the [MIGRATION.md](./MIGRATION.md) guide.
289
-
290
- ### Quick Migration with Adapter
291
-
292
- ```typescript
293
- import { FormGenerator } from '@connect-soft/form-generator';
294
- import { adaptV1FieldsToV2 } from '@connect-soft/form-generator/adapters';
295
-
296
- // Your existing v1 fields
297
- const v1Fields = [
298
- {
299
- type: 'textField',
300
- props: { name: 'email', label: 'Email', required: true },
301
- },
302
- ];
303
-
304
- // Auto-convert to v2
305
- const v2Fields = adaptV1FieldsToV2(v1Fields);
306
-
307
- <FormGenerator fields={v2Fields} onSubmit={handleSubmit} />
308
- ```
309
-
310
- ---
311
-
312
- ## API Reference
313
-
314
- ### FormGenerator Props
315
-
316
- | Prop | Type | Default | Description |
317
- |------|------|---------|-------------|
318
- | `fields` | `Field[]` | **required** | Array of field definitions |
319
- | `onSubmit` | `(values) => void \| Promise<void>` | **required** | Form submission handler |
320
- | `defaultValues` | `Partial<InferFormValues<TFields>>` | `{}` | Initial form values |
321
- | `className` | `string` | - | Tailwind classes for form container |
322
- | `submitText` | `string` | `'Submit'` | Submit button text |
323
- | `submitButtonVariant` | `'default' \| 'destructive' \| 'outline' \| 'secondary' \| 'ghost' \| 'link'` | `'default'` | Submit button style |
324
- | `disabled` | `boolean` | `false` | Disable entire form |
325
- | `mode` | `'onChange' \| 'onBlur' \| 'onSubmit' \| 'onTouched' \| 'all'` | `'onChange'` | Validation trigger mode |
326
-
327
- ### Field Base Properties
328
-
329
- | Property | Type | Description |
330
- |----------|------|-------------|
331
- | `type` | `string` | Field type (text, number, select, etc.) |
332
- | `name` | `string` | Field name (must be unique) |
333
- | `label` | `string` | Field label |
334
- | `description` | `string` | Helper text below field |
335
- | `required` | `boolean` | Mark field as required |
336
- | `disabled` | `boolean` | Disable field |
337
- | `hidden` | `boolean` | Hide field |
338
- | `defaultValue` | `any` | Default field value |
339
- | `validation` | `ZodType` | Zod validation schema |
340
- | `className` | `string` | Tailwind classes for field |
341
-
342
- ---
343
-
344
- ## Links
345
-
346
- - [Migration Guide](./MIGRATION.md)
347
- - [GitLab Repository](https://gitlab.com/connect-soft/components/form-generator)
348
- - [Issues](https://gitlab.com/connect-soft/components/form-generator/issues)
349
-
350
- ---
58
+ See [main README](../../README.md) for full documentation.
351
59
 
352
60
  ## License
353
61
 
354
62
  ISC © Connect Soft
355
-
356
- ---
357
-
358
- ## Acknowledgments
359
-
360
- Built with:
361
- - [Radix UI](https://www.radix-ui.com/) - Accessible UI primitives
362
- - [Tailwind CSS](https://tailwindcss.com/) - Utility-first CSS framework
363
- - [react-hook-form](https://react-hook-form.com/) - Performant form library
364
- - [Zod](https://zod.dev/) - TypeScript-first schema validation
365
- - [react-day-picker](https://react-day-picker.js.org/) - Flexible date picker
366
- - [lucide-react](https://lucide.dev/) - Beautiful icons
367
-
368
- Inspired by [shadcn/ui](https://ui.shadcn.com/) component architecture.