@ultraviolet/form 2.13.1 → 2.13.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.
Files changed (73) hide show
  1. package/dist/components/CheckboxField/index.d.ts +10 -0
  2. package/dist/components/CheckboxField/index.js +40 -41
  3. package/dist/components/CheckboxGroupField/index.d.ts +32 -0
  4. package/dist/components/CheckboxGroupField/index.js +59 -53
  5. package/dist/components/DateField/index.d.ts +16 -0
  6. package/dist/components/DateField/index.js +53 -58
  7. package/dist/components/Form/defaultErrors.d.ts +2 -0
  8. package/dist/components/Form/defaultErrors.js +20 -19
  9. package/dist/components/Form/index.d.ts +69 -0
  10. package/dist/components/Form/index.js +52 -57
  11. package/dist/components/KeyValueField/index.d.ts +33 -0
  12. package/dist/components/KeyValueField/index.js +61 -60
  13. package/dist/components/NumberInputField/index.d.ts +13 -0
  14. package/dist/components/NumberInputField/index.js +39 -45
  15. package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
  16. package/dist/components/NumberInputFieldV2/index.js +45 -51
  17. package/dist/components/RadioField/index.d.ts +12 -0
  18. package/dist/components/RadioField/index.js +36 -42
  19. package/dist/components/RadioGroupField/index.d.ts +28 -0
  20. package/dist/components/RadioGroupField/index.js +31 -32
  21. package/dist/components/SelectInputField/index.d.ts +82 -0
  22. package/dist/components/SelectInputField/index.js +90 -83
  23. package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
  24. package/dist/components/SelectInputFieldV2/index.js +60 -60
  25. package/dist/components/SelectableCardField/index.d.ts +9 -0
  26. package/dist/components/SelectableCardField/index.js +49 -44
  27. package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
  28. package/dist/components/SelectableCardGroupField/index.js +42 -41
  29. package/dist/components/Submit/index.d.ts +17 -0
  30. package/dist/components/Submit/index.js +27 -27
  31. package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
  32. package/dist/components/SubmitErrorAlert/index.js +9 -17
  33. package/dist/components/TagInputField/index.d.ts +6 -0
  34. package/dist/components/TagInputField/index.js +35 -38
  35. package/dist/components/TextAreaField/index.d.ts +11 -0
  36. package/dist/components/TextAreaField/index.js +57 -56
  37. package/dist/components/TextInputField/index.d.ts +18 -0
  38. package/dist/components/TextInputField/index.js +82 -81
  39. package/dist/components/TextInputFieldV2/index.d.ts +12 -0
  40. package/dist/components/TextInputFieldV2/index.js +73 -72
  41. package/dist/components/TimeField/index.d.ts +9 -0
  42. package/dist/components/TimeField/index.js +51 -49
  43. package/dist/components/ToggleField/index.d.ts +10 -0
  44. package/dist/components/ToggleField/index.js +32 -31
  45. package/dist/components/ToggleGroupField/index.d.ts +26 -0
  46. package/dist/components/index.d.ts +22 -0
  47. package/dist/constants.d.ts +1 -0
  48. package/dist/constants.js +4 -3
  49. package/dist/hooks/index.d.ts +5 -0
  50. package/dist/hooks/useField.d.ts +34 -0
  51. package/dist/hooks/useField.js +7 -30
  52. package/dist/hooks/useFieldArray.d.ts +21 -0
  53. package/dist/hooks/useFieldArray.js +9 -22
  54. package/dist/hooks/useForm.d.ts +23 -0
  55. package/dist/hooks/useForm.js +8 -25
  56. package/dist/hooks/useFormState.d.ts +39 -0
  57. package/dist/hooks/useFormState.js +6 -23
  58. package/dist/hooks/useOnFieldChange.d.ts +3 -0
  59. package/dist/hooks/useOnFieldChange.js +10 -11
  60. package/dist/index.d.ts +7 -555
  61. package/dist/index.js +66 -29
  62. package/dist/mocks/index.d.ts +1 -0
  63. package/dist/mocks/mockErrors.d.ts +3 -0
  64. package/dist/providers/ErrorContext/index.d.ts +14 -0
  65. package/dist/providers/ErrorContext/index.js +30 -29
  66. package/dist/providers/index.d.ts +1 -0
  67. package/dist/types.d.ts +32 -0
  68. package/dist/validators/index.d.ts +5 -0
  69. package/dist/validators/maxDate.d.ts +1 -0
  70. package/dist/validators/maxDate.js +4 -3
  71. package/dist/validators/minDate.d.ts +1 -0
  72. package/dist/validators/minDate.js +4 -3
  73. package/package.json +17 -11
@@ -0,0 +1,10 @@
1
+ import { Checkbox } from '@ultraviolet/ui';
2
+ import type { ComponentProps, ReactNode } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type CheckboxFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'value'> & Partial<Pick<ComponentProps<typeof Checkbox>, 'id' | 'disabled' | 'onBlur' | 'onFocus' | 'progress' | 'size' | 'data-testid' | 'helper' | 'tooltip'>> & {
6
+ className?: string;
7
+ children?: ReactNode;
8
+ };
9
+ export declare const CheckboxField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ id, name, label, size, progress, disabled, required, className, children, onChange, onBlur, onFocus, rules, helper, tooltip, "data-testid": dataTestId, shouldUnregister, }: CheckboxFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -1,8 +1,7 @@
1
- import { Checkbox } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { jsx } from '@emotion/react/jsx-runtime';
4
- import { useErrors } from '../../providers/ErrorContext/index.js';
5
-
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { Checkbox } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
4
+ import { useErrors } from "../../providers/ErrorContext/index.js";
6
5
  const CheckboxField = ({
7
6
  id,
8
7
  name,
@@ -19,17 +18,13 @@ const CheckboxField = ({
19
18
  rules,
20
19
  helper,
21
20
  tooltip,
22
- 'data-testid': dataTestId,
21
+ "data-testid": dataTestId,
23
22
  shouldUnregister = false
24
23
  }) => {
25
- const {
26
- getError
27
- } = useErrors();
24
+ const { getError } = useErrors();
28
25
  const {
29
26
  field,
30
- fieldState: {
31
- error
32
- }
27
+ fieldState: { error }
33
28
  } = useController({
34
29
  name,
35
30
  disabled,
@@ -39,33 +34,37 @@ const CheckboxField = ({
39
34
  ...rules
40
35
  }
41
36
  });
42
- return jsx(Checkbox, {
43
- id: id,
44
- name: field.name,
45
- onChange: event => {
46
- field.onChange(event.target.checked);
47
- onChange?.(event.target.checked);
48
- },
49
- onBlur: event => {
50
- field.onBlur();
51
- onBlur?.(event);
52
- },
53
- onFocus: onFocus,
54
- size: size,
55
- progress: progress,
56
- disabled: field.disabled,
57
- checked: !!field.value,
58
- error: getError({
59
- label: label ?? ''
60
- }, error),
61
- ref: field.ref,
62
- className: className,
63
- required: required,
64
- "data-testid": dataTestId,
65
- helper: helper,
66
- tooltip: tooltip,
67
- children: children
68
- });
37
+ return /* @__PURE__ */ jsx(
38
+ Checkbox,
39
+ {
40
+ id,
41
+ name: field.name,
42
+ onChange: (event) => {
43
+ field.onChange(event.target.checked);
44
+ onChange?.(
45
+ event.target.checked
46
+ );
47
+ },
48
+ onBlur: (event) => {
49
+ field.onBlur();
50
+ onBlur?.(event);
51
+ },
52
+ onFocus,
53
+ size,
54
+ progress,
55
+ disabled: field.disabled,
56
+ checked: !!field.value,
57
+ error: getError({ label: label ?? "" }, error),
58
+ ref: field.ref,
59
+ className,
60
+ required,
61
+ "data-testid": dataTestId,
62
+ helper,
63
+ tooltip,
64
+ children
65
+ }
66
+ );
67
+ };
68
+ export {
69
+ CheckboxField
69
70
  };
70
-
71
- export { CheckboxField };
@@ -0,0 +1,32 @@
1
+ import { CheckboxGroup } from '@ultraviolet/ui';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type CheckboxGroupFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'required' | 'direction' | 'children' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend'>>;
6
+ export declare const CheckboxGroupField: {
7
+ <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ legend, className, helper, direction, children, onChange, label, error: customError, name, required, shouldUnregister, rules, }: CheckboxGroupFieldProps<TFieldValues, TName>): import("@emotion/react/jsx-runtime").JSX.Element;
8
+ Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, required, }: Omit<({
9
+ error?: import("react").ReactNode;
10
+ size?: number | undefined;
11
+ progress?: boolean | undefined;
12
+ helper?: import("react").ReactNode;
13
+ disabled?: boolean | undefined;
14
+ checked?: boolean | "indeterminate" | undefined;
15
+ className?: string | undefined;
16
+ "data-visibility"?: string | undefined;
17
+ required?: boolean | undefined;
18
+ 'data-testid'?: string | undefined;
19
+ tooltip?: string | undefined;
20
+ } & Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onBlur" | "name" | "onFocus" | "autoFocus" | "id" | "tabIndex"> & (({
21
+ "aria-label"?: undefined;
22
+ } & {
23
+ children: import("react").ReactNode;
24
+ }) | ({
25
+ children?: undefined;
26
+ } & {
27
+ 'aria-label': string;
28
+ }))) & import("react").RefAttributes<HTMLInputElement>, "onChange" | "checked"> & {
29
+ value: string;
30
+ }) => import("@emotion/react/jsx-runtime").JSX.Element;
31
+ };
32
+ export {};
@@ -1,14 +1,13 @@
1
- import { CheckboxGroup } from '@ultraviolet/ui';
2
- import { useCallback, Children, isValidElement } from 'react';
3
- import { useController } from 'react-hook-form';
4
- import { jsx } from '@emotion/react/jsx-runtime';
5
- import { useErrors } from '../../providers/ErrorContext/index.js';
6
-
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { CheckboxGroup } from "@ultraviolet/ui";
3
+ import { useCallback, Children, isValidElement } from "react";
4
+ import { useController } from "react-hook-form";
5
+ import { useErrors } from "../../providers/ErrorContext/index.js";
7
6
  const arraysContainSameValues = (array1, array2) => {
8
7
  if (array1.length === 0) {
9
8
  return false;
10
9
  }
11
- return array2.every(value => array1.includes(value));
10
+ return array2.every((value) => array1.includes(value));
12
11
  };
13
12
  const CheckboxGroupField = ({
14
13
  legend,
@@ -17,39 +16,38 @@ const CheckboxGroupField = ({
17
16
  direction,
18
17
  children,
19
18
  onChange,
20
- label = '',
19
+ label = "",
21
20
  error: customError,
22
21
  name,
23
22
  required = false,
24
23
  shouldUnregister = false,
25
24
  rules
26
25
  }) => {
27
- const {
28
- getError
29
- } = useErrors();
30
- const validate = useCallback(value => {
31
- const requiredChildren = Children.map(children, child => {
32
- if ( /*#__PURE__*/isValidElement(child)) {
33
- if (child.props.required) {
34
- return child.props.name;
26
+ const { getError } = useErrors();
27
+ const validate = useCallback(
28
+ (value) => {
29
+ const requiredChildren = Children.map(children, (child) => {
30
+ if (isValidElement(child)) {
31
+ if (child.props.required) {
32
+ return child.props.name;
33
+ }
34
+ return null;
35
35
  }
36
36
  return null;
37
+ })?.filter(Boolean) ?? [];
38
+ if (!required && arraysContainSameValues(value, requiredChildren)) {
39
+ return true;
37
40
  }
38
- return null;
39
- })?.filter(Boolean) ?? [];
40
- if (!required && arraysContainSameValues(value, requiredChildren)) {
41
- return true;
42
- }
43
- if (value.length >= Children.count(children)) {
44
- return true;
45
- }
46
- return false;
47
- }, [children, required]);
41
+ if (value.length >= Children.count(children)) {
42
+ return true;
43
+ }
44
+ return false;
45
+ },
46
+ [children, required]
47
+ );
48
48
  const {
49
49
  field,
50
- fieldState: {
51
- error
52
- }
50
+ fieldState: { error }
53
51
  } = useController({
54
52
  name,
55
53
  shouldUnregister,
@@ -58,29 +56,37 @@ const CheckboxGroupField = ({
58
56
  ...rules
59
57
  }
60
58
  });
61
- return jsx(CheckboxGroup, {
62
- legend: legend,
63
- name: name,
64
- value: field.value,
65
- onChange: event => {
66
- const fieldValue = field.value;
67
- if (fieldValue?.includes(event.currentTarget.value)) {
68
- field.onChange(fieldValue?.filter(currentValue => currentValue !== event.currentTarget.value));
69
- } else {
70
- field.onChange([...field.value, event.currentTarget.value]);
71
- }
72
- onChange?.(event.currentTarget.value);
73
- },
74
- error: getError({
75
- label
76
- }, error) ?? customError,
77
- className: className,
78
- direction: direction,
79
- helper: helper,
80
- required: required,
81
- children: children
82
- });
59
+ return /* @__PURE__ */ jsx(
60
+ CheckboxGroup,
61
+ {
62
+ legend,
63
+ name,
64
+ value: field.value,
65
+ onChange: (event) => {
66
+ const fieldValue = field.value;
67
+ if (fieldValue?.includes(event.currentTarget.value)) {
68
+ field.onChange(
69
+ fieldValue?.filter(
70
+ (currentValue) => currentValue !== event.currentTarget.value
71
+ )
72
+ );
73
+ } else {
74
+ field.onChange([...field.value, event.currentTarget.value]);
75
+ }
76
+ onChange?.(
77
+ event.currentTarget.value
78
+ );
79
+ },
80
+ error: getError({ label }, error) ?? customError,
81
+ className,
82
+ direction,
83
+ helper,
84
+ required,
85
+ children
86
+ }
87
+ );
83
88
  };
84
89
  CheckboxGroupField.Checkbox = CheckboxGroup.Checkbox;
85
-
86
- export { CheckboxGroupField };
90
+ export {
91
+ CheckboxGroupField
92
+ };
@@ -0,0 +1,16 @@
1
+ import { DateInput } from '@ultraviolet/ui';
2
+ import type { ComponentProps, FocusEvent } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type DateFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof DateInput>, 'maxDate' | 'minDate' | 'disabled' | 'required' | 'locale' | 'name' | 'onChange' | 'onFocus' | 'onBlur' | 'autoFocus' | 'stardDate' | 'endDate'> & {
6
+ maxDate?: Date;
7
+ minDate?: Date;
8
+ disabled?: boolean;
9
+ required?: boolean;
10
+ locale?: string;
11
+ onBlur?: (event: FocusEvent<HTMLElement>) => void;
12
+ onFocus?: (value: FocusEvent<HTMLElement>) => void;
13
+ autoFocus?: boolean;
14
+ };
15
+ export declare const DateField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ required, name, label, format, locale, maxDate, minDate, disabled, onChange, onBlur, onFocus, rules, autoFocus, excludeDates, selectsRange, "data-testid": dataTestId, shouldUnregister, }: DateFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -1,16 +1,15 @@
1
- import { DateInput } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { maxDateValidator } from '../../validators/maxDate.js';
4
- import { minDateValidator } from '../../validators/minDate.js';
5
- import { jsx } from '@emotion/react/jsx-runtime';
6
- import { useErrors } from '../../providers/ErrorContext/index.js';
7
-
8
- const parseDate = value => typeof value === 'string' ? new Date(value) : value;
9
- const isEmpty = value => typeof value === 'string' ? value === '' : value === undefined;
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { DateInput } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
4
+ import { maxDateValidator } from "../../validators/maxDate.js";
5
+ import { minDateValidator } from "../../validators/minDate.js";
6
+ import { useErrors } from "../../providers/ErrorContext/index.js";
7
+ const parseDate = (value) => typeof value === "string" ? new Date(value) : value;
8
+ const isEmpty = (value) => typeof value === "string" ? value === "" : value === void 0;
10
9
  const DateField = ({
11
10
  required,
12
11
  name,
13
- label = '',
12
+ label = "",
14
13
  format,
15
14
  locale,
16
15
  maxDate,
@@ -23,17 +22,13 @@ const DateField = ({
23
22
  autoFocus = false,
24
23
  excludeDates,
25
24
  selectsRange,
26
- 'data-testid': dataTestId,
25
+ "data-testid": dataTestId,
27
26
  shouldUnregister = false
28
27
  }) => {
29
- const {
30
- getError
31
- } = useErrors();
28
+ const { getError } = useErrors();
32
29
  const {
33
30
  field,
34
- fieldState: {
35
- error
36
- }
31
+ fieldState: { error }
37
32
  } = useController({
38
33
  name,
39
34
  shouldUnregister,
@@ -47,48 +42,48 @@ const DateField = ({
47
42
  required
48
43
  }
49
44
  });
50
- return jsx(DateInput, {
51
- name: field.name,
52
- label: label,
53
- value: field.value,
54
- format: format || (value => value ? parseDate(value).toLocaleDateString() : ''),
55
- locale: locale,
56
- required: required,
57
- onChange: val => {
58
- if (val && val instanceof Date) {
59
- onChange?.(val);
60
- const newDate = parseDate(val);
61
- if (isEmpty(field.value)) {
45
+ return /* @__PURE__ */ jsx(
46
+ DateInput,
47
+ {
48
+ name: field.name,
49
+ label,
50
+ value: field.value,
51
+ format: format || ((value) => value ? parseDate(value).toLocaleDateString() : ""),
52
+ locale,
53
+ required,
54
+ onChange: (val) => {
55
+ if (val && val instanceof Date) {
56
+ onChange?.(val);
57
+ const newDate = parseDate(val);
58
+ if (isEmpty(field.value)) {
59
+ field.onChange(newDate);
60
+ return;
61
+ }
62
+ const currentDate = parseDate(field.value);
63
+ newDate.setHours(currentDate.getHours(), currentDate.getMinutes());
62
64
  field.onChange(newDate);
63
- return;
65
+ } else if (Array.isArray(val)) {
66
+ field.onChange(val);
64
67
  }
65
- const currentDate = parseDate(field.value);
66
- newDate.setHours(currentDate.getHours(), currentDate.getMinutes());
67
- field.onChange(newDate);
68
- } else if (Array.isArray(val)) {
69
- field.onChange(val);
70
- }
71
- },
72
- onBlur: e => {
73
- field.onBlur();
74
- onBlur?.(e);
75
- },
76
- onFocus: onFocus,
77
- maxDate: maxDate,
78
- minDate: minDate,
79
- error: getError({
80
- minDate,
68
+ },
69
+ onBlur: (e) => {
70
+ field.onBlur();
71
+ onBlur?.(e);
72
+ },
73
+ onFocus,
81
74
  maxDate,
82
- label
83
- }, error),
84
- disabled: disabled,
85
- autoFocus: autoFocus,
86
- excludeDates: excludeDates,
87
- selectsRange: selectsRange,
88
- "data-testid": dataTestId,
89
- startDate: selectsRange && Array.isArray(field.value) ? field.value[0] : undefined,
90
- endDate: selectsRange && Array.isArray(field.value) ? field.value[1] : undefined
91
- });
75
+ minDate,
76
+ error: getError({ minDate, maxDate, label }, error),
77
+ disabled,
78
+ autoFocus,
79
+ excludeDates,
80
+ selectsRange,
81
+ "data-testid": dataTestId,
82
+ startDate: selectsRange && Array.isArray(field.value) ? field.value[0] : void 0,
83
+ endDate: selectsRange && Array.isArray(field.value) ? field.value[1] : void 0
84
+ }
85
+ );
86
+ };
87
+ export {
88
+ DateField
92
89
  };
93
-
94
- export { DateField };
@@ -0,0 +1,2 @@
1
+ import type { RequiredErrors } from '../../types';
2
+ export declare const defaultErrors: RequiredErrors;
@@ -1,21 +1,22 @@
1
1
  const defaultErrors = {
2
- maxDate: () => '',
3
- maxLength: () => '',
4
- minLength: () => '',
5
- max: () => '',
6
- min: () => '',
7
- required: () => '',
8
- pattern: () => '',
9
- deps: () => '',
10
- value: () => '',
11
- onBlur: () => '',
12
- disabled: () => '',
13
- onChange: () => '',
14
- validate: () => '',
15
- setValueAs: () => '',
16
- valueAsDate: () => '',
17
- valueAsNumber: () => '',
18
- shouldUnregister: () => ''
2
+ maxDate: () => "",
3
+ maxLength: () => "",
4
+ minLength: () => "",
5
+ max: () => "",
6
+ min: () => "",
7
+ required: () => "",
8
+ pattern: () => "",
9
+ deps: () => "",
10
+ value: () => "",
11
+ onBlur: () => "",
12
+ disabled: () => "",
13
+ onChange: () => "",
14
+ validate: () => "",
15
+ setValueAs: () => "",
16
+ valueAsDate: () => "",
17
+ valueAsNumber: () => "",
18
+ shouldUnregister: () => ""
19
+ };
20
+ export {
21
+ defaultErrors
19
22
  };
20
-
21
- export { defaultErrors };
@@ -0,0 +1,69 @@
1
+ import type { ReactNode } from 'react';
2
+ import React from 'react';
3
+ import type { DefaultValues, FieldErrors, FieldValues, UseFormHandleSubmit, UseFormReturn } from 'react-hook-form';
4
+ import { FORM_ERROR } from '../../constants';
5
+ import type { FormErrors } from '../../types';
6
+ type Without<T, U> = {
7
+ [P in Exclude<keyof T, keyof U>]?: never;
8
+ };
9
+ type SingleXOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
10
+ export type XOR<T extends unknown[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? XOR<[SingleXOR<A, B>, ...Rest]> : never;
11
+ type FormStateReturn<TFormValues extends FieldValues> = {
12
+ values: TFormValues;
13
+ hasValidationErrors: boolean;
14
+ errors: FieldErrors<TFormValues>;
15
+ submitting: boolean;
16
+ pristine: boolean;
17
+ handleSubmit: () => Promise<void>;
18
+ submitError: boolean;
19
+ valid: boolean;
20
+ form: {
21
+ change: UseFormReturn<TFormValues>['setValue'];
22
+ reset: UseFormReturn<TFormValues>['reset'];
23
+ submit: () => Promise<void>;
24
+ };
25
+ };
26
+ type OnRawSubmitReturn = {
27
+ [FORM_ERROR]?: string;
28
+ } | undefined | null | string | void | boolean | number;
29
+ type FormSubmitContextValue<TFieldValues extends FieldValues = FieldValues> = {
30
+ handleSubmit: ReturnType<UseFormHandleSubmit<TFieldValues>>;
31
+ };
32
+ export declare const FormSubmitContext: React.Context<FormSubmitContextValue<FieldValues>>;
33
+ export type FormProps<TFormValues extends FieldValues = FieldValues> = {
34
+ children?: ((props: FormStateReturn<TFormValues>) => ReactNode) | ReactNode;
35
+ errors: FormErrors;
36
+ name?: string;
37
+ onRawSubmit: (data: TFormValues, formState: {
38
+ reset: UseFormReturn<TFormValues>['reset'];
39
+ resetFieldState: UseFormReturn<TFormValues>['resetField'];
40
+ restart: () => void;
41
+ change: UseFormReturn<TFormValues>['setValue'];
42
+ }) => Promise<OnRawSubmitReturn> | OnRawSubmitReturn;
43
+ } & XOR<[
44
+ {
45
+ /**
46
+ * @deprecated Use the `methods` prop with [useForm](https://www.react-hook-form.com/api/useform/) instead.
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * const methods = useForm({
51
+ * defaultValues,
52
+ * mode: 'onChange'
53
+ * })
54
+ *
55
+ * return (
56
+ * <Form methods={methods} onRawSubmit={handleSubmit} errors={formErrors}>
57
+ * // ...
58
+ * </Form>
59
+ * )
60
+ * ```
61
+ */
62
+ initialValues?: DefaultValues<TFormValues>;
63
+ },
64
+ {
65
+ methods: UseFormReturn<TFormValues>;
66
+ }
67
+ ]>;
68
+ export declare const Form: <TFormValues extends FieldValues>({ children, methods: methodsProp, initialValues, errors, onRawSubmit, name, }: FormProps<TFormValues>) => import("@emotion/react/jsx-runtime").JSX.Element;
69
+ export {};