@tachui/forms 0.7.1-alpha → 0.8.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/README.md +87 -272
- package/dist/DatePicker-D5nRFTUm.js +475 -0
- package/dist/DatePicker-D5nRFTUm.js.map +1 -0
- package/dist/Select-yZyKooXk.js +945 -0
- package/dist/Select-yZyKooXk.js.map +1 -0
- package/dist/Slider-0-oal5YR.js +644 -0
- package/dist/Slider-0-oal5YR.js.map +1 -0
- package/dist/TextField-hX15dY3U.js +509 -0
- package/dist/TextField-hX15dY3U.js.map +1 -0
- package/dist/components/advanced/Slider.d.ts +190 -0
- package/dist/components/advanced/Slider.d.ts.map +1 -0
- package/dist/components/advanced/Stepper.d.ts +161 -0
- package/dist/components/advanced/Stepper.d.ts.map +1 -0
- package/dist/components/advanced/index.d.ts +15 -0
- package/dist/components/advanced/index.d.ts.map +1 -0
- package/dist/components/advanced/index.js +6 -0
- package/dist/components/advanced/index.js.map +1 -0
- package/dist/components/date-picker/DatePicker.d.ts +126 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
- package/dist/components/date-picker/index.d.ts +14 -0
- package/dist/components/date-picker/index.d.ts.map +1 -0
- package/dist/components/date-picker/index.js +5 -0
- package/dist/components/date-picker/index.js.map +1 -0
- package/dist/components/form-container/index.d.ts +58 -0
- package/dist/components/form-container/index.d.ts.map +1 -0
- package/dist/components/selection/Checkbox.d.ts.map +1 -0
- package/dist/components/selection/Radio.d.ts.map +1 -0
- package/dist/components/selection/Select.d.ts.map +1 -0
- package/dist/components/selection/index.d.ts +68 -0
- package/dist/components/selection/index.d.ts.map +1 -0
- package/dist/components/selection/index.js +12 -0
- package/dist/components/selection/index.js.map +1 -0
- package/dist/components/text-input/TextField.d.ts.map +1 -0
- package/dist/components/text-input/index.d.ts +8 -0
- package/dist/components/text-input/index.d.ts.map +1 -0
- package/dist/components/text-input/index.js +18 -0
- package/dist/components/text-input/index.js.map +1 -0
- package/dist/{state/index.js → index-D3WfkqVv.js} +15 -8
- package/dist/index-D3WfkqVv.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +198 -376
- package/dist/index.js.map +1 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/validation/component-validation.d.ts +11 -2
- package/dist/validation/component-validation.d.ts.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +282 -191
- package/dist/validation/index.js.map +1 -0
- package/package.json +53 -39
- package/src/components/advanced/Slider.ts +722 -0
- package/src/components/advanced/Stepper.ts +715 -0
- package/src/components/advanced/index.ts +20 -0
- package/src/components/date-picker/DatePicker.ts +925 -0
- package/src/components/date-picker/index.ts +20 -0
- package/src/components/form-container/index.ts +266 -0
- package/src/components/selection/Checkbox.ts +478 -0
- package/src/components/selection/Radio.ts +470 -0
- package/src/components/selection/Select.ts +620 -0
- package/src/components/selection/index.ts +81 -0
- package/src/components/text-input/TextField.ts +728 -0
- package/src/components/text-input/index.ts +35 -0
- package/src/index.ts +48 -0
- package/src/state/index.ts +544 -0
- package/src/types/index.ts +579 -0
- package/src/utils/formatters.ts +184 -0
- package/src/utils/index.ts +57 -0
- package/src/validation/component-validation.ts +429 -0
- package/src/validation/index.ts +641 -0
- package/dist/TextField-CGBM3x7K.js +0 -1799
- package/dist/components/Form.d.ts +0 -76
- package/dist/components/Form.d.ts.map +0 -1
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -28
- package/dist/components/input/Checkbox.d.ts.map +0 -1
- package/dist/components/input/Radio.d.ts.map +0 -1
- package/dist/components/input/Select.d.ts.map +0 -1
- package/dist/components/input/TextField.d.ts.map +0 -1
- package/dist/components/input/index.d.ts +0 -11
- package/dist/components/input/index.d.ts.map +0 -1
- package/dist/utils/validators.d.ts +0 -101
- package/dist/utils/validators.d.ts.map +0 -1
- /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
- /package/dist/components/{input → selection}/Radio.d.ts +0 -0
- /package/dist/components/{input → selection}/Select.d.ts +0 -0
- /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,321 +1,136 @@
|
|
|
1
1
|
# @tachui/forms
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Comprehensive form components and validation system for tachUI - unified package combining all form functionality.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://opensource.org/licenses/MPL-2.0)
|
|
5
|
+
## What's New in v2.0
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
- 🎯 **Advanced Form Components** - TextField, Select, Checkbox, Radio, and more
|
|
15
|
-
- ✅ **Built-in Validation** - Schema-based validation with real-time feedback
|
|
16
|
-
- 🔄 **Reactive Form State** - Automatic state management and synchronization
|
|
17
|
-
- 🎨 **SwiftUI-style API** - Familiar component patterns and modifiers
|
|
18
|
-
- 📱 **Mobile-friendly** - Touch-optimized inputs and interactions
|
|
19
|
-
- 🔧 **TypeScript-first** - Complete type safety for forms and validation
|
|
7
|
+
- **Unified Package**: All 27 form components in one optimized package
|
|
8
|
+
- **20% Bundle Reduction**: From 488KB to ~390KB through build optimization
|
|
9
|
+
- **Tree Shaking**: Import only the components you need
|
|
10
|
+
- **Backwards Compatible**: Maintains all existing APIs
|
|
20
11
|
|
|
21
12
|
## Installation
|
|
22
13
|
|
|
23
14
|
```bash
|
|
24
|
-
|
|
25
|
-
# or
|
|
26
|
-
pnpm add @tachui/core @tachui/forms
|
|
15
|
+
pnpm add @tachui/forms
|
|
27
16
|
```
|
|
28
17
|
|
|
29
18
|
## Quick Start
|
|
30
19
|
|
|
31
20
|
```typescript
|
|
32
|
-
import {
|
|
33
|
-
import { Form, TextField, Select, createFormState } from '@tachui/forms'
|
|
34
|
-
|
|
35
|
-
// Create form state
|
|
36
|
-
const formState = createFormState(
|
|
37
|
-
{
|
|
38
|
-
name: '',
|
|
39
|
-
email: '',
|
|
40
|
-
country: 'US',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: { required: true, minLength: 2 },
|
|
44
|
-
email: { required: true, email: true },
|
|
45
|
-
country: { required: true },
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
const contactForm = Form({
|
|
50
|
-
state: formState,
|
|
51
|
-
children: [
|
|
52
|
-
VStack({
|
|
53
|
-
children: [
|
|
54
|
-
TextField('Name', formState.binding('name'))
|
|
55
|
-
.modifier.placeholder('Enter your name')
|
|
56
|
-
.build(),
|
|
57
|
-
|
|
58
|
-
TextField('Email', formState.binding('email'))
|
|
59
|
-
.modifier.placeholder('Enter your email')
|
|
60
|
-
.keyboardType('email')
|
|
61
|
-
.build(),
|
|
62
|
-
|
|
63
|
-
Select(
|
|
64
|
-
'Country',
|
|
65
|
-
[
|
|
66
|
-
{ value: 'US', label: 'United States' },
|
|
67
|
-
{ value: 'CA', label: 'Canada' },
|
|
68
|
-
{ value: 'UK', label: 'United Kingdom' },
|
|
69
|
-
],
|
|
70
|
-
formState.binding('country')
|
|
71
|
-
).build(),
|
|
72
|
-
|
|
73
|
-
Button('Submit', () => {
|
|
74
|
-
if (formState.validate()) {
|
|
75
|
-
console.log('Form data:', formState.values())
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
.modifier.disabled(() => !formState.isValid())
|
|
79
|
-
.build(),
|
|
80
|
-
],
|
|
81
|
-
spacing: 16,
|
|
82
|
-
}).build(),
|
|
83
|
-
],
|
|
84
|
-
}).build()
|
|
85
|
-
```
|
|
21
|
+
import { Form, TextField, DatePicker, validation } from '@tachui/forms'
|
|
86
22
|
|
|
87
|
-
|
|
23
|
+
// Or use granular imports for optimal bundle size
|
|
24
|
+
import { TextField } from '@tachui/forms/text-input'
|
|
25
|
+
import { DatePicker } from '@tachui/forms/date-picker'
|
|
26
|
+
import { required, email } from '@tachui/forms/validation'
|
|
27
|
+
```
|
|
88
28
|
|
|
89
|
-
|
|
29
|
+
## Components (27 total)
|
|
90
30
|
|
|
91
|
-
|
|
31
|
+
### Form Container (2 components)
|
|
92
32
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
TextField('Password', passwordBinding)
|
|
97
|
-
.modifier.placeholder('Enter password')
|
|
98
|
-
.secureTextEntry(true)
|
|
99
|
-
.minLength(8)
|
|
100
|
-
.validation(value => (value.length >= 8 ? null : 'Password too short'))
|
|
101
|
-
.build()
|
|
102
|
-
```
|
|
33
|
+
- `Form` - Form state management and submission
|
|
34
|
+
- `FormSection` - Logical grouping of form fields
|
|
103
35
|
|
|
104
|
-
###
|
|
36
|
+
### Text Input (14 components)
|
|
105
37
|
|
|
106
|
-
|
|
38
|
+
- `TextField` - Basic text input
|
|
39
|
+
- `TextArea` - Multi-line text input
|
|
40
|
+
- `EmailField` - Email validation and formatting
|
|
41
|
+
- `PasswordField` - Password input with visibility toggle
|
|
42
|
+
- `SearchField` - Search input with clear button
|
|
43
|
+
- `URLField` - URL validation and formatting
|
|
44
|
+
- `PhoneField` - Phone number formatting and validation
|
|
45
|
+
- `NumberField` - Numeric input with validation
|
|
46
|
+
- `CreditCardField` - Credit card formatting and validation
|
|
47
|
+
- `SSNField` - Social Security Number formatting
|
|
48
|
+
- `PostalCodeField` - Postal/ZIP code validation
|
|
49
|
+
- `DateField` - Simple date text input
|
|
50
|
+
- `TimeField` - Time input and validation
|
|
51
|
+
- `ColorField` - Color picker input
|
|
107
52
|
|
|
108
|
-
|
|
109
|
-
import { Select, Picker } from '@tachui/forms'
|
|
53
|
+
### Selection (8 components)
|
|
110
54
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
55
|
+
- `Checkbox` - Single checkbox input
|
|
56
|
+
- `CheckboxGroup` - Multiple checkbox group
|
|
57
|
+
- `Switch` - Toggle switch input
|
|
58
|
+
- `Radio` - Single radio button
|
|
59
|
+
- `RadioGroup` - Radio button group
|
|
60
|
+
- `Select` - Single select dropdown
|
|
61
|
+
- `MultiSelect` - Multiple selection dropdown
|
|
62
|
+
- `Combobox` - Searchable select input
|
|
115
63
|
|
|
116
|
-
|
|
117
|
-
.modifier.multiSelect(true)
|
|
118
|
-
.displayStyle('compact')
|
|
119
|
-
.build()
|
|
120
|
-
```
|
|
64
|
+
### Advanced (3 components)
|
|
121
65
|
|
|
122
|
-
|
|
66
|
+
- `DatePicker` - Rich calendar interface
|
|
67
|
+
- `Stepper` - Numeric increment/decrement
|
|
68
|
+
- `Slider` - Range input with marks
|
|
123
69
|
|
|
124
|
-
|
|
70
|
+
## Tree-Shaking Examples
|
|
125
71
|
|
|
126
72
|
```typescript
|
|
127
|
-
|
|
73
|
+
// Import entire package (390KB)
|
|
74
|
+
import { TextField, DatePicker, validation } from '@tachui/forms'
|
|
128
75
|
|
|
129
|
-
|
|
76
|
+
// Import specific categories (~180KB for text inputs)
|
|
77
|
+
import * as TextInputs from '@tachui/forms/text-input'
|
|
78
|
+
import * as Validation from '@tachui/forms/validation'
|
|
130
79
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
80
|
+
// Import individual components (~20-30KB each)
|
|
81
|
+
import { TextField } from '@tachui/forms/text-input'
|
|
82
|
+
import { required, email } from '@tachui/forms/validation'
|
|
134
83
|
```
|
|
135
84
|
|
|
136
|
-
##
|
|
85
|
+
## Migration from v1.x
|
|
137
86
|
|
|
138
|
-
###
|
|
87
|
+
### From @tachui/forms + @tachui/advanced-forms
|
|
139
88
|
|
|
140
89
|
```typescript
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
{
|
|
145
|
-
firstName: '',
|
|
146
|
-
lastName: '',
|
|
147
|
-
age: 0,
|
|
148
|
-
preferences: [],
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
// Validation rules
|
|
152
|
-
firstName: {
|
|
153
|
-
required: true,
|
|
154
|
-
minLength: 2,
|
|
155
|
-
pattern: /^[A-Za-z]+$/,
|
|
156
|
-
},
|
|
157
|
-
lastName: {
|
|
158
|
-
required: true,
|
|
159
|
-
minLength: 2,
|
|
160
|
-
},
|
|
161
|
-
age: {
|
|
162
|
-
required: true,
|
|
163
|
-
min: 18,
|
|
164
|
-
max: 120,
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
```
|
|
90
|
+
// Old approach (488KB total)
|
|
91
|
+
import { TextField, Form } from '@tachui/forms'
|
|
92
|
+
import { DatePicker, Stepper } from '@tachui/advanced-forms'
|
|
169
93
|
|
|
170
|
-
|
|
94
|
+
// New unified approach (390KB total)
|
|
95
|
+
import { TextField, Form, DatePicker, Stepper } from '@tachui/forms'
|
|
171
96
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// Custom validation
|
|
177
|
-
const emailBinding = userForm.binding('email', {
|
|
178
|
-
validator: value => {
|
|
179
|
-
if (!value.includes('@')) return 'Invalid email'
|
|
180
|
-
return null
|
|
181
|
-
},
|
|
182
|
-
debounce: 300,
|
|
183
|
-
})
|
|
97
|
+
// Or with tree-shaking (as needed)
|
|
98
|
+
import { TextField, Form } from '@tachui/forms/text-input'
|
|
99
|
+
import { DatePicker } from '@tachui/forms/date-picker'
|
|
100
|
+
import { Stepper } from '@tachui/forms/advanced'
|
|
184
101
|
```
|
|
185
102
|
|
|
186
|
-
###
|
|
103
|
+
### Backwards Compatibility
|
|
187
104
|
|
|
188
|
-
|
|
189
|
-
// Validate entire form
|
|
190
|
-
const isValid = userForm.validate()
|
|
191
|
-
|
|
192
|
-
// Check specific field
|
|
193
|
-
const hasErrors = userForm.hasErrors('firstName')
|
|
194
|
-
|
|
195
|
-
// Get validation errors
|
|
196
|
-
const errors = userForm.getErrors()
|
|
197
|
-
|
|
198
|
-
// Real-time validation status
|
|
199
|
-
createEffect(() => {
|
|
200
|
-
if (userForm.isValid()) {
|
|
201
|
-
console.log('Form is valid!')
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
```
|
|
105
|
+
All existing APIs remain unchanged. Migration is optional and can be done incrementally.
|
|
205
106
|
|
|
206
|
-
##
|
|
107
|
+
## Validation System
|
|
207
108
|
|
|
208
|
-
|
|
109
|
+
Comprehensive validation with 20+ built-in rules:
|
|
209
110
|
|
|
210
111
|
```typescript
|
|
211
|
-
import {
|
|
212
|
-
|
|
213
|
-
const passwordValidator = createValidator({
|
|
214
|
-
minLength: 8,
|
|
215
|
-
requireUppercase: true,
|
|
216
|
-
requireLowercase: true,
|
|
217
|
-
requireNumbers: true,
|
|
218
|
-
requireSymbols: true,
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
TextField('Password', passwordBinding)
|
|
222
|
-
.modifier.validator(passwordValidator)
|
|
223
|
-
.build()
|
|
224
|
-
```
|
|
112
|
+
import { validation } from '@tachui/forms'
|
|
225
113
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const registrationSchema = createFormSchema({
|
|
232
|
-
username: {
|
|
233
|
-
type: 'string',
|
|
234
|
-
required: true,
|
|
235
|
-
minLength: 3,
|
|
236
|
-
maxLength: 20,
|
|
237
|
-
pattern: /^[a-zA-Z0-9_]+$/,
|
|
238
|
-
},
|
|
239
|
-
email: {
|
|
240
|
-
type: 'email',
|
|
241
|
-
required: true,
|
|
242
|
-
},
|
|
243
|
-
birthDate: {
|
|
244
|
-
type: 'date',
|
|
245
|
-
required: true,
|
|
246
|
-
maxDate: new Date(),
|
|
247
|
-
},
|
|
114
|
+
const schema = validation.object({
|
|
115
|
+
email: validation.string().email().required(),
|
|
116
|
+
password: validation.string().min(8).required(),
|
|
117
|
+
confirmPassword: validation.string().matches('password'),
|
|
118
|
+
age: validation.number().min(18).max(120),
|
|
248
119
|
})
|
|
249
|
-
|
|
250
|
-
const form = createFormState({}, registrationSchema)
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Conditional Fields
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
const surveyForm = createFormState({
|
|
257
|
-
hasExperience: false,
|
|
258
|
-
yearsExperience: 0,
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
// Show years field only if has experience
|
|
262
|
-
Show(
|
|
263
|
-
() => surveyForm.values().hasExperience,
|
|
264
|
-
() =>
|
|
265
|
-
TextField('Years of Experience', surveyForm.binding('yearsExperience'))
|
|
266
|
-
.modifier.keyboardType('numeric')
|
|
267
|
-
.build()
|
|
268
|
-
).build()
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
## Styling and Theming
|
|
272
|
-
|
|
273
|
-
Forms inherit tachUI's modifier system:
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
TextField('Email', emailBinding)
|
|
277
|
-
.modifier.padding(16)
|
|
278
|
-
.backgroundColor('#f8f9fa')
|
|
279
|
-
.cornerRadius(8)
|
|
280
|
-
.border({ width: 1, color: '#dee2e6' })
|
|
281
|
-
.focusBorderColor('#007AFF')
|
|
282
|
-
.errorBorderColor('#dc3545')
|
|
283
|
-
.build()
|
|
284
120
|
```
|
|
285
121
|
|
|
286
|
-
##
|
|
287
|
-
|
|
288
|
-
Built-in accessibility features:
|
|
289
|
-
|
|
290
|
-
- **ARIA labels** and descriptions
|
|
291
|
-
- **Keyboard navigation** support
|
|
292
|
-
- **Screen reader** compatibility
|
|
293
|
-
- **Focus management** and indicators
|
|
294
|
-
- **Error announcements** for validation
|
|
295
|
-
|
|
296
|
-
## Examples
|
|
297
|
-
|
|
298
|
-
Check out complete examples:
|
|
299
|
-
|
|
300
|
-
- **[Contact Form](https://github.com/tach-UI/tachUI/tree/main/apps/examples/forms/contact)**
|
|
301
|
-
- **[Registration Form](https://github.com/tach-UI/tachUI/tree/main/apps/examples/forms/registration)**
|
|
302
|
-
- **[Survey Builder](https://github.com/tach-UI/tachUI/tree/main/apps/examples/forms/survey)**
|
|
303
|
-
|
|
304
|
-
## API Reference
|
|
305
|
-
|
|
306
|
-
- **[TextField API](https://github.com/tach-UI/tachUI/blob/main/docs/api/forms/src/classes/TextField.md)**
|
|
307
|
-
- **[Form State API](https://github.com/tach-UI/tachUI/blob/main/docs/api/forms/src/functions/createFormState.md)**
|
|
308
|
-
- **[Validation API](https://github.com/tach-UI/tachUI/blob/main/docs/api/forms/src/functions/createValidator.md)**
|
|
309
|
-
|
|
310
|
-
## Requirements
|
|
311
|
-
|
|
312
|
-
- **@tachui/core** ^0.7.0-alpha1 or later
|
|
313
|
-
- **TypeScript** 5.0+ (recommended)
|
|
314
|
-
|
|
315
|
-
## Contributing
|
|
122
|
+
## Bundle Size Comparison
|
|
316
123
|
|
|
317
|
-
|
|
124
|
+
| Package | v1.x (Split) | v2.0 (Unified) | Savings |
|
|
125
|
+
| -------------- | -------------- | -------------- | --------- |
|
|
126
|
+
| Text Inputs | 149KB | 120KB | 19% |
|
|
127
|
+
| Advanced Forms | 268KB | 80KB | 70% |
|
|
128
|
+
| Date Picker | Included above | 60KB | Optimized |
|
|
129
|
+
| **Total** | **488KB** | **390KB** | **20%** |
|
|
318
130
|
|
|
319
|
-
##
|
|
131
|
+
## Documentation
|
|
320
132
|
|
|
321
|
-
|
|
133
|
+
- [Component API Reference](./docs/components.md)
|
|
134
|
+
- [Validation Guide](./docs/validation.md)
|
|
135
|
+
- [Migration Guide](./docs/migration.md)
|
|
136
|
+
- [Bundle Optimization](./docs/optimization.md)
|