@delightui/components 0.1.139 → 0.1.140

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/dist/index.d.ts CHANGED
@@ -2332,6 +2332,56 @@ type DropzoneContentProps = {
2332
2332
 
2333
2333
  declare const DropzoneContent: (props: DropzoneContentProps) => react_jsx_runtime.JSX.Element;
2334
2334
 
2335
+ /**
2336
+ * Custom hook to access form context values.
2337
+ * Provides direct access to all form state management functions and values.
2338
+ *
2339
+ * @throws {Error} If used outside of a Form component
2340
+ * @returns {FormContextValues} Object containing form state and control functions
2341
+ *
2342
+ * @example
2343
+ * ```tsx
2344
+ * const MyCustomField = () => {
2345
+ * const {
2346
+ * formState,
2347
+ * formErrors,
2348
+ * updateFieldValue,
2349
+ * resetForm
2350
+ * } = useForm();
2351
+ *
2352
+ * return (
2353
+ * <div>
2354
+ * <input
2355
+ * value={formState.myField || ''}
2356
+ * onChange={(e) => updateFieldValue('myField', e.target.value)}
2357
+ * />
2358
+ * {formErrors.myField && <span>{formErrors.myField}</span>}
2359
+ * </div>
2360
+ * );
2361
+ * };
2362
+ * ```
2363
+ */
2364
+ declare const useForm: <T extends FormState = Partial<Record<string, FieldValue>>>() => FormContextValues<T>;
2365
+ /**
2366
+ * Type-safe version of useForm that returns properly typed form context
2367
+ *
2368
+ * @example
2369
+ * ```tsx
2370
+ * interface MyFormData {
2371
+ * name: string;
2372
+ * email: string;
2373
+ * age: number;
2374
+ * }
2375
+ *
2376
+ * const MyComponent = () => {
2377
+ * const form = useFormTyped<MyFormData>();
2378
+ * // form.formState is now typed as MyFormData
2379
+ * // form.formErrors is now typed as FormErrors<MyFormData>
2380
+ * };
2381
+ * ```
2382
+ */
2383
+ declare const useFormTyped: <T extends FormState>() => FormContextValues<T>;
2384
+
2335
2385
  declare const Form: <T extends FormState>(props: FormProviderProps<T> & FormProps) => react_jsx_runtime.JSX.Element;
2336
2386
 
2337
2387
  type TableProps = TableHTMLAttributes<HTMLTableElement> & {
@@ -2689,4 +2739,4 @@ declare const NotificationContext: React__default.Context<NotificationContextVal
2689
2739
  declare const NotificationProvider: React__default.FC<NotificationProviderProps>;
2690
2740
  declare const useNotification: () => NotificationContextValue;
2691
2741
 
2692
- export { type AccessibilityActions, type AccessibilityProps, Accordion, AccordionDetails, AccordionGroup, AccordionSummary, ActionCard, type ActionCardProps, ActionImage, type ActionImageProps, Breadcrumb, type BreadcrumbProps, Breadcrumbs, type BreadcrumbsProps, Breakpoint, type BreakpointProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, Card, type CardProps, Checkbox, CheckboxItem, type CheckboxItemProps, type CheckboxLabelAlignmentEnum, type CheckboxProps, type CheckboxSizeEnum, type CheckboxTypeEnum, Chip, ChipInput, type ChipInputProps, type ChipProps, ConditionalView, type ConditionalViewProps, ContextMenu, type ContextMenuProps, type CustomTimePickerConfig, CustomToggle, type CustomToggleProps, DatePicker, type DatePickerProps, SortableItem as DraggableItem, SortableTrigger as DraggableItemTrigger, Dropzone, DropzoneClear, DropzoneContent, type DropzoneContentProps, type DropzoneContentTypeEnum, DropzoneFilename, DropzoneFilename as DropzonePreview, type DropzoneProps, DropzoneSupportedFormats as DropzoneReject, DropzoneTrigger as DropzoneRoot, DropzoneSupportedFormats, DropzoneTrigger, type FieldValidationFunction, type FieldValidators, type FieldValue, Form, type FormContextValues, type FormErrors, FormField, type FormFieldProps, type FormProps, type FormProviderProps, type FormState, type FormStateChangeHandler, type FormSubmitHandler, type FormValidator, Grid, GridItem, type GridItemProps, GridList, type GridListProps, type GridProps, Icon, IconButton, type IconButtonProps, type IconButtonStyleEnum, type IconProps, type IconSizeEnum, type IconStyleEnum, Image, type ImageFitEnum, type ImageProps, Input, type InputProps, type InputTypeEnum, List, ListItem, type ListItemProps$1 as ListItemProps, type ListProps, Modal, type ModalComponentProps, ModalFooter, type ModalFooterProps, ModalHeader, type ModalHeaderProps, type ModalProps, ModalProvider, type ModalProviderProps, Nav, NavItem, type NavItemProps, NavLink, type NavLinkProps, type NavProps, type Notification, type NotificationContainerProps, NotificationContext, type NotificationOffset, type NotificationPosition, NotificationProvider, type NotificationTrigger, Option, type OptionLike, type OptionLikeKey, type OptionProps, type OverlayDirectionEnum, Pagination, PaginationNumberField, type PaginationNumberFieldProps, type PaginationProps, Password, Popover, type PopoverHandle, type PopoverProps, ProgressBar, type ProgressBarProps, RadioButton, RadioButtonItem, type RadioButtonItemProps, type RadioButtonLabelAlignmentEnum, type RadioButtonProps, type RadioButtonSizeEnum, RadioGroup, type RadioGroupProps, RenderStateView, type RenderStateViewProps, RepeaterList, type RepeaterListProps, type RequiredFields, ResponsiveComponent, type ResponsiveComponentProps, Search, type SearchCallback, type SearchStyleEnum as SearchModeEnum, type SearchProps, Select, SelectListItem, type SelectListItemProps, type SelectProps, SelectProvider, SlideOutPanel, type SlideOutPanelDirectionEnum, type SlideOutPanelProps, type SlideOutPanelSizeEnum, Slider, type SliderProps, Spinner, type SpinnerProps, TabContent, type TabContentProps, TabItem, type TabItemProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHeader, TableHeaderCell, type TableHeaderCellProps, type TableHeaderProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsProps, Text, TextArea, type TextAreaProps, type TextDecorationEnum, type TextProps, type TextTypeEnum, type TextWeightEnum, ThemeContext, type ThemeContextType, ThemeProvider, type ThemeProviderProps, Toggle, ToggleButton, type ToggleButtonProps, type ToggleLabelAlignmentEnum, type ToggleProps, Tooltip, type TooltipProps, type TriggerNotificationPayload, type UseModalReturn, WrapTextNodes, type WrapTextNodesProps, applyPropsToChildren, getClickAccessibilityProps, mergeRefs, useDebounce, useDropzoneContext, useInflateView, useModal, useNotification, useSelectContext, useTab };
2742
+ export { type AccessibilityActions, type AccessibilityProps, Accordion, AccordionDetails, AccordionGroup, AccordionSummary, ActionCard, type ActionCardProps, ActionImage, type ActionImageProps, Breadcrumb, type BreadcrumbProps, Breadcrumbs, type BreadcrumbsProps, Breakpoint, type BreakpointProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, Card, type CardProps, Checkbox, CheckboxItem, type CheckboxItemProps, type CheckboxLabelAlignmentEnum, type CheckboxProps, type CheckboxSizeEnum, type CheckboxTypeEnum, Chip, ChipInput, type ChipInputProps, type ChipProps, ConditionalView, type ConditionalViewProps, ContextMenu, type ContextMenuProps, type CustomTimePickerConfig, CustomToggle, type CustomToggleProps, DatePicker, type DatePickerProps, SortableItem as DraggableItem, SortableTrigger as DraggableItemTrigger, Dropzone, DropzoneClear, DropzoneContent, type DropzoneContentProps, type DropzoneContentTypeEnum, DropzoneFilename, DropzoneFilename as DropzonePreview, type DropzoneProps, DropzoneSupportedFormats as DropzoneReject, DropzoneTrigger as DropzoneRoot, DropzoneSupportedFormats, DropzoneTrigger, type FieldValidationFunction, type FieldValidators, type FieldValue, Form, type FormContextValues, type FormErrors, FormField, type FormFieldProps, type FormProps, type FormProviderProps, type FormState, type FormStateChangeHandler, type FormSubmitHandler, type FormValidator, Grid, GridItem, type GridItemProps, GridList, type GridListProps, type GridProps, Icon, IconButton, type IconButtonProps, type IconButtonStyleEnum, type IconProps, type IconSizeEnum, type IconStyleEnum, Image, type ImageFitEnum, type ImageProps, Input, type InputProps, type InputTypeEnum, List, ListItem, type ListItemProps$1 as ListItemProps, type ListProps, Modal, type ModalComponentProps, ModalFooter, type ModalFooterProps, ModalHeader, type ModalHeaderProps, type ModalProps, ModalProvider, type ModalProviderProps, Nav, NavItem, type NavItemProps, NavLink, type NavLinkProps, type NavProps, type Notification, type NotificationContainerProps, NotificationContext, type NotificationOffset, type NotificationPosition, NotificationProvider, type NotificationTrigger, Option, type OptionLike, type OptionLikeKey, type OptionProps, type OverlayDirectionEnum, Pagination, PaginationNumberField, type PaginationNumberFieldProps, type PaginationProps, Password, Popover, type PopoverHandle, type PopoverProps, ProgressBar, type ProgressBarProps, RadioButton, RadioButtonItem, type RadioButtonItemProps, type RadioButtonLabelAlignmentEnum, type RadioButtonProps, type RadioButtonSizeEnum, RadioGroup, type RadioGroupProps, RenderStateView, type RenderStateViewProps, RepeaterList, type RepeaterListProps, type RequiredFields, ResponsiveComponent, type ResponsiveComponentProps, Search, type SearchCallback, type SearchStyleEnum as SearchModeEnum, type SearchProps, Select, SelectListItem, type SelectListItemProps, type SelectProps, SelectProvider, SlideOutPanel, type SlideOutPanelDirectionEnum, type SlideOutPanelProps, type SlideOutPanelSizeEnum, Slider, type SliderProps, Spinner, type SpinnerProps, TabContent, type TabContentProps, TabItem, type TabItemProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHeader, TableHeaderCell, type TableHeaderCellProps, type TableHeaderProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsProps, Text, TextArea, type TextAreaProps, type TextDecorationEnum, type TextProps, type TextTypeEnum, type TextWeightEnum, ThemeContext, type ThemeContextType, ThemeProvider, type ThemeProviderProps, Toggle, ToggleButton, type ToggleButtonProps, type ToggleLabelAlignmentEnum, type ToggleProps, Tooltip, type TooltipProps, type TriggerNotificationPayload, type UseModalReturn, WrapTextNodes, type WrapTextNodesProps, applyPropsToChildren, getClickAccessibilityProps, mergeRefs, useDebounce, useDropzoneContext, useForm, useFormTyped, useInflateView, useModal, useNotification, useSelectContext, useTab };
@@ -0,0 +1,248 @@
1
+ # useForm Hook
2
+
3
+ A custom React hook that provides direct access to form context values and controls within the Form component.
4
+
5
+ ## Overview
6
+
7
+ The `useForm` hook allows components to directly interact with the form's state management system without going through the `FormField` wrapper. This is useful for creating custom form controls, debugging tools, or implementing complex form logic.
8
+
9
+ ## Installation
10
+
11
+ ```tsx
12
+ import { useForm } from '@delightui/components';
13
+ ```
14
+
15
+ ## API
16
+
17
+ ### `useForm<T>()`
18
+
19
+ Returns the complete form context with all state and control functions.
20
+
21
+ #### Return Value
22
+
23
+ ```typescript
24
+ {
25
+ formRef: RefObject<HTMLFormElement>;
26
+ formState: T;
27
+ formErrors: FormErrors<T>;
28
+ updateFieldValue: (name: string, value: FieldValue) => void;
29
+ updateFieldError: (name: keyof T, error: string) => void;
30
+ updateFieldValidators: (name: keyof T, validate?: FieldValidationFunction) => void;
31
+ updateRequiredFields: (name: keyof T, required?: boolean) => void;
32
+ onFormSubmit: FormEventHandler<HTMLFormElement>;
33
+ resetForm: () => void;
34
+ }
35
+ ```
36
+
37
+ ### Properties
38
+
39
+ | Property | Type | Description |
40
+ |----------|------|-------------|
41
+ | `formRef` | `RefObject<HTMLFormElement>` | Reference to the form element |
42
+ | `formState` | `T` | Current values of all form fields |
43
+ | `formErrors` | `FormErrors<T>` | Current validation errors for each field |
44
+ | `updateFieldValue` | `Function` | Updates a specific field's value |
45
+ | `updateFieldError` | `Function` | Sets an error message for a field |
46
+ | `updateFieldValidators` | `Function` | Registers validation function for a field |
47
+ | `updateRequiredFields` | `Function` | Marks a field as required/optional |
48
+ | `onFormSubmit` | `Function` | Form submission handler |
49
+ | `resetForm` | `Function` | Resets form to initial state |
50
+
51
+ ## Usage Examples
52
+
53
+ ### Basic Usage
54
+
55
+ ```tsx
56
+ import { useForm, Form } from '@delightui/components';
57
+
58
+ const MyCustomField = () => {
59
+ const { formState, updateFieldValue } = useForm();
60
+
61
+ return (
62
+ <input
63
+ value={formState.myField || ''}
64
+ onChange={(e) => updateFieldValue('myField', e.target.value)}
65
+ />
66
+ );
67
+ };
68
+
69
+ // Usage within Form
70
+ <Form formState={{ myField: '' }}>
71
+ <MyCustomField />
72
+ </Form>
73
+ ```
74
+
75
+ ### Type-Safe Usage
76
+
77
+ ```tsx
78
+ interface MyFormData {
79
+ username: string;
80
+ email: string;
81
+ age: number;
82
+ }
83
+
84
+ const MyComponent = () => {
85
+ const { formState, formErrors, updateFieldValue } = useForm<MyFormData>();
86
+
87
+ return (
88
+ <div>
89
+ <input
90
+ value={formState.username || ''}
91
+ onChange={(e) => updateFieldValue('username', e.target.value)}
92
+ />
93
+ {formErrors.username && <span>{formErrors.username}</span>}
94
+ </div>
95
+ );
96
+ };
97
+ ```
98
+
99
+ ### Custom Validation
100
+
101
+ ```tsx
102
+ const CustomValidatedField = () => {
103
+ const { updateFieldValidators, updateFieldValue } = useForm();
104
+
105
+ useEffect(() => {
106
+ // Register custom validation
107
+ updateFieldValidators('customField', (setError, value) => {
108
+ if (value && value.length < 5) {
109
+ setError('Must be at least 5 characters');
110
+ return false;
111
+ }
112
+ return true;
113
+ });
114
+
115
+ // Cleanup on unmount
116
+ return () => updateFieldValidators('customField', undefined);
117
+ }, [updateFieldValidators]);
118
+
119
+ return (
120
+ <input onChange={(e) => updateFieldValue('customField', e.target.value)} />
121
+ );
122
+ };
123
+ ```
124
+
125
+ ### Form Debugging Component
126
+
127
+ ```tsx
128
+ const FormDebugger = () => {
129
+ const { formState, formErrors, resetForm } = useForm();
130
+
131
+ return (
132
+ <div style={{ padding: '1rem', background: '#f0f0f0' }}>
133
+ <h4>Form State:</h4>
134
+ <pre>{JSON.stringify(formState, null, 2)}</pre>
135
+
136
+ <h4>Form Errors:</h4>
137
+ <pre>{JSON.stringify(formErrors, null, 2)}</pre>
138
+
139
+ <button onClick={resetForm}>Reset Form</button>
140
+ </div>
141
+ );
142
+ };
143
+ ```
144
+
145
+ ### Dynamic Field Management
146
+
147
+ ```tsx
148
+ const DynamicFieldManager = () => {
149
+ const { formState, updateFieldValue, updateRequiredFields } = useForm();
150
+ const [fields, setFields] = useState<string[]>([]);
151
+
152
+ const addField = () => {
153
+ const fieldName = `field_${fields.length}`;
154
+ setFields([...fields, fieldName]);
155
+ updateFieldValue(fieldName, '');
156
+ updateRequiredFields(fieldName, true);
157
+ };
158
+
159
+ return (
160
+ <div>
161
+ {fields.map(field => (
162
+ <input
163
+ key={field}
164
+ value={formState[field] || ''}
165
+ onChange={(e) => updateFieldValue(field, e.target.value)}
166
+ />
167
+ ))}
168
+ <button onClick={addField}>Add Field</button>
169
+ </div>
170
+ );
171
+ };
172
+ ```
173
+
174
+ ## When to Use
175
+
176
+ Use `useForm` when you need:
177
+
178
+ - **Custom form controls** that require direct access to form state
179
+ - **Complex validation logic** that spans multiple fields
180
+ - **Dynamic field management** with programmatic control
181
+ - **Form debugging tools** or state visualization
182
+ - **Integration with third-party components** that don't work with FormField
183
+
184
+ ## Best Practices
185
+
186
+ 1. **Always use within Form**: The hook must be used inside a Form component
187
+ 2. **Clean up validators**: Remove validators when components unmount
188
+ 3. **Type your form data**: Use generics for type-safe form state
189
+ 4. **Prefer FormField for standard inputs**: Use FormField when possible for automatic integration
190
+ 5. **Handle errors gracefully**: Check for context availability in reusable components
191
+
192
+ ## Comparison with FormField
193
+
194
+ | Feature | FormField | useForm |
195
+ |---------|-----------|---------|
196
+ | Automatic validation | ✅ | ❌ (manual) |
197
+ | Error display | ✅ | ❌ (manual) |
198
+ | Required field handling | ✅ | ❌ (manual) |
199
+ | Direct state access | ❌ | ✅ |
200
+ | Custom logic flexibility | Limited | Full |
201
+ | Setup complexity | Low | Medium |
202
+
203
+ ## Error Handling
204
+
205
+ The hook will throw an error if used outside a Form component:
206
+
207
+ ```tsx
208
+ // ❌ This will throw an error
209
+ const MyComponent = () => {
210
+ const form = useForm(); // Error: useForm must be used within a Form component
211
+ return <div>...</div>;
212
+ };
213
+
214
+ // ✅ Correct usage
215
+ const MyComponent = () => {
216
+ return (
217
+ <Form>
218
+ <MyFormContent />
219
+ </Form>
220
+ );
221
+ };
222
+
223
+ const MyFormContent = () => {
224
+ const form = useForm(); // Works!
225
+ return <div>...</div>;
226
+ };
227
+ ```
228
+
229
+ ## TypeScript Support
230
+
231
+ The hook is fully typed and supports generic type parameters:
232
+
233
+ ```tsx
234
+ // Basic usage (untyped)
235
+ const form = useForm();
236
+
237
+ // Typed usage
238
+ const form = useForm<MyFormData>();
239
+
240
+ // Alternative typed version
241
+ const form = useFormTyped<MyFormData>();
242
+ ```
243
+
244
+ ## Related
245
+
246
+ - [Form Component](../components/organisms/Form.md)
247
+ - [FormField Component](../components/molecules/FormField.md)
248
+ - [Form Validation Guide](../guides/form-validation.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delightui/components",
3
- "version": "0.1.139",
3
+ "version": "0.1.140",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "start": "vite",