@tachui/forms 0.7.0-alpha1 → 0.7.1-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 +321 -0
- package/dist/TextField-CGBM3x7K.js +1799 -0
- package/dist/components/index.js +25 -28
- package/dist/index.js +79 -81
- package/dist/state/index.js +240 -7
- package/dist/validation/index.js +598 -19
- package/package.json +5 -6
- package/dist/Form-ueYEcSg1.cjs +0 -2
- package/dist/Form-ueYEcSg1.cjs.map +0 -1
- package/dist/Form-ylAr3o_e.js +0 -376
- package/dist/Form-ylAr3o_e.js.map +0 -1
- package/dist/components/index.cjs +0 -2
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/forms-complex-BiQsZZlT.js +0 -361
- package/dist/forms-complex-BiQsZZlT.js.map +0 -1
- package/dist/forms-complex-DLEnXXJ5.cjs +0 -2
- package/dist/forms-complex-DLEnXXJ5.cjs.map +0 -1
- package/dist/forms-core-B1bx1drO.js +0 -839
- package/dist/forms-core-B1bx1drO.js.map +0 -1
- package/dist/forms-core-W_JGVLAI.cjs +0 -9
- package/dist/forms-core-W_JGVLAI.cjs.map +0 -1
- package/dist/forms-inputs-6QdeMWFk.js +0 -1075
- package/dist/forms-inputs-6QdeMWFk.js.map +0 -1
- package/dist/forms-inputs-DQ5QI_SU.cjs +0 -2
- package/dist/forms-inputs-DQ5QI_SU.cjs.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/state/index.cjs +0 -2
- package/dist/state/index.cjs.map +0 -1
- package/dist/state/index.js.map +0 -1
- package/dist/validation/index.cjs +0 -2
- package/dist/validation/index.cjs.map +0 -1
- package/dist/validation/index.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# @tachui/forms
|
|
2
|
+
|
|
3
|
+
> Advanced form components and validation system for tachUI framework
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@tachui/forms)
|
|
6
|
+
[](https://opensource.org/licenses/MPL-2.0)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
The tachUI forms package provides advanced form components, validation utilities, and form state management that extends the core tachUI framework with powerful form-building capabilities.
|
|
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
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @tachui/core @tachui/forms
|
|
25
|
+
# or
|
|
26
|
+
pnpm add @tachui/core @tachui/forms
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { VStack, Button } from '@tachui/core'
|
|
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
|
+
```
|
|
86
|
+
|
|
87
|
+
## Components
|
|
88
|
+
|
|
89
|
+
### TextField
|
|
90
|
+
|
|
91
|
+
Advanced text input with validation and formatting:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { TextField } from '@tachui/forms'
|
|
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
|
+
```
|
|
103
|
+
|
|
104
|
+
### Select & Picker
|
|
105
|
+
|
|
106
|
+
Dropdown selections with search and multi-select:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { Select, Picker } from '@tachui/forms'
|
|
110
|
+
|
|
111
|
+
Select('Category', categories, selectedCategory)
|
|
112
|
+
.modifier.searchable(true)
|
|
113
|
+
.placeholder('Choose category')
|
|
114
|
+
.build()
|
|
115
|
+
|
|
116
|
+
Picker('Colors', colors, selectedColors)
|
|
117
|
+
.modifier.multiSelect(true)
|
|
118
|
+
.displayStyle('compact')
|
|
119
|
+
.build()
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Checkbox & Radio
|
|
123
|
+
|
|
124
|
+
Selection controls with grouping:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { Checkbox, RadioGroup } from '@tachui/forms'
|
|
128
|
+
|
|
129
|
+
Checkbox('Accept Terms', acceptedBinding).modifier.required(true).build()
|
|
130
|
+
|
|
131
|
+
RadioGroup('Size', sizeOptions, selectedSize)
|
|
132
|
+
.modifier.layout('horizontal')
|
|
133
|
+
.build()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Form State Management
|
|
137
|
+
|
|
138
|
+
### Creating Form State
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { createFormState } from '@tachui/forms'
|
|
142
|
+
|
|
143
|
+
const userForm = createFormState(
|
|
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
|
+
```
|
|
169
|
+
|
|
170
|
+
### Form Bindings
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
// Two-way data binding
|
|
174
|
+
const nameBinding = userForm.binding('firstName')
|
|
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
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Form Validation
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
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
|
+
```
|
|
205
|
+
|
|
206
|
+
## Advanced Features
|
|
207
|
+
|
|
208
|
+
### Custom Validation
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { createValidator } from '@tachui/forms'
|
|
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
|
+
```
|
|
225
|
+
|
|
226
|
+
### Form Schemas
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { createFormSchema } from '@tachui/forms'
|
|
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
|
+
},
|
|
248
|
+
})
|
|
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
|
+
```
|
|
285
|
+
|
|
286
|
+
## Accessibility
|
|
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
|
|
316
|
+
|
|
317
|
+
See the main [Contributing Guide](https://github.com/tach-UI/tachUI/blob/main/CONTRIBUTING.md) for information on contributing to tachUI forms.
|
|
318
|
+
|
|
319
|
+
## License
|
|
320
|
+
|
|
321
|
+
Mozilla Public License 2.0 - see [LICENSE](https://github.com/tach-UI/tachUI/blob/main/LICENSE) for details.
|