@ultraviolet/form 2.14.7 → 3.0.0
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.cjs +5 -3
- package/dist/components/CheckboxField/index.d.ts +2 -2
- package/dist/components/CheckboxField/index.js +5 -3
- package/dist/components/CheckboxGroupField/index.cjs +12 -8
- package/dist/components/CheckboxGroupField/index.d.ts +2 -2
- package/dist/components/CheckboxGroupField/index.js +8 -4
- package/dist/components/DateField/index.cjs +7 -6
- package/dist/components/DateField/index.d.ts +2 -2
- package/dist/components/DateField/index.js +7 -6
- package/dist/components/Form/index.cjs +7 -47
- package/dist/components/Form/index.d.ts +8 -64
- package/dist/components/Form/index.js +9 -47
- package/dist/components/NumberInputField/index.cjs +5 -3
- package/dist/components/NumberInputField/index.d.ts +2 -2
- package/dist/components/NumberInputField/index.js +5 -3
- package/dist/components/NumberInputFieldV2/index.cjs +5 -3
- package/dist/components/NumberInputFieldV2/index.d.ts +2 -4
- package/dist/components/NumberInputFieldV2/index.js +5 -3
- package/dist/components/RadioField/index.cjs +5 -3
- package/dist/components/RadioField/index.d.ts +2 -2
- package/dist/components/RadioField/index.js +5 -3
- package/dist/components/RadioGroupField/index.cjs +5 -3
- package/dist/components/RadioGroupField/index.d.ts +2 -2
- package/dist/components/RadioGroupField/index.js +5 -3
- package/dist/components/SelectInputField/index.cjs +7 -7
- package/dist/components/SelectInputField/index.d.ts +2 -2
- package/dist/components/SelectInputField/index.js +3 -3
- package/dist/components/SelectInputFieldV2/index.cjs +7 -5
- package/dist/components/SelectInputFieldV2/index.d.ts +2 -2
- package/dist/components/SelectInputFieldV2/index.js +5 -3
- package/dist/components/SelectableCardField/index.cjs +4 -2
- package/dist/components/SelectableCardField/index.d.ts +2 -2
- package/dist/components/SelectableCardField/index.js +4 -2
- package/dist/components/SelectableCardGroupField/index.cjs +5 -3
- package/dist/components/SelectableCardGroupField/index.d.ts +2 -2
- package/dist/components/SelectableCardGroupField/index.js +5 -3
- package/dist/components/TagInputField/index.cjs +5 -3
- package/dist/components/TagInputField/index.d.ts +2 -2
- package/dist/components/TagInputField/index.js +5 -3
- package/dist/components/TextAreaField/index.cjs +6 -3
- package/dist/components/TextAreaField/index.d.ts +2 -2
- package/dist/components/TextAreaField/index.js +6 -3
- package/dist/components/TextInputField/index.cjs +15 -14
- package/dist/components/TextInputField/index.d.ts +2 -2
- package/dist/components/TextInputField/index.js +15 -14
- package/dist/components/TextInputFieldV2/index.cjs +6 -3
- package/dist/components/TextInputFieldV2/index.d.ts +2 -2
- package/dist/components/TextInputFieldV2/index.js +6 -3
- package/dist/components/TimeField/index.cjs +5 -3
- package/dist/components/TimeField/index.d.ts +2 -4
- package/dist/components/TimeField/index.js +5 -3
- package/dist/components/ToggleField/index.cjs +5 -3
- package/dist/components/ToggleField/index.d.ts +2 -2
- package/dist/components/ToggleField/index.js +5 -3
- package/dist/components/ToggleGroupField/index.d.ts +2 -2
- package/dist/components/UnitInputField/index.cjs +4 -4
- package/dist/components/UnitInputField/index.d.ts +2 -2
- package/dist/components/UnitInputField/index.js +4 -4
- package/dist/components/index.d.ts +0 -1
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/useOnFieldChange.cjs +3 -3
- package/dist/hooks/useOnFieldChange.d.ts +3 -0
- package/dist/index.cjs +8 -18
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -11
- package/dist/providers/ErrorContext/index.cjs +5 -5
- package/dist/types.d.ts +7 -10
- package/dist/utils/validateRegex.cjs +4 -0
- package/dist/utils/validateRegex.d.ts +2 -0
- package/dist/utils/validateRegex.js +4 -0
- package/package.json +2 -2
- package/dist/constants.cjs +0 -4
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -4
- package/dist/hooks/useField.cjs +0 -30
- package/dist/hooks/useField.d.ts +0 -34
- package/dist/hooks/useField.js +0 -30
- package/dist/hooks/useFieldArray.cjs +0 -32
- package/dist/hooks/useFieldArray.d.ts +0 -21
- package/dist/hooks/useFieldArray.js +0 -32
- package/dist/hooks/useForm.cjs +0 -24
- package/dist/hooks/useForm.d.ts +0 -22
- package/dist/hooks/useForm.js +0 -24
- package/dist/hooks/useFormState.cjs +0 -22
- package/dist/hooks/useFormState.d.ts +0 -39
- package/dist/hooks/useFormState.js +0 -22
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const constants = require("./constants.cjs");
|
|
4
3
|
const index = require("./providers/ErrorContext/index.cjs");
|
|
5
4
|
const reactHookForm = require("react-hook-form");
|
|
6
|
-
const useFormState = require("./hooks/useFormState.cjs");
|
|
7
|
-
const useField = require("./hooks/useField.cjs");
|
|
8
|
-
const useForm = require("./hooks/useForm.cjs");
|
|
9
|
-
const useFieldArray = require("./hooks/useFieldArray.cjs");
|
|
10
5
|
const useOnFieldChange = require("./hooks/useOnFieldChange.cjs");
|
|
11
|
-
const index$1 = require("./components/
|
|
12
|
-
const index$2 = require("./components/
|
|
13
|
-
const index$3 = require("./components/
|
|
14
|
-
const index$4 = require("./components/
|
|
6
|
+
const index$1 = require("./components/Form/index.cjs");
|
|
7
|
+
const index$2 = require("./components/CheckboxField/index.cjs");
|
|
8
|
+
const index$3 = require("./components/CheckboxGroupField/index.cjs");
|
|
9
|
+
const index$4 = require("./components/DateField/index.cjs");
|
|
15
10
|
const index$5 = require("./components/RadioField/index.cjs");
|
|
16
11
|
const index$6 = require("./components/SelectInputField/index.cjs");
|
|
17
12
|
const index$7 = require("./components/SelectableCardField/index.cjs");
|
|
@@ -30,7 +25,6 @@ const index$j = require("./components/KeyValueField/index.cjs");
|
|
|
30
25
|
const index$k = require("./components/SelectableCardGroupField/index.cjs");
|
|
31
26
|
const index$l = require("./components/SelectInputFieldV2/index.cjs");
|
|
32
27
|
const index$m = require("./components/UnitInputField/index.cjs");
|
|
33
|
-
exports.FORM_ERROR = constants.FORM_ERROR;
|
|
34
28
|
exports.ErrorProvider = index.ErrorProvider;
|
|
35
29
|
exports.useErrors = index.useErrors;
|
|
36
30
|
Object.defineProperty(exports, "useController", {
|
|
@@ -57,15 +51,11 @@ Object.defineProperty(exports, "useWatch", {
|
|
|
57
51
|
enumerable: true,
|
|
58
52
|
get: () => reactHookForm.useWatch
|
|
59
53
|
});
|
|
60
|
-
exports.useFormStateDeprecated = useFormState.useFormStateDeprecated;
|
|
61
|
-
exports.useFieldDeprecated = useField.useFieldDeprecated;
|
|
62
|
-
exports.useFormDeprecated = useForm.useFormDeprecated;
|
|
63
|
-
exports.useFieldArrayDeprecated = useFieldArray.useFieldArrayDeprecated;
|
|
64
54
|
exports.useOnFieldChange = useOnFieldChange.useOnFieldChange;
|
|
65
|
-
exports.
|
|
66
|
-
exports.
|
|
67
|
-
exports.
|
|
68
|
-
exports.
|
|
55
|
+
exports.Form = index$1.Form;
|
|
56
|
+
exports.CheckboxField = index$2.CheckboxField;
|
|
57
|
+
exports.CheckboxGroupField = index$3.CheckboxGroupField;
|
|
58
|
+
exports.DateField = index$4.DateField;
|
|
69
59
|
exports.RadioField = index$5.RadioField;
|
|
70
60
|
exports.SelectInputField = index$6.SelectInputField;
|
|
71
61
|
exports.SelectableCardField = index$7.SelectableCardField;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { FORM_ERROR } from './constants';
|
|
2
1
|
export * from './components';
|
|
3
2
|
export type { BaseFieldProps, FormErrors } from './types';
|
|
4
3
|
export { useErrors, ErrorProvider } from './providers/ErrorContext';
|
|
5
|
-
export {
|
|
4
|
+
export { useOnFieldChange } from './hooks';
|
|
6
5
|
export { useForm, useFieldArray, useWatch, useController, useFormState, useFormContext, } from 'react-hook-form';
|
|
7
|
-
export type
|
|
6
|
+
export type * from 'react-hook-form';
|
|
7
|
+
export { Form } from './components';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { FORM_ERROR } from "./constants.js";
|
|
2
1
|
import { ErrorProvider, useErrors } from "./providers/ErrorContext/index.js";
|
|
3
2
|
import { useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from "react-hook-form";
|
|
4
|
-
import { useFormStateDeprecated } from "./hooks/useFormState.js";
|
|
5
|
-
import { useFieldDeprecated } from "./hooks/useField.js";
|
|
6
|
-
import { useFormDeprecated } from "./hooks/useForm.js";
|
|
7
|
-
import { useFieldArrayDeprecated } from "./hooks/useFieldArray.js";
|
|
8
3
|
import { useOnFieldChange } from "./hooks/useOnFieldChange.js";
|
|
4
|
+
import { Form } from "./components/Form/index.js";
|
|
9
5
|
import { CheckboxField } from "./components/CheckboxField/index.js";
|
|
10
6
|
import { CheckboxGroupField } from "./components/CheckboxGroupField/index.js";
|
|
11
7
|
import { DateField } from "./components/DateField/index.js";
|
|
12
|
-
import { Form } from "./components/Form/index.js";
|
|
13
8
|
import { RadioField } from "./components/RadioField/index.js";
|
|
14
9
|
import { SelectInputField } from "./components/SelectInputField/index.js";
|
|
15
10
|
import { SelectableCardField } from "./components/SelectableCardField/index.js";
|
|
@@ -33,7 +28,6 @@ export {
|
|
|
33
28
|
CheckboxGroupField,
|
|
34
29
|
DateField,
|
|
35
30
|
ErrorProvider,
|
|
36
|
-
FORM_ERROR,
|
|
37
31
|
Form,
|
|
38
32
|
KeyValueField,
|
|
39
33
|
NumberInputField,
|
|
@@ -56,13 +50,9 @@ export {
|
|
|
56
50
|
useController,
|
|
57
51
|
useErrors,
|
|
58
52
|
useFieldArray,
|
|
59
|
-
useFieldArrayDeprecated,
|
|
60
|
-
useFieldDeprecated,
|
|
61
53
|
useForm,
|
|
62
54
|
useFormContext,
|
|
63
|
-
useFormDeprecated,
|
|
64
55
|
useFormState,
|
|
65
|
-
useFormStateDeprecated,
|
|
66
56
|
useOnFieldChange,
|
|
67
57
|
useWatch
|
|
68
58
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
-
const
|
|
5
|
-
const ErrorContext =
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const ErrorContext = react.createContext(void 0);
|
|
6
6
|
const ErrorProvider = ({
|
|
7
7
|
children,
|
|
8
8
|
errors
|
|
9
9
|
}) => {
|
|
10
|
-
const getError =
|
|
10
|
+
const getError = react.useCallback((meta, error) => {
|
|
11
11
|
if (!error) {
|
|
12
12
|
return void 0;
|
|
13
13
|
}
|
|
@@ -16,14 +16,14 @@ const ErrorProvider = ({
|
|
|
16
16
|
}
|
|
17
17
|
return errors?.[error.type]?.(meta);
|
|
18
18
|
}, [errors]);
|
|
19
|
-
const value =
|
|
19
|
+
const value = react.useMemo(() => ({
|
|
20
20
|
errors,
|
|
21
21
|
getError
|
|
22
22
|
}), [errors, getError]);
|
|
23
23
|
return /* @__PURE__ */ jsxRuntime.jsx(ErrorContext.Provider, { value, children });
|
|
24
24
|
};
|
|
25
25
|
const useErrors = () => {
|
|
26
|
-
const context =
|
|
26
|
+
const context = react.useContext(ErrorContext);
|
|
27
27
|
if (context === void 0) {
|
|
28
28
|
throw new Error("useErrors must be used within an ErrorProvider ");
|
|
29
29
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldError, FieldPath, FieldPathValue, FieldValues, Path, PathValue, UseControllerProps, Validate } from 'react-hook-form';
|
|
1
|
+
import type { Control, FieldError, FieldPath, FieldPathValue, FieldValues, Path, PathValue, UseControllerProps, Validate } from 'react-hook-form';
|
|
2
2
|
export type MetaField = {
|
|
3
3
|
min?: number | string;
|
|
4
4
|
max?: number | string;
|
|
@@ -16,17 +16,14 @@ export type RequiredErrors = {
|
|
|
16
16
|
export type FormErrors = {
|
|
17
17
|
[key in 'required' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'minDate' | 'maxDate']: RequiredErrors[key];
|
|
18
18
|
};
|
|
19
|
-
export type BaseFieldProps<TFieldValues extends FieldValues,
|
|
20
|
-
name:
|
|
19
|
+
export type BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
20
|
+
name: TFieldName;
|
|
21
21
|
required?: boolean;
|
|
22
|
-
validate?: Record<string, Validate<FieldPathValue<TFieldValues,
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated Use individual props instead
|
|
25
|
-
*/
|
|
26
|
-
rules?: UseControllerProps<TFieldValues>['rules'];
|
|
22
|
+
validate?: Record<string, Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues>>;
|
|
27
23
|
defaultValue?: PathValue<TFieldValues, Path<TFieldValues>>;
|
|
28
24
|
label?: string;
|
|
29
25
|
value?: PathValue<TFieldValues, Path<TFieldValues>>;
|
|
30
|
-
onChange?: (value?: PathValue<TFieldValues,
|
|
31
|
-
shouldUnregister?: UseControllerProps<TFieldValues,
|
|
26
|
+
onChange?: (value?: PathValue<TFieldValues, TFieldName>) => void;
|
|
27
|
+
shouldUnregister?: UseControllerProps<TFieldValues, TFieldName>['shouldUnregister'];
|
|
28
|
+
control?: Control<TFieldValues>;
|
|
32
29
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const validateRegex = (value, regexes) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)));
|
|
4
|
+
exports.validateRegex = validateRegex;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@emotion/styled": "11.11.5",
|
|
73
73
|
"react-select": "5.8.0",
|
|
74
74
|
"react-hook-form": "7.52.0",
|
|
75
|
-
"@ultraviolet/ui": "1.57.
|
|
75
|
+
"@ultraviolet/ui": "1.57.1",
|
|
76
76
|
"@ultraviolet/themes": "1.12.1"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
package/dist/constants.cjs
DELETED
package/dist/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const FORM_ERROR = "FINAL_FORM/form-error";
|
package/dist/constants.js
DELETED
package/dist/hooks/useField.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const reactHookForm = require("react-hook-form");
|
|
4
|
-
const useFieldDeprecated = (name, options) => {
|
|
5
|
-
const {
|
|
6
|
-
getValues
|
|
7
|
-
} = reactHookForm.useFormContext();
|
|
8
|
-
const {
|
|
9
|
-
field,
|
|
10
|
-
fieldState
|
|
11
|
-
} = reactHookForm.useController({
|
|
12
|
-
name,
|
|
13
|
-
rules: {
|
|
14
|
-
validate: options?.validate
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return {
|
|
18
|
-
input: {
|
|
19
|
-
value: getValues(name),
|
|
20
|
-
onChange: field.onChange
|
|
21
|
-
},
|
|
22
|
-
meta: {
|
|
23
|
-
error: fieldState.error?.message,
|
|
24
|
-
touched: fieldState.isTouched,
|
|
25
|
-
invalid: fieldState.invalid,
|
|
26
|
-
dirty: fieldState.isDirty
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
exports.useFieldDeprecated = useFieldDeprecated;
|
package/dist/hooks/useField.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { FieldPath, FieldPathValue, FieldValues, Path, Validate } from 'react-hook-form';
|
|
2
|
-
type Options<TFieldValues extends FieldValues> = {
|
|
3
|
-
subscription?: Record<string, boolean>;
|
|
4
|
-
validate?: Validate<FieldPathValue<TFieldValues, Path<TFieldValues>>, TFieldValues>;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* @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 fields states.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const Input = () {
|
|
12
|
-
* const username = useWatch({
|
|
13
|
-
* name: 'username'
|
|
14
|
-
* })
|
|
15
|
-
*
|
|
16
|
-
* const { errors } = useFormState()
|
|
17
|
-
*
|
|
18
|
-
* console.log(errors.username)
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const useFieldDeprecated: <T, TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: Options<TFieldValues>) => {
|
|
23
|
-
input: {
|
|
24
|
-
value: T;
|
|
25
|
-
onChange: (...event: any[]) => void;
|
|
26
|
-
};
|
|
27
|
-
meta: {
|
|
28
|
-
error: string | undefined;
|
|
29
|
-
touched: boolean;
|
|
30
|
-
invalid: boolean;
|
|
31
|
-
dirty: boolean;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
export {};
|
package/dist/hooks/useField.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useFormContext, useController } from "react-hook-form";
|
|
2
|
-
const useFieldDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
4
|
-
getValues
|
|
5
|
-
} = useFormContext();
|
|
6
|
-
const {
|
|
7
|
-
field,
|
|
8
|
-
fieldState
|
|
9
|
-
} = useController({
|
|
10
|
-
name,
|
|
11
|
-
rules: {
|
|
12
|
-
validate: options?.validate
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
input: {
|
|
17
|
-
value: getValues(name),
|
|
18
|
-
onChange: field.onChange
|
|
19
|
-
},
|
|
20
|
-
meta: {
|
|
21
|
-
error: fieldState.error?.message,
|
|
22
|
-
touched: fieldState.isTouched,
|
|
23
|
-
invalid: fieldState.invalid,
|
|
24
|
-
dirty: fieldState.isDirty
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
useFieldDeprecated
|
|
30
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const reactHookForm = require("react-hook-form");
|
|
4
|
-
const useFieldArrayDeprecated = (name, options) => {
|
|
5
|
-
const {
|
|
6
|
-
fields,
|
|
7
|
-
append,
|
|
8
|
-
remove,
|
|
9
|
-
update,
|
|
10
|
-
move
|
|
11
|
-
} = reactHookForm.useFieldArray({
|
|
12
|
-
name,
|
|
13
|
-
rules: {
|
|
14
|
-
validate: options?.validate
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const value = reactHookForm.useWatch({
|
|
18
|
-
name
|
|
19
|
-
});
|
|
20
|
-
return {
|
|
21
|
-
fields: {
|
|
22
|
-
push: append,
|
|
23
|
-
value,
|
|
24
|
-
remove,
|
|
25
|
-
update,
|
|
26
|
-
map: (callback) => fields.map((_, index) => callback(`${name}.${index}`, index)),
|
|
27
|
-
move,
|
|
28
|
-
length: fields.length
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.useFieldArrayDeprecated = useFieldArrayDeprecated;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { ArrayPath, FieldArray, FieldValues, Validate } from 'react-hook-form';
|
|
3
|
-
type Options<TFieldValues extends FieldValues> = {
|
|
4
|
-
validate?: Validate<FieldArray<TFieldValues>[], TFieldValues>;
|
|
5
|
-
subscription?: Record<string, boolean>;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use [useFieldArray](https://www.react-hook-form.com/api/usefieldarray/)
|
|
9
|
-
*/
|
|
10
|
-
export declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = FieldValues>(name: ArrayPath<TFieldValues>, options?: Options<TFieldValues>) => {
|
|
11
|
-
fields: {
|
|
12
|
-
push: import("react-hook-form").UseFieldArrayAppend<TFieldValues, ArrayPath<TFieldValues>>;
|
|
13
|
-
value: T[];
|
|
14
|
-
remove: import("react-hook-form").UseFieldArrayRemove;
|
|
15
|
-
update: import("react-hook-form").UseFieldArrayUpdate<TFieldValues, ArrayPath<TFieldValues>>;
|
|
16
|
-
map: (callback: (name: string, index: number) => ReactNode) => ReactNode[];
|
|
17
|
-
move: import("react-hook-form").UseFieldArrayMove;
|
|
18
|
-
length: number;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useFieldArray, useWatch } from "react-hook-form";
|
|
2
|
-
const useFieldArrayDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
4
|
-
fields,
|
|
5
|
-
append,
|
|
6
|
-
remove,
|
|
7
|
-
update,
|
|
8
|
-
move
|
|
9
|
-
} = useFieldArray({
|
|
10
|
-
name,
|
|
11
|
-
rules: {
|
|
12
|
-
validate: options?.validate
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
const value = useWatch({
|
|
16
|
-
name
|
|
17
|
-
});
|
|
18
|
-
return {
|
|
19
|
-
fields: {
|
|
20
|
-
push: append,
|
|
21
|
-
value,
|
|
22
|
-
remove,
|
|
23
|
-
update,
|
|
24
|
-
map: (callback) => fields.map((_, index) => callback(`${name}.${index}`, index)),
|
|
25
|
-
move,
|
|
26
|
-
length: fields.length
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
useFieldArrayDeprecated
|
|
32
|
-
};
|
package/dist/hooks/useForm.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const reactHookForm = require("react-hook-form");
|
|
5
|
-
const index = require("../components/Form/index.cjs");
|
|
6
|
-
const useFormDeprecated = () => {
|
|
7
|
-
const {
|
|
8
|
-
setValue,
|
|
9
|
-
resetField,
|
|
10
|
-
getFieldState,
|
|
11
|
-
reset
|
|
12
|
-
} = reactHookForm.useFormContext();
|
|
13
|
-
const formSubmitContext = React.useContext(index.FormSubmitContext);
|
|
14
|
-
return {
|
|
15
|
-
change: setValue,
|
|
16
|
-
resetFieldState: resetField,
|
|
17
|
-
getFieldState,
|
|
18
|
-
batch: (callback) => callback(),
|
|
19
|
-
restart: reset,
|
|
20
|
-
reset,
|
|
21
|
-
submit: formSubmitContext.handleSubmit
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
exports.useFormDeprecated = useFormDeprecated;
|
package/dist/hooks/useForm.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { FieldValues } from 'react-hook-form';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Use [useFormContext](https://www.react-hook-form.com/api/useformcontext/)
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```tsx
|
|
7
|
-
* const Input = () {
|
|
8
|
-
* const { setValue } = useFormContext()
|
|
9
|
-
*
|
|
10
|
-
* setValue('username', 'John Wick')
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare const useFormDeprecated: <TFieldValues extends FieldValues>() => {
|
|
15
|
-
change: import("react-hook-form").UseFormSetValue<TFieldValues>;
|
|
16
|
-
resetFieldState: import("react-hook-form").UseFormResetField<TFieldValues>;
|
|
17
|
-
getFieldState: import("react-hook-form").UseFormGetFieldState<TFieldValues>;
|
|
18
|
-
batch: (callback: () => void) => void;
|
|
19
|
-
restart: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
20
|
-
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
21
|
-
submit: (e?: import("react").BaseSyntheticEvent) => Promise<void>;
|
|
22
|
-
};
|
package/dist/hooks/useForm.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { useFormContext } from "react-hook-form";
|
|
3
|
-
import { FormSubmitContext } from "../components/Form/index.js";
|
|
4
|
-
const useFormDeprecated = () => {
|
|
5
|
-
const {
|
|
6
|
-
setValue,
|
|
7
|
-
resetField,
|
|
8
|
-
getFieldState,
|
|
9
|
-
reset
|
|
10
|
-
} = useFormContext();
|
|
11
|
-
const formSubmitContext = useContext(FormSubmitContext);
|
|
12
|
-
return {
|
|
13
|
-
change: setValue,
|
|
14
|
-
resetFieldState: resetField,
|
|
15
|
-
getFieldState,
|
|
16
|
-
batch: (callback) => callback(),
|
|
17
|
-
restart: reset,
|
|
18
|
-
reset,
|
|
19
|
-
submit: formSubmitContext.handleSubmit
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
useFormDeprecated
|
|
24
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const reactHookForm = require("react-hook-form");
|
|
4
|
-
const useFormStateDeprecated = (_params) => {
|
|
5
|
-
const {
|
|
6
|
-
formState
|
|
7
|
-
} = reactHookForm.useFormContext();
|
|
8
|
-
return {
|
|
9
|
-
dirtySinceLastSubmit: formState.isDirty,
|
|
10
|
-
submitErrors: formState.errors.root,
|
|
11
|
-
values: reactHookForm.useWatch(),
|
|
12
|
-
hasValidationErrors: !formState.isValid,
|
|
13
|
-
pristine: !formState.isDirty,
|
|
14
|
-
errors: formState.errors,
|
|
15
|
-
initialValues: formState.defaultValues,
|
|
16
|
-
touched: formState.touchedFields,
|
|
17
|
-
submitting: formState.isSubmitting,
|
|
18
|
-
invalid: !formState.isValid,
|
|
19
|
-
valid: formState.isValid
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
exports.useFormStateDeprecated = useFormStateDeprecated;
|
|
@@ -1,39 +0,0 @@
|
|
|
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: import("react-hook-form").Message;
|
|
25
|
-
}>> & Partial<{
|
|
26
|
-
type: string | number;
|
|
27
|
-
message: import("react-hook-form").Message;
|
|
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,22 +0,0 @@
|
|
|
1
|
-
import { useFormContext, useWatch } from "react-hook-form";
|
|
2
|
-
const useFormStateDeprecated = (_params) => {
|
|
3
|
-
const {
|
|
4
|
-
formState
|
|
5
|
-
} = useFormContext();
|
|
6
|
-
return {
|
|
7
|
-
dirtySinceLastSubmit: formState.isDirty,
|
|
8
|
-
submitErrors: formState.errors.root,
|
|
9
|
-
values: useWatch(),
|
|
10
|
-
hasValidationErrors: !formState.isValid,
|
|
11
|
-
pristine: !formState.isDirty,
|
|
12
|
-
errors: formState.errors,
|
|
13
|
-
initialValues: formState.defaultValues,
|
|
14
|
-
touched: formState.touchedFields,
|
|
15
|
-
submitting: formState.isSubmitting,
|
|
16
|
-
invalid: !formState.isValid,
|
|
17
|
-
valid: formState.isValid
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
useFormStateDeprecated
|
|
22
|
-
};
|