@juantroconisf/lib 11.0.1 → 11.1.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/README.md CHANGED
@@ -343,24 +343,25 @@ return (
343
343
  );
344
344
  ```
345
345
 
346
- ### Option 3: Inline handler with full type inference
346
+ ### Option 3: External handler with `FormSubmit`
347
347
 
348
- When the schema is defined inline inside `useForm`, extract the handler type from `ControlledForm`:
348
+ When you need to define the submit handler outside the JSX, use the `FormSubmit` utility type:
349
349
 
350
350
  ```tsx
351
+ import { useForm, FormSubmit } from "@juantroconisf/lib";
352
+
351
353
  const { ControlledForm } = useForm({
352
354
  email: string().required().default(""),
353
355
  });
354
356
 
355
- const handleSubmit: React.ComponentProps<typeof ControlledForm>["onSubmit"] = (
356
- data,
357
- event,
358
- ) => {
357
+ const handleSubmit: FormSubmit<typeof ControlledForm> = (data, event) => {
359
358
  // data.email is correctly typed as string — no schema re-declaration needed
360
359
  console.log(data.email);
361
360
  };
362
361
  ```
363
362
 
363
+ `FormSubmit<typeof ControlledForm>` is a shorthand for `React.ComponentProps<typeof ControlledForm>["onSubmit"]`.
364
+
364
365
  ---
365
366
 
366
367
  ## API Reference
package/dist/index.d.mts CHANGED
@@ -66,6 +66,19 @@ type FormSubmitHandler<O extends StateType> = (data: O, e: React.FormEvent) => v
66
66
  * This saves developers from manually mapping `InferType` back to `FormSubmitHandler` when extracting sumbits.
67
67
  */
68
68
  type InferSubmitHandler<S extends Record<string, ConfigType>> = (data: InferState<S>, e: React.FormEvent) => void;
69
+ /**
70
+ * Shorthand to extract the `onSubmit` handler type from a `ControlledForm` component.
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * const { ControlledForm } = useForm({ email: string().required().default("") });
75
+ *
76
+ * const handleSubmit: FormSubmit<typeof ControlledForm> = (data, event) => {
77
+ * console.log(data.email); // fully typed
78
+ * };
79
+ * ```
80
+ */
81
+ type FormSubmit<C extends React.ComponentType<any>> = NonNullable<React.ComponentProps<C>["onSubmit"]>;
69
82
  interface FormResetOptions<O> {
70
83
  keepValues?: (keyof O)[];
71
84
  }
@@ -268,4 +281,4 @@ interface UseFormResponse<O extends StateType> {
268
281
 
269
282
  declare function useForm<S extends Record<string, ConfigType>>(schema: S, { arrayIdentifiers, onFormSubmit: onFormSubmitProp, resetOnSubmit, keepValues: keepValuesProp, }?: FormOptions<InferState<S>>): UseFormResponse<InferState<S>>;
270
283
 
271
- export { type BlurFunc, type ComponentInputProps, type ConfigType, type FieldMetadata, type FormOptions, type FormResetOptions, type FormSubmitHandler, type HelpersFunc, type InferState, type InferSubmitHandler, type ItemAutocompleteProps, type ItemInputProps, type ItemNumberInputProps, type ItemRadioGroupProps, type ItemSelectProps, type ItemToggleProps, type MetadataType, type NestedChangeProps, NextUIError, type OnMethods, type StateType, type UseFormResponse, type ValueChangeFunc, useForm };
284
+ export { type BlurFunc, type ComponentInputProps, type ConfigType, type FieldMetadata, type FormOptions, type FormResetOptions, type FormSubmit, type FormSubmitHandler, type HelpersFunc, type InferState, type InferSubmitHandler, type ItemAutocompleteProps, type ItemInputProps, type ItemNumberInputProps, type ItemRadioGroupProps, type ItemSelectProps, type ItemToggleProps, type MetadataType, type NestedChangeProps, NextUIError, type OnMethods, type StateType, type UseFormResponse, type ValueChangeFunc, useForm };
package/dist/index.d.ts CHANGED
@@ -66,6 +66,19 @@ type FormSubmitHandler<O extends StateType> = (data: O, e: React.FormEvent) => v
66
66
  * This saves developers from manually mapping `InferType` back to `FormSubmitHandler` when extracting sumbits.
67
67
  */
68
68
  type InferSubmitHandler<S extends Record<string, ConfigType>> = (data: InferState<S>, e: React.FormEvent) => void;
69
+ /**
70
+ * Shorthand to extract the `onSubmit` handler type from a `ControlledForm` component.
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * const { ControlledForm } = useForm({ email: string().required().default("") });
75
+ *
76
+ * const handleSubmit: FormSubmit<typeof ControlledForm> = (data, event) => {
77
+ * console.log(data.email); // fully typed
78
+ * };
79
+ * ```
80
+ */
81
+ type FormSubmit<C extends React.ComponentType<any>> = NonNullable<React.ComponentProps<C>["onSubmit"]>;
69
82
  interface FormResetOptions<O> {
70
83
  keepValues?: (keyof O)[];
71
84
  }
@@ -268,4 +281,4 @@ interface UseFormResponse<O extends StateType> {
268
281
 
269
282
  declare function useForm<S extends Record<string, ConfigType>>(schema: S, { arrayIdentifiers, onFormSubmit: onFormSubmitProp, resetOnSubmit, keepValues: keepValuesProp, }?: FormOptions<InferState<S>>): UseFormResponse<InferState<S>>;
270
283
 
271
- export { type BlurFunc, type ComponentInputProps, type ConfigType, type FieldMetadata, type FormOptions, type FormResetOptions, type FormSubmitHandler, type HelpersFunc, type InferState, type InferSubmitHandler, type ItemAutocompleteProps, type ItemInputProps, type ItemNumberInputProps, type ItemRadioGroupProps, type ItemSelectProps, type ItemToggleProps, type MetadataType, type NestedChangeProps, NextUIError, type OnMethods, type StateType, type UseFormResponse, type ValueChangeFunc, useForm };
284
+ export { type BlurFunc, type ComponentInputProps, type ConfigType, type FieldMetadata, type FormOptions, type FormResetOptions, type FormSubmit, type FormSubmitHandler, type HelpersFunc, type InferState, type InferSubmitHandler, type ItemAutocompleteProps, type ItemInputProps, type ItemNumberInputProps, type ItemRadioGroupProps, type ItemSelectProps, type ItemToggleProps, type MetadataType, type NestedChangeProps, NextUIError, type OnMethods, type StateType, type UseFormResponse, type ValueChangeFunc, useForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "11.0.1",
3
+ "version": "11.1.0",
4
4
  "description": "A form validation library for HeroUI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",