@delightui/components 0.1.162-alpha.2 → 0.1.162-alpha.3
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/cjs/components/molecules/FormField/FormField.types.d.ts +35 -9
- package/dist/cjs/components/organisms/Form/Form.presenter.d.ts +2 -2
- package/dist/cjs/components/organisms/Form/Form.types.d.ts +80 -2
- package/dist/cjs/library.js +2 -2
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/molecules/FormField/FormField.types.d.ts +35 -9
- package/dist/esm/components/organisms/Form/Form.presenter.d.ts +2 -2
- package/dist/esm/components/organisms/Form/Form.types.d.ts +80 -2
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +116 -12
- package/package.json +1 -1
|
@@ -56,6 +56,32 @@ export type FieldValidationFunction<TValue = FieldValue> = (value: TValue) => st
|
|
|
56
56
|
* Returns error message string if invalid, undefined if valid
|
|
57
57
|
*/
|
|
58
58
|
export type AsyncFieldValidationFunction<TValue = FieldValue> = (value: TValue) => Promise<string | undefined>;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
61
|
+
* Use the new FieldValidationFunction signature that returns error messages instead.
|
|
62
|
+
*
|
|
63
|
+
* Type representing a validation function for a form field
|
|
64
|
+
* It takes an error setter function and the field value (optional) and returns a boolean indicating if the value is valid
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const nameValidator: LegacyFieldValidationFunction = (setError, value) => {
|
|
68
|
+
* if (!value) {
|
|
69
|
+
* setError('Name is required');
|
|
70
|
+
* return false;
|
|
71
|
+
* }
|
|
72
|
+
* return true;
|
|
73
|
+
* };
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export type LegacyFieldValidationFunction<T extends FieldValue = FieldValue> = (setError: (message: string) => void, value?: T) => boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
79
|
+
* Use the new AsyncFieldValidationFunction signature that returns error messages instead.
|
|
80
|
+
*
|
|
81
|
+
* Type representing an async validation function for a form field
|
|
82
|
+
* It takes an error setter function and the field value (optional) and returns a Promise<boolean> indicating if the value is valid
|
|
83
|
+
*/
|
|
84
|
+
export type LegacyAsyncFieldValidationFunction<T extends FieldValue = FieldValue> = (setError: (message: string) => void, value?: T) => Promise<boolean>;
|
|
59
85
|
/**
|
|
60
86
|
* FormField component props for use within a Form
|
|
61
87
|
*/
|
|
@@ -73,10 +99,10 @@ export type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName
|
|
|
73
99
|
children: ReactNode;
|
|
74
100
|
/** Field is required */
|
|
75
101
|
required?: boolean;
|
|
76
|
-
/** Sync validation function */
|
|
77
|
-
validate?: FieldValidationFunction<PathValue<TFieldValues, TName>>;
|
|
78
|
-
/** Async validation function */
|
|
79
|
-
asyncValidate?: AsyncFieldValidationFunction<PathValue<TFieldValues, TName>>;
|
|
102
|
+
/** Sync validation function (supports both new and legacy signatures) */
|
|
103
|
+
validate?: FieldValidationFunction<PathValue<TFieldValues, TName>> | LegacyFieldValidationFunction<PathValue<TFieldValues, TName>>;
|
|
104
|
+
/** Async validation function (supports both new and legacy signatures) */
|
|
105
|
+
asyncValidate?: AsyncFieldValidationFunction<PathValue<TFieldValues, TName>> | LegacyAsyncFieldValidationFunction<PathValue<TFieldValues, TName>>;
|
|
80
106
|
/** Default value for this field */
|
|
81
107
|
defaultValue?: PathValue<TFieldValues, TName>;
|
|
82
108
|
/** Info message to display */
|
|
@@ -95,7 +121,7 @@ export type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName
|
|
|
95
121
|
/**
|
|
96
122
|
* Standalone FormField props (works without Form context)
|
|
97
123
|
*/
|
|
98
|
-
export type StandaloneFieldProps<TValue = FieldValue> = Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'children' | 'onChange'> & {
|
|
124
|
+
export type StandaloneFieldProps<TValue extends FieldValue = FieldValue> = Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'children' | 'onChange'> & {
|
|
99
125
|
/** Field name */
|
|
100
126
|
name: string;
|
|
101
127
|
/** Field label */
|
|
@@ -106,10 +132,10 @@ export type StandaloneFieldProps<TValue = FieldValue> = Omit<HTMLAttributes<HTML
|
|
|
106
132
|
children: ReactNode;
|
|
107
133
|
/** Field is required */
|
|
108
134
|
required?: boolean;
|
|
109
|
-
/** Sync validation function */
|
|
110
|
-
validate?: FieldValidationFunction<TValue>;
|
|
111
|
-
/** Async validation function */
|
|
112
|
-
asyncValidate?: AsyncFieldValidationFunction<TValue>;
|
|
135
|
+
/** Sync validation function (supports both new and legacy signatures) */
|
|
136
|
+
validate?: FieldValidationFunction<TValue> | LegacyFieldValidationFunction<TValue>;
|
|
137
|
+
/** Async validation function (supports both new and legacy signatures) */
|
|
138
|
+
asyncValidate?: AsyncFieldValidationFunction<TValue> | LegacyAsyncFieldValidationFunction<TValue>;
|
|
113
139
|
/** Controlled value */
|
|
114
140
|
value?: TValue;
|
|
115
141
|
/** Controlled onChange */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FieldValues } from 'react-hook-form';
|
|
2
|
-
import type { FormProps } from './Form.types';
|
|
2
|
+
import type { FormProps, FormSubmitHandler } from './Form.types';
|
|
3
3
|
/**
|
|
4
4
|
* Presenter hook for Form component
|
|
5
5
|
* Handles RHF initialization and form state management
|
|
@@ -8,7 +8,7 @@ declare const usePresenter: <TFormValues extends FieldValues = FieldValues>(prop
|
|
|
8
8
|
methods: import("react-hook-form").UseFormReturn<TFormValues, any, TFormValues>;
|
|
9
9
|
onFormSubmit: import("react").FormEventHandler<HTMLFormElement>;
|
|
10
10
|
autosave: boolean;
|
|
11
|
-
onSubmit: import("./Form.types").
|
|
11
|
+
onSubmit: FormSubmitHandler<TFormValues> | import("./Form.types").LegacyFormSubmitHandler<TFormValues> | undefined;
|
|
12
12
|
autosaveDelayMs: number;
|
|
13
13
|
variantProps: {
|
|
14
14
|
'component-variant': string;
|
|
@@ -5,14 +5,75 @@ export type { FieldValue, FieldValidationFunction, AsyncFieldValidationFunction,
|
|
|
5
5
|
* Form submission handler
|
|
6
6
|
*/
|
|
7
7
|
export type FormSubmitHandler<TFormValues extends FieldValues = FieldValues> = (values: TFormValues) => void | Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
10
|
+
* Use the new FormSubmitHandler signature without setError instead.
|
|
11
|
+
*
|
|
12
|
+
* Type representing a function that handles form submission.
|
|
13
|
+
* It takes updated form state and a function to set error messages for specific fields.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type of the form state, defaulting to FieldValues.
|
|
16
|
+
*
|
|
17
|
+
* @param {T} values - The updated form state values.
|
|
18
|
+
* @param {(field: keyof T, errorMessage: string) => void} setError - A function to set error messages for specific fields.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const handleFormSubmit: LegacyFormSubmitHandler = (values, setError) => {
|
|
23
|
+
* // Submit form data
|
|
24
|
+
* console.log(values);
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type LegacyFormSubmitHandler<T extends FieldValues = FieldValues> = (values: T, setError: (field: keyof T, errorMessage: string) => void) => void | Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
31
|
+
* Use React Hook Form's built-in validation or field-level validation instead.
|
|
32
|
+
*
|
|
33
|
+
* Type representing a function that handles form state changes
|
|
34
|
+
* It takes the new form state and an error setter function and doesn't return anything
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const handleFormStateChange: FormStateChangeHandler = (state, setError) => {
|
|
38
|
+
* // Validate form state and set errors
|
|
39
|
+
* if (!state.name) {
|
|
40
|
+
* setError('name', 'Name is required');
|
|
41
|
+
* }
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type FormStateChangeHandler<T extends FieldValues = FieldValues> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => void;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
48
|
+
* Use React Hook Form's resolver or field-level validation instead.
|
|
49
|
+
*
|
|
50
|
+
* Type representing a function that validates the entire form
|
|
51
|
+
* It takes the form values and an error setter function and returns a boolean indicating if the form is valid
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const validateForm: FormValidator = (state, setError) => {
|
|
55
|
+
* let isValid = true;
|
|
56
|
+
* if (!state.name) {
|
|
57
|
+
* setError('name', 'Name is required');
|
|
58
|
+
* isValid = false;
|
|
59
|
+
* }
|
|
60
|
+
* if (!state.age || typeof state.age !== 'number') {
|
|
61
|
+
* setError('age', 'Age must be a number');
|
|
62
|
+
* isValid = false;
|
|
63
|
+
* }
|
|
64
|
+
* return isValid;
|
|
65
|
+
* };
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export type FormValidator<T extends FieldValues = FieldValues> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => boolean;
|
|
8
69
|
/**
|
|
9
70
|
* Form component props
|
|
10
71
|
*/
|
|
11
72
|
export type FormProps<TFormValues extends FieldValues = FieldValues> = Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'ref'> & {
|
|
12
73
|
/** Initial form values (uncontrolled mode) */
|
|
13
74
|
defaultValues?: UseFormProps<TFormValues>['defaultValues'];
|
|
14
|
-
/** Form submission handler - receives typed form values */
|
|
15
|
-
onSubmit?: FormSubmitHandler<TFormValues>;
|
|
75
|
+
/** Form submission handler - receives typed form values (supports both new and legacy signatures) */
|
|
76
|
+
onSubmit?: FormSubmitHandler<TFormValues> | LegacyFormSubmitHandler<TFormValues>;
|
|
16
77
|
/** Enable autosave functionality */
|
|
17
78
|
autosave?: boolean;
|
|
18
79
|
/** Autosave debounce delay in milliseconds */
|
|
@@ -23,6 +84,23 @@ export type FormProps<TFormValues extends FieldValues = FieldValues> = Omit<Form
|
|
|
23
84
|
formOptions?: Omit<UseFormProps<TFormValues>, 'defaultValues' | 'mode'>;
|
|
24
85
|
/** Ref to the form element */
|
|
25
86
|
formRef?: React.Ref<HTMLFormElement>;
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Use defaultValues instead. This prop is maintained for backwards compatibility only.
|
|
89
|
+
* Alias for defaultValues - initial form values
|
|
90
|
+
*/
|
|
91
|
+
formState?: UseFormProps<TFormValues>['defaultValues'];
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Use React Hook Form's useWatch hook or field-level validation instead.
|
|
94
|
+
* This prop is maintained for backwards compatibility only.
|
|
95
|
+
* Callback fired whenever form values change
|
|
96
|
+
*/
|
|
97
|
+
onFormStateChange?: FormStateChangeHandler<TFormValues>;
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated Use React Hook Form's resolver or field-level validation instead.
|
|
100
|
+
* This prop is maintained for backwards compatibility only.
|
|
101
|
+
* Custom validator function for the entire form
|
|
102
|
+
*/
|
|
103
|
+
formValidator?: FormValidator<TFormValues>;
|
|
26
104
|
};
|
|
27
105
|
/**
|
|
28
106
|
* @deprecated Use FormProps instead
|