@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.
Files changed (90) hide show
  1. package/README.md +87 -272
  2. package/dist/DatePicker-D5nRFTUm.js +475 -0
  3. package/dist/DatePicker-D5nRFTUm.js.map +1 -0
  4. package/dist/Select-yZyKooXk.js +945 -0
  5. package/dist/Select-yZyKooXk.js.map +1 -0
  6. package/dist/Slider-0-oal5YR.js +644 -0
  7. package/dist/Slider-0-oal5YR.js.map +1 -0
  8. package/dist/TextField-hX15dY3U.js +509 -0
  9. package/dist/TextField-hX15dY3U.js.map +1 -0
  10. package/dist/components/advanced/Slider.d.ts +190 -0
  11. package/dist/components/advanced/Slider.d.ts.map +1 -0
  12. package/dist/components/advanced/Stepper.d.ts +161 -0
  13. package/dist/components/advanced/Stepper.d.ts.map +1 -0
  14. package/dist/components/advanced/index.d.ts +15 -0
  15. package/dist/components/advanced/index.d.ts.map +1 -0
  16. package/dist/components/advanced/index.js +6 -0
  17. package/dist/components/advanced/index.js.map +1 -0
  18. package/dist/components/date-picker/DatePicker.d.ts +126 -0
  19. package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
  20. package/dist/components/date-picker/index.d.ts +14 -0
  21. package/dist/components/date-picker/index.d.ts.map +1 -0
  22. package/dist/components/date-picker/index.js +5 -0
  23. package/dist/components/date-picker/index.js.map +1 -0
  24. package/dist/components/form-container/index.d.ts +58 -0
  25. package/dist/components/form-container/index.d.ts.map +1 -0
  26. package/dist/components/selection/Checkbox.d.ts.map +1 -0
  27. package/dist/components/selection/Radio.d.ts.map +1 -0
  28. package/dist/components/selection/Select.d.ts.map +1 -0
  29. package/dist/components/selection/index.d.ts +68 -0
  30. package/dist/components/selection/index.d.ts.map +1 -0
  31. package/dist/components/selection/index.js +12 -0
  32. package/dist/components/selection/index.js.map +1 -0
  33. package/dist/components/text-input/TextField.d.ts.map +1 -0
  34. package/dist/components/text-input/index.d.ts +8 -0
  35. package/dist/components/text-input/index.d.ts.map +1 -0
  36. package/dist/components/text-input/index.js +18 -0
  37. package/dist/components/text-input/index.js.map +1 -0
  38. package/dist/{state/index.js → index-D3WfkqVv.js} +15 -8
  39. package/dist/index-D3WfkqVv.js.map +1 -0
  40. package/dist/index.d.ts +10 -15
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +198 -376
  43. package/dist/index.js.map +1 -0
  44. package/dist/state/index.d.ts.map +1 -1
  45. package/dist/types/index.d.ts.map +1 -1
  46. package/dist/utils/index.d.ts +19 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/validation/component-validation.d.ts +11 -2
  49. package/dist/validation/component-validation.d.ts.map +1 -1
  50. package/dist/validation/index.d.ts.map +1 -1
  51. package/dist/validation/index.js +282 -191
  52. package/dist/validation/index.js.map +1 -0
  53. package/package.json +53 -39
  54. package/src/components/advanced/Slider.ts +722 -0
  55. package/src/components/advanced/Stepper.ts +715 -0
  56. package/src/components/advanced/index.ts +20 -0
  57. package/src/components/date-picker/DatePicker.ts +925 -0
  58. package/src/components/date-picker/index.ts +20 -0
  59. package/src/components/form-container/index.ts +266 -0
  60. package/src/components/selection/Checkbox.ts +478 -0
  61. package/src/components/selection/Radio.ts +470 -0
  62. package/src/components/selection/Select.ts +620 -0
  63. package/src/components/selection/index.ts +81 -0
  64. package/src/components/text-input/TextField.ts +728 -0
  65. package/src/components/text-input/index.ts +35 -0
  66. package/src/index.ts +48 -0
  67. package/src/state/index.ts +544 -0
  68. package/src/types/index.ts +579 -0
  69. package/src/utils/formatters.ts +184 -0
  70. package/src/utils/index.ts +57 -0
  71. package/src/validation/component-validation.ts +429 -0
  72. package/src/validation/index.ts +641 -0
  73. package/dist/TextField-CGBM3x7K.js +0 -1799
  74. package/dist/components/Form.d.ts +0 -76
  75. package/dist/components/Form.d.ts.map +0 -1
  76. package/dist/components/index.d.ts +0 -9
  77. package/dist/components/index.d.ts.map +0 -1
  78. package/dist/components/index.js +0 -28
  79. package/dist/components/input/Checkbox.d.ts.map +0 -1
  80. package/dist/components/input/Radio.d.ts.map +0 -1
  81. package/dist/components/input/Select.d.ts.map +0 -1
  82. package/dist/components/input/TextField.d.ts.map +0 -1
  83. package/dist/components/input/index.d.ts +0 -11
  84. package/dist/components/input/index.d.ts.map +0 -1
  85. package/dist/utils/validators.d.ts +0 -101
  86. package/dist/utils/validators.d.ts.map +0 -1
  87. /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
  88. /package/dist/components/{input → selection}/Radio.d.ts +0 -0
  89. /package/dist/components/{input → selection}/Select.d.ts +0 -0
  90. /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Date Picker Component
3
+ *
4
+ * Rich calendar interface for date selection from @tachui/advanced-forms
5
+ */
6
+
7
+ // Import and re-export the complete DatePicker implementation
8
+ export { DatePicker } from './DatePicker'
9
+
10
+ // Export types
11
+ export type {
12
+ DatePickerProps,
13
+ DatePickerDisplayComponents,
14
+ DatePickerStyle,
15
+ } from './DatePicker'
16
+
17
+ // Legacy type aliases for backwards compatibility
18
+ export type DatePickerValue = Date | Date[] | { start: Date; end: Date }
19
+ export type DatePickerMode = 'single' | 'range' | 'multiple'
20
+ export type CalendarDate = Date
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Form Container Components
3
+ *
4
+ * Core form structure and state management components
5
+ */
6
+
7
+ import { createSignal, createComputed } from '@tachui/core'
8
+ import { createFormState } from '../../state'
9
+ import type { FormState, FormSubmitHandler, FieldValidation } from '../../types'
10
+
11
+ export interface FormProps {
12
+ onSubmit?: FormSubmitHandler
13
+ validation?: Record<string, FieldValidation>
14
+ initialValues?: Record<string, any>
15
+ children?: any
16
+ className?: string
17
+ id?: string
18
+ resetOnSubmit?: boolean
19
+ validateOnSubmit?: boolean
20
+ [key: string]: any
21
+ }
22
+
23
+ export interface FormSectionProps {
24
+ title?: string
25
+ description?: string
26
+ children?: any
27
+ className?: string
28
+ collapsible?: boolean
29
+ defaultExpanded?: boolean
30
+ [key: string]: any
31
+ }
32
+
33
+ export class Form {
34
+ readonly type = 'form-container'
35
+ private formState: ReturnType<typeof createFormState>
36
+
37
+ constructor(public readonly properties: FormProps) {
38
+ this.formState = createFormState(properties.initialValues || {})
39
+
40
+ // Register field validations
41
+ if (properties.validation) {
42
+ Object.entries(properties.validation).forEach(
43
+ ([fieldName, validation]) => {
44
+ this.formState.register(fieldName, validation)
45
+ }
46
+ )
47
+ }
48
+ }
49
+
50
+ get state(): FormState {
51
+ return this.formState.state
52
+ }
53
+
54
+ async handleSubmit(): Promise<void> {
55
+ if (this.properties.validateOnSubmit !== false) {
56
+ const isValid = await this.formState.validateForm()
57
+ if (!isValid) {
58
+ return
59
+ }
60
+ }
61
+
62
+ if (this.properties.onSubmit) {
63
+ await this.properties.onSubmit(
64
+ this.formState.watch(),
65
+ this.formState.state
66
+ )
67
+ }
68
+
69
+ if (this.properties.resetOnSubmit) {
70
+ this.formState.resetForm()
71
+ }
72
+ }
73
+
74
+ register(fieldName: string, validation?: FieldValidation): void {
75
+ this.formState.register(fieldName, validation)
76
+ }
77
+
78
+ setValue(fieldName: string, value: any): void {
79
+ this.formState.setValue(fieldName, value)
80
+ }
81
+
82
+ getValue(fieldName: string): any {
83
+ return this.formState.getValue(fieldName)
84
+ }
85
+
86
+ getError(fieldName: string): string | undefined {
87
+ return this.formState.getError(fieldName)
88
+ }
89
+
90
+ async validateField(fieldName: string): Promise<boolean> {
91
+ return this.formState.validateField(fieldName)
92
+ }
93
+
94
+ async validateForm(): Promise<boolean> {
95
+ return this.formState.validateForm()
96
+ }
97
+
98
+ resetForm(): void {
99
+ this.formState.resetForm()
100
+ }
101
+
102
+ render(): HTMLElement {
103
+ const element = document.createElement('form')
104
+
105
+ // Set form attributes
106
+ if (this.properties.className) {
107
+ element.className = this.properties.className
108
+ }
109
+ if (this.properties.id) {
110
+ element.id = this.properties.id
111
+ }
112
+
113
+ // Prevent default form submission
114
+ element.addEventListener('submit', e => {
115
+ e.preventDefault()
116
+ this.handleSubmit()
117
+ })
118
+
119
+ // Add children if provided
120
+ if (this.properties.children) {
121
+ if (Array.isArray(this.properties.children)) {
122
+ this.properties.children.forEach(child => {
123
+ if (typeof child === 'string') {
124
+ element.appendChild(document.createTextNode(child))
125
+ } else if (child && typeof child.render === 'function') {
126
+ element.appendChild(child.render())
127
+ } else if (child instanceof HTMLElement) {
128
+ element.appendChild(child)
129
+ }
130
+ })
131
+ } else if (typeof this.properties.children === 'string') {
132
+ element.appendChild(document.createTextNode(this.properties.children))
133
+ } else if (
134
+ this.properties.children &&
135
+ typeof this.properties.children.render === 'function'
136
+ ) {
137
+ element.appendChild(this.properties.children.render())
138
+ } else if (this.properties.children instanceof HTMLElement) {
139
+ element.appendChild(this.properties.children)
140
+ }
141
+ }
142
+
143
+ return element
144
+ }
145
+ }
146
+
147
+ export class FormSection {
148
+ readonly type = 'form-section'
149
+ private expanded: () => boolean
150
+ private setExpanded: (value: boolean) => void
151
+
152
+ constructor(public readonly properties: FormSectionProps) {
153
+ const [expandedSignal, setExpandedSignal] = createSignal(
154
+ properties.defaultExpanded ?? true
155
+ )
156
+ this.expanded = expandedSignal
157
+ this.setExpanded = setExpandedSignal
158
+ }
159
+
160
+ get isExpanded(): boolean {
161
+ return this.expanded()
162
+ }
163
+
164
+ toggle(): void {
165
+ if (this.properties.collapsible) {
166
+ this.setExpanded(!this.expanded())
167
+ }
168
+ }
169
+
170
+ expand(): void {
171
+ this.setExpanded(true)
172
+ }
173
+
174
+ collapse(): void {
175
+ if (this.properties.collapsible) {
176
+ this.setExpanded(false)
177
+ }
178
+ }
179
+
180
+ render(): HTMLElement {
181
+ const section = document.createElement('section')
182
+
183
+ if (this.properties.className) {
184
+ section.className = this.properties.className
185
+ }
186
+
187
+ // Add title if provided
188
+ if (this.properties.title) {
189
+ const title = document.createElement('h3')
190
+ title.textContent = this.properties.title
191
+ title.style.cssText = 'margin: 0 0 1rem 0; font-weight: 600;'
192
+
193
+ if (this.properties.collapsible) {
194
+ title.style.cursor = 'pointer'
195
+ title.addEventListener('click', () => this.toggle())
196
+
197
+ const indicator = document.createElement('span')
198
+ indicator.textContent = this.expanded() ? ' ▼' : ' ▶'
199
+ indicator.style.cssText = 'font-size: 0.8em; margin-left: 0.5rem;'
200
+ title.appendChild(indicator)
201
+
202
+ // Update indicator when expanded state changes
203
+ createComputed(() => {
204
+ indicator.textContent = this.expanded() ? ' ▼' : ' ▶'
205
+ })
206
+ }
207
+
208
+ section.appendChild(title)
209
+ }
210
+
211
+ // Add description if provided
212
+ if (this.properties.description) {
213
+ const description = document.createElement('p')
214
+ description.textContent = this.properties.description
215
+ description.style.cssText =
216
+ 'margin: 0 0 1rem 0; color: #666; font-size: 0.9em;'
217
+ section.appendChild(description)
218
+ }
219
+
220
+ // Add content container
221
+ const content = document.createElement('div')
222
+
223
+ // Handle collapsible behavior
224
+ createComputed(() => {
225
+ content.style.display = this.expanded() ? 'block' : 'none'
226
+ })
227
+
228
+ // Add children if provided
229
+ if (this.properties.children) {
230
+ if (Array.isArray(this.properties.children)) {
231
+ this.properties.children.forEach(child => {
232
+ if (typeof child === 'string') {
233
+ content.appendChild(document.createTextNode(child))
234
+ } else if (child && typeof child.render === 'function') {
235
+ content.appendChild(child.render())
236
+ } else if (child instanceof HTMLElement) {
237
+ content.appendChild(child)
238
+ }
239
+ })
240
+ } else if (typeof this.properties.children === 'string') {
241
+ content.appendChild(document.createTextNode(this.properties.children))
242
+ } else if (
243
+ this.properties.children &&
244
+ typeof this.properties.children.render === 'function'
245
+ ) {
246
+ content.appendChild(this.properties.children.render())
247
+ } else if (this.properties.children instanceof HTMLElement) {
248
+ content.appendChild(this.properties.children)
249
+ }
250
+ }
251
+
252
+ section.appendChild(content)
253
+ return section
254
+ }
255
+ }
256
+
257
+ export function form(props: FormProps): Form {
258
+ return new Form(props)
259
+ }
260
+
261
+ export function formSection(props: FormSectionProps): FormSection {
262
+ return new FormSection(props)
263
+ }
264
+
265
+ // Re-export types for convenience
266
+ export type { FormState, FormSubmitHandler, FieldValidation }