@paragrav/rhf-utils 0.0.111 → 0.0.112

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/README.md CHANGED
@@ -117,7 +117,7 @@ Currently, only `zod` is supported.
117
117
  }) => {
118
118
  onError(error);
119
119
  }}
120
- // children/fields
120
+ // fields
121
121
  Children={({
122
122
  // UseRhfUtilsFormChildrenProps
123
123
  formId, // unique id string
@@ -130,13 +130,10 @@ Currently, only `zod` is supported.
130
130
  <Controller
131
131
  name="email" // strongly-typed field name
132
132
  render={({ field, formState: { isSubmitting } }) => (
133
- <input
134
- autoFocus
135
- label="Email"
136
- autoComplete="email"
137
- disabled={isSubmitting}
138
- {...field}
139
- />
133
+ <label>
134
+ Email
135
+ <input {...field} disabled={isSubmitting} />
136
+ </label>
140
137
  )}
141
138
  />
142
139
 
@@ -151,7 +148,9 @@ Currently, only `zod` is supported.
151
148
  If you prefer to define your `Children` component as standalone:
152
149
 
153
150
  ```tsx
154
- const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = () => {};
151
+ const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = ({ ... }) => { };
152
+
153
+ function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
155
154
  ```
156
155
 
157
156
  ## `RhfUtilsFormOptions`
@@ -221,7 +220,7 @@ To get accurate orphan analysis, you must either use `FormNonFieldErrorMarker` i
221
220
  Alternatively, you can use `FormErrorMessageByPath` to display error message to user:
222
221
 
223
222
  ```tsx
224
- <FormErrorMessageByPath path="phone" />
223
+ <FormErrorMessageByPath path="street.address" />
225
224
  ```
226
225
 
227
226
  Example use case: Field array with minimum items. (When there are no items, the error is not associated with a field and is displayed separately.)
@@ -232,3 +231,28 @@ Orphans are optionally exposed in a few places.
232
231
  - And `useFlatFieldErrorsContext()` hook, which returns an object with divided into `all`, `root`, and `orphans` errors.
233
232
 
234
233
  `FlatFieldErrors` is a flattened, simplified version of RHF's `FieldErrors`. Keys represent field paths flattened to dot notation.
234
+
235
+ ## Form Groups
236
+
237
+ Sometimes you need to group multiple forms together.
238
+
239
+ Use case: disable parent form when any child is "busy"; disable all children when parent is "busy".
240
+
241
+ Use `FormGroupContextProvider` to wrap your children and parent forms.
242
+
243
+ ```tsx
244
+ <FormGroupContextProvider>
245
+ <ChildForm1 />
246
+ <ChildForm2 />
247
+ <ParentForm />
248
+ </FormGroupContextProvider>
249
+ ```
250
+
251
+ In your parent form, use the hook `useFormGroupParentTracker`, which returns `boolean` value indicating whether any child forms is busy.
252
+
253
+ In children forms, there are two options. You can choose to consider form "busy" when:
254
+
255
+ - `isSubmitting` is `true` by using `useFormGroupChildIsSubmittingTracker` hook
256
+ - it is mounted by using `useFormGroupChildIsMountedTracker` hook
257
+
258
+ Both hooks return `boolean` value indicating whether parent form is busy.
@@ -1,7 +1,6 @@
1
1
  import r from "./useFormGroupChildTracker.mjs";
2
- const o = () => {
3
- r(!0);
4
- }, u = o;
2
+ import o from "./useFormGroupIsParentBusy.mjs";
3
+ const e = () => (r(!0), o()), t = e;
5
4
  export {
6
- u as default
5
+ t as default
7
6
  };
@@ -1,9 +1,10 @@
1
1
  import { useFormState as o } from "react-hook-form";
2
2
  import t from "./useFormGroupChildTracker.mjs";
3
- const i = () => {
3
+ import u from "./useFormGroupIsParentBusy.mjs";
4
+ const m = () => {
4
5
  const { isSubmitting: r } = o();
5
- t(r);
6
- }, u = i;
6
+ return t(r), u();
7
+ }, n = m;
7
8
  export {
8
- u as default
9
+ n as default
9
10
  };
@@ -2,7 +2,7 @@ import { _useFormGroupContextMaybe as o } from "./index.mjs";
2
2
  const s = () => {
3
3
  const r = o();
4
4
  return !!(r != null && r.parent.isBusy);
5
- }, t = s;
5
+ };
6
6
  export {
7
- t as default
7
+ s as default
8
8
  };
@@ -1,12 +1,13 @@
1
1
  import s from "react";
2
2
  import t from "../../useFormIsBusy.mjs";
3
3
  import { _useFormGroupContext as e } from "./index.mjs";
4
- const u = () => {
4
+ import u from "./useFormGroupIsChildBusy.mjs";
5
+ const m = () => {
5
6
  const r = t(), { setIsBusy: o } = e().parent;
6
- s.useEffect(() => {
7
+ return s.useEffect(() => {
7
8
  o(r);
8
- }, [o, r]);
9
- }, n = u;
9
+ }, [o, r]), u();
10
+ }, f = m;
10
11
  export {
11
- n as default
12
+ f as default
12
13
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Mark "child" form as "busy" when mounted.
3
3
  */
4
- declare const useFormGroupChildIsMountedTracker: () => void;
4
+ declare const useFormGroupChildIsMountedTracker: () => boolean;
5
5
  export default useFormGroupChildIsMountedTracker;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Mark "child" form as "busy" when submitting.
3
3
  */
4
- declare const useFormGroupChildIsSubmittingTracker: () => void;
4
+ declare const useFormGroupChildIsSubmittingTracker: () => boolean;
5
5
  export default useFormGroupChildIsSubmittingTracker;
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Requires usage of provider.
5
5
  */
6
- declare const useFormGroupParentTracker: () => void;
6
+ declare const useFormGroupParentTracker: () => boolean;
7
7
  export default useFormGroupParentTracker;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.111",
5
+ "version": "0.0.112",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,