@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.
Files changed (73) hide show
  1. package/dist/components/CheckboxField/index.d.ts +10 -0
  2. package/dist/components/CheckboxField/index.js +17 -35
  3. package/dist/components/CheckboxGroupField/index.d.ts +32 -0
  4. package/dist/components/CheckboxGroupField/index.js +24 -35
  5. package/dist/components/DateField/index.d.ts +16 -0
  6. package/dist/components/DateField/index.js +33 -53
  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 +41 -54
  11. package/dist/components/KeyValueField/index.d.ts +33 -0
  12. package/dist/components/KeyValueField/index.js +23 -56
  13. package/dist/components/NumberInputField/index.d.ts +13 -0
  14. package/dist/components/NumberInputField/index.js +18 -39
  15. package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
  16. package/dist/components/NumberInputFieldV2/index.js +20 -46
  17. package/dist/components/RadioField/index.d.ts +12 -0
  18. package/dist/components/RadioField/index.js +18 -36
  19. package/dist/components/RadioGroupField/index.d.ts +28 -0
  20. package/dist/components/RadioGroupField/index.js +15 -26
  21. package/dist/components/SelectInputField/index.d.ts +82 -0
  22. package/dist/components/SelectInputField/index.js +31 -61
  23. package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
  24. package/dist/components/SelectInputFieldV2/index.js +18 -52
  25. package/dist/components/SelectableCardField/index.d.ts +9 -0
  26. package/dist/components/SelectableCardField/index.js +24 -41
  27. package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
  28. package/dist/components/SelectableCardGroupField/index.js +22 -35
  29. package/dist/components/Submit/index.d.ts +17 -0
  30. package/dist/components/Submit/index.js +9 -23
  31. package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
  32. package/dist/components/SubmitErrorAlert/index.js +7 -11
  33. package/dist/components/TagInputField/index.d.ts +6 -0
  34. package/dist/components/TagInputField/index.js +14 -32
  35. package/dist/components/TextAreaField/index.d.ts +11 -0
  36. package/dist/components/TextAreaField/index.js +25 -52
  37. package/dist/components/TextInputField/index.d.ts +18 -0
  38. package/dist/components/TextInputField/index.js +37 -76
  39. package/dist/components/TextInputFieldV2/index.d.ts +12 -0
  40. package/dist/components/TextInputFieldV2/index.js +30 -66
  41. package/dist/components/TimeField/index.d.ts +9 -0
  42. package/dist/components/TimeField/index.js +23 -46
  43. package/dist/components/ToggleField/index.d.ts +10 -0
  44. package/dist/components/ToggleField/index.js +15 -28
  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 +4 -20
  52. package/dist/hooks/useFieldArray.d.ts +21 -0
  53. package/dist/hooks/useFieldArray.js +6 -9
  54. package/dist/hooks/useForm.d.ts +23 -0
  55. package/dist/hooks/useForm.js +7 -19
  56. package/dist/hooks/useFormState.d.ts +39 -0
  57. package/dist/hooks/useFormState.js +5 -20
  58. package/dist/hooks/useOnFieldChange.d.ts +3 -0
  59. package/dist/hooks/useOnFieldChange.js +6 -6
  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 +11 -13
  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 +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
+ };
@@ -1,19 +1,6 @@
1
- import { useContext } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
- import { FormSubmitContext } from '../components/Form/index.js';
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
- export { useFormDeprecated };
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 'react-hook-form';
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
- export { useFormStateDeprecated };
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 'react';
2
- import { useFormContext } from 'react-hook-form';
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
- export { useOnFieldChange };
19
+ export {
20
+ useOnFieldChange
21
+ };