@chris-c-brine/form-dialog 1.0.5 → 1.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.
@@ -1,9 +1,22 @@
1
+ import { MouseEvent } from "react";
1
2
  export interface UseDialogProps {
2
3
  /** Initial open state of the dialog */
3
4
  open?: boolean;
4
- /** Whether to keep the dialog mounted when closed */
5
+ /** Always keep the children in the DOM. */
5
6
  keepMounted?: boolean;
6
7
  }
8
+ export interface UseDialogReturn {
9
+ /** Function to close the dialog */
10
+ closeDialog: () => void;
11
+ /** Function to open the dialog */
12
+ openDialog: (e?: MouseEvent) => void;
13
+ /** Props to spread onto the dialog component */
14
+ dialogProps: {
15
+ open: boolean;
16
+ onClose: () => void;
17
+ keepMounted: boolean;
18
+ };
19
+ }
7
20
  /**
8
21
  * Hook for managing dialog state and providing dialog control functions
9
22
  *
@@ -11,6 +24,8 @@ export interface UseDialogProps {
11
24
  * functions to open and close the dialog, along with props that can be
12
25
  * spread onto a Material-UI Dialog component.
13
26
  *
27
+ * Restores focus to the opening element, but only after the dialog has fully closed.
28
+ *
14
29
  * @example
15
30
  * // Basic usage
16
31
  * const { openDialog, closeDialog, dialogProps } = useDialog();
@@ -21,17 +36,8 @@ export interface UseDialogProps {
21
36
  *
22
37
  * @example
23
38
  * // With initial configuration
24
- * const { dialogProps } = useDialog({ keepMounted: false });
25
- *
39
+ * const { dialogProps } = useDialog({ keepMounted: true});
26
40
  *
27
41
  * @param props - Optional configuration options
28
42
  */
29
- export declare const useDialog: (props?: UseDialogProps) => {
30
- closeDialog: () => void;
31
- openDialog: () => void;
32
- dialogProps: {
33
- open: boolean;
34
- onClose: () => void;
35
- keepMounted: boolean;
36
- };
37
- };
43
+ export declare const useDialog: (props?: UseDialogProps) => UseDialogReturn;
@@ -2,7 +2,7 @@
2
2
  * Hook for accessing the FormDialog context values and functions
3
3
  *
4
4
  * This hook provides access to the form dialog state and controls managed by
5
- * the FormDialogProvider. It allows components to interact with dialog state,
5
+ * the FormDialogProvider. It allows components to interact with the dialog state,
6
6
  * including open/close status and form-wide disabled state.
7
7
  *
8
8
  * The context provides:
@@ -0,0 +1,29 @@
1
+ import { FieldValues, UseFormReturn } from "react-hook-form-mui";
2
+ export type PersistedFormProviderProps<T extends FieldValues> = {
3
+ /**
4
+ * A unique key for the form
5
+ */
6
+ formName: string | undefined;
7
+ /**
8
+ * Represents the context of a form, which is used to manage the state and actions of the form.
9
+ * The context is typically provided by a form management library and used to handle form inputs,
10
+ * validation, and submission.
11
+ */
12
+ formContext: UseFormReturn<T, any, T> | UseFormReturn<T> | undefined;
13
+ };
14
+ /**
15
+ * Hook that enables form state persistence across sessions
16
+ *
17
+ * This hook connects a form to persistent storage (e.g., sessionStorage)
18
+ * allowing form values to be preserved when navigating away and returning.
19
+ * It works by watching form changes and syncing with a zustand store.
20
+ *
21
+ * Key features:
22
+ * - Persists form values during navigation or page reloads
23
+ * - Automatically restores saved values when form is rendered
24
+ * - Debounced updates to avoid excessive storage operations
25
+ * - Only saves changed fields, not the entire form state
26
+ * - Automatically clears storage when form values match defaults
27
+ *
28
+ */
29
+ export declare const usePersistForm: <T extends FieldValues>({ formName, formContext }: PersistedFormProviderProps<T>) => void;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./components";
2
- export * from "./utils";
3
- export { usePersistedForm, useFormDialog, useDialog } from "./hooks";
2
+ export { usePersistForm, useFormDialog, useDialog } from "./hooks";
4
3
  export { FormDialogProvider } from "./state/FormDialogProvider";