@ultraviolet/form 2.13.2 → 2.13.4
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/components/CheckboxField/index.d.ts +10 -0
- package/dist/components/CheckboxField/index.js +17 -35
- package/dist/components/CheckboxGroupField/index.d.ts +32 -0
- package/dist/components/CheckboxGroupField/index.js +24 -35
- package/dist/components/DateField/index.d.ts +16 -0
- package/dist/components/DateField/index.js +33 -53
- package/dist/components/Form/defaultErrors.d.ts +2 -0
- package/dist/components/Form/defaultErrors.js +20 -19
- package/dist/components/Form/index.d.ts +69 -0
- package/dist/components/Form/index.js +41 -54
- package/dist/components/KeyValueField/index.d.ts +33 -0
- package/dist/components/KeyValueField/index.js +23 -56
- package/dist/components/NumberInputField/index.d.ts +13 -0
- package/dist/components/NumberInputField/index.js +18 -39
- package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
- package/dist/components/NumberInputFieldV2/index.js +20 -46
- package/dist/components/RadioField/index.d.ts +12 -0
- package/dist/components/RadioField/index.js +18 -36
- package/dist/components/RadioGroupField/index.d.ts +28 -0
- package/dist/components/RadioGroupField/index.js +15 -26
- package/dist/components/SelectInputField/index.d.ts +82 -0
- package/dist/components/SelectInputField/index.js +31 -61
- package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
- package/dist/components/SelectInputFieldV2/index.js +18 -52
- package/dist/components/SelectableCardField/index.d.ts +9 -0
- package/dist/components/SelectableCardField/index.js +24 -41
- package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
- package/dist/components/SelectableCardGroupField/index.js +22 -35
- package/dist/components/Submit/index.d.ts +17 -0
- package/dist/components/Submit/index.js +9 -23
- package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
- package/dist/components/SubmitErrorAlert/index.js +7 -11
- package/dist/components/TagInputField/index.d.ts +6 -0
- package/dist/components/TagInputField/index.js +14 -32
- package/dist/components/TextAreaField/index.d.ts +11 -0
- package/dist/components/TextAreaField/index.js +25 -52
- package/dist/components/TextInputField/index.d.ts +18 -0
- package/dist/components/TextInputField/index.js +37 -76
- package/dist/components/TextInputFieldV2/index.d.ts +12 -0
- package/dist/components/TextInputFieldV2/index.js +30 -66
- package/dist/components/TimeField/index.d.ts +9 -0
- package/dist/components/TimeField/index.js +23 -46
- package/dist/components/ToggleField/index.d.ts +10 -0
- package/dist/components/ToggleField/index.js +15 -28
- package/dist/components/ToggleGroupField/index.d.ts +26 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -3
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useField.d.ts +34 -0
- package/dist/hooks/useField.js +4 -20
- package/dist/hooks/useFieldArray.d.ts +21 -0
- package/dist/hooks/useFieldArray.js +6 -9
- package/dist/hooks/useForm.d.ts +23 -0
- package/dist/hooks/useForm.js +7 -19
- package/dist/hooks/useFormState.d.ts +39 -0
- package/dist/hooks/useFormState.js +5 -20
- package/dist/hooks/useOnFieldChange.d.ts +3 -0
- package/dist/hooks/useOnFieldChange.js +6 -6
- package/dist/index.d.ts +7 -555
- package/dist/index.js +66 -29
- package/dist/mocks/index.d.ts +1 -0
- package/dist/mocks/mockErrors.d.ts +3 -0
- package/dist/providers/ErrorContext/index.d.ts +14 -0
- package/dist/providers/ErrorContext/index.js +11 -13
- package/dist/providers/index.d.ts +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/validators/index.d.ts +5 -0
- package/dist/validators/maxDate.d.ts +1 -0
- package/dist/validators/maxDate.js +4 -3
- package/dist/validators/minDate.d.ts +1 -0
- package/dist/validators/minDate.js +4 -3
- package/package.json +12 -6
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FieldValues } from 'react-hook-form';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use [useFormContext](https://www.react-hook-form.com/api/useformcontext/)
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const Input = () {
|
|
9
|
+
* const { setValue } = useFormContext()
|
|
10
|
+
*
|
|
11
|
+
* setValue('username', 'John Wick')
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const useFormDeprecated: <TFieldValues extends FieldValues>() => {
|
|
16
|
+
change: import("react-hook-form").UseFormSetValue<TFieldValues>;
|
|
17
|
+
resetFieldState: import("react-hook-form").UseFormResetField<TFieldValues>;
|
|
18
|
+
getFieldState: import("react-hook-form").UseFormGetFieldState<TFieldValues>;
|
|
19
|
+
batch: (callback: () => void) => void;
|
|
20
|
+
restart: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
21
|
+
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
22
|
+
submit: (e?: import("react").BaseSyntheticEvent<object, any, any> | undefined) => Promise<void>;
|
|
23
|
+
};
|
package/dist/hooks/useForm.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { useFormContext } from
|
|
3
|
-
import { FormSubmitContext } from
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use [useFormContext](https://www.react-hook-form.com/api/useformcontext/)
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* const Input = () {
|
|
11
|
-
* const { setValue } = useFormContext()
|
|
12
|
-
*
|
|
13
|
-
* setValue('username', 'John Wick')
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { FormSubmitContext } from "../components/Form/index.js";
|
|
17
4
|
const useFormDeprecated = () => {
|
|
18
5
|
const {
|
|
19
6
|
setValue,
|
|
@@ -26,11 +13,12 @@ const useFormDeprecated = () => {
|
|
|
26
13
|
change: setValue,
|
|
27
14
|
resetFieldState: resetField,
|
|
28
15
|
getFieldState,
|
|
29
|
-
batch: callback => callback(),
|
|
16
|
+
batch: (callback) => callback(),
|
|
30
17
|
restart: reset,
|
|
31
18
|
reset,
|
|
32
19
|
submit: formSubmitContext.handleSubmit
|
|
33
20
|
};
|
|
34
21
|
};
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
export {
|
|
23
|
+
useFormDeprecated
|
|
24
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FieldValues } from 'react-hook-form';
|
|
2
|
+
type UseFormStateParams = {
|
|
3
|
+
subscription?: Record<string, boolean>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use [useForm](https://www.react-hook-form.com/api/useform/), [useFormContext](https://www.react-hook-form.com/api/useformcontext/) or [useWatch](https://www.react-hook-form.com/api/usewatch/) to get values. Use [useFormState](https://www.react-hook-form.com/api/useformstate/) to get form states.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const Input = () {
|
|
11
|
+
* const username = useWatch({
|
|
12
|
+
* name: 'username'
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* const { isValid } = useFormState()
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
export declare const useFormStateDeprecated: <TFieldValues extends FieldValues>(_params?: UseFormStateParams) => {
|
|
21
|
+
dirtySinceLastSubmit: boolean;
|
|
22
|
+
submitErrors: (Record<string, Partial<{
|
|
23
|
+
type: string | number;
|
|
24
|
+
message: string;
|
|
25
|
+
}>> & Partial<{
|
|
26
|
+
type: string | number;
|
|
27
|
+
message: string;
|
|
28
|
+
}>) | undefined;
|
|
29
|
+
values: TFieldValues;
|
|
30
|
+
hasValidationErrors: boolean;
|
|
31
|
+
pristine: boolean;
|
|
32
|
+
errors: import("react-hook-form").FieldErrors<TFieldValues>;
|
|
33
|
+
initialValues: Readonly<import("react-hook-form").DeepPartial<TFieldValues>> | undefined;
|
|
34
|
+
touched: Partial<Readonly<import("react-hook-form").DeepMap<import("react-hook-form").DeepPartial<TFieldValues>, boolean>>>;
|
|
35
|
+
submitting: boolean;
|
|
36
|
+
invalid: boolean;
|
|
37
|
+
valid: boolean;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import { useFormContext, useWatch } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use [useForm](https://www.react-hook-form.com/api/useform/), [useFormContext](https://www.react-hook-form.com/api/useformcontext/) or [useWatch](https://www.react-hook-form.com/api/usewatch/) to get values. Use [useFormState](https://www.react-hook-form.com/api/useformstate/) to get form states.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* const Input = () {
|
|
9
|
-
* const username = useWatch({
|
|
10
|
-
* name: 'username'
|
|
11
|
-
* })
|
|
12
|
-
*
|
|
13
|
-
* const { isValid } = useFormState()
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
const useFormStateDeprecated = _params => {
|
|
1
|
+
import { useFormContext, useWatch } from "react-hook-form";
|
|
2
|
+
const useFormStateDeprecated = (_params) => {
|
|
19
3
|
const {
|
|
20
4
|
formState
|
|
21
5
|
} = useFormContext();
|
|
@@ -33,5 +17,6 @@ const useFormStateDeprecated = _params => {
|
|
|
33
17
|
valid: formState.isValid
|
|
34
18
|
};
|
|
35
19
|
};
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
export {
|
|
21
|
+
useFormStateDeprecated
|
|
22
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DeepPartial, FieldPath, FieldPathValue, FieldValues } from 'react-hook-form';
|
|
2
|
+
export type CallbackFn<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = (value: FieldPathValue<TFieldValues, TFieldName>, values: DeepPartial<TFieldValues>) => void | Promise<void>;
|
|
3
|
+
export declare const useOnFieldChange: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>>(fieldName: TFieldName, callback: CallbackFn<TFieldValues, TFieldName>, enabled?: boolean) => void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useRef, useEffect } from
|
|
2
|
-
import { useFormContext } from
|
|
3
|
-
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
4
3
|
const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
5
4
|
const {
|
|
6
5
|
watch,
|
|
@@ -8,7 +7,7 @@ const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
|
8
7
|
} = useFormContext();
|
|
9
8
|
const previousValues = useRef(getValues(fieldName));
|
|
10
9
|
useEffect(() => {
|
|
11
|
-
const subscription = watch(value => {
|
|
10
|
+
const subscription = watch((value) => {
|
|
12
11
|
if (previousValues.current !== value[fieldName] && enabled) {
|
|
13
12
|
previousValues.current = value[fieldName];
|
|
14
13
|
callback(value[fieldName], value)?.catch(() => null);
|
|
@@ -17,5 +16,6 @@ const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
|
17
16
|
return () => subscription.unsubscribe();
|
|
18
17
|
}, [callback, enabled, watch, getValues, fieldName]);
|
|
19
18
|
};
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export {
|
|
20
|
+
useOnFieldChange
|
|
21
|
+
};
|