@chris-c-brine/form-dialog 1.1.0 → 1.1.2

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,2 @@
1
- import { DialogProps } from "@mui/material";
2
- import type { Dispatch, SetStateAction } from 'react';
3
- export type FormDialogContextType = {
4
- open?: boolean;
5
- closeDialog?: DialogProps['onClose'];
6
- disabled: boolean;
7
- setDisabled: Dispatch<SetStateAction<boolean>>;
8
- };
1
+ import { FormDialogContextType } from "../types";
9
2
  export declare const FormDialogContext: import("react").Context<FormDialogContextType | undefined>;
@@ -1,13 +1,5 @@
1
- import { type FC, type PropsWithChildren } from "react";
2
- import { type FormDialogContextType } from "./FormDialogContext";
3
- /**
4
- * Props for the FormDialogProvider component
5
- *
6
- * Extends React's PropsWithChildren and allows optional passing of dialog state
7
- * (open state and close handler) directly to the provider.
8
- */
9
- export interface FormDialogProviderProps extends PropsWithChildren, Partial<Pick<FormDialogContextType, "open" | "closeDialog">> {
10
- }
1
+ import { type FC } from "react";
2
+ import { FormDialogProviderProps } from "../types";
11
3
  /**
12
4
  * Context provider component for form dialog state management
13
5
  *
@@ -1,9 +1,5 @@
1
- import type { FieldValue, FieldValues } from "react-hook-form";
2
- export interface FormStore<T extends FieldValues> {
3
- formData: Partial<Record<keyof T, FieldValue<T>>>;
4
- updateFormData: <K extends keyof T>(key: K, value: FieldValue<T>) => void;
5
- resetFormData: (key?: keyof T) => void;
6
- }
1
+ import type { FieldValues } from "react-hook-form";
2
+ import { FormStore } from "../types";
7
3
  /**
8
4
  * Factory function to create a form store with a custom storage name.
9
5
  *
@@ -0,0 +1,256 @@
1
+ import type { ButtonProps, DialogActionsProps, DialogContentProps, DialogProps, DialogTitleProps, GridProps, PaperProps } from "@mui/material";
2
+ import { type Dispatch, MouseEvent, PropsWithChildren, ReactNode, type SetStateAction } from "react";
3
+ import { FieldValues, type FormContainerProps, UseFormReturn } from "react-hook-form-mui";
4
+ import type { FieldValue } from "react-hook-form";
5
+ /**
6
+ * Props for the FormCancelButton component
7
+ */
8
+ export type FormCancelButtonProps = Omit<ButtonProps, "onClick"> & {
9
+ /** Whether to maintain any attempt counters when canceling */
10
+ keepCount?: boolean;
11
+ };
12
+ /**
13
+ * Props for the FormResetButton component
14
+ */
15
+ export type FormResetButtonProps = Omit<ButtonProps, "onClick"> & {
16
+ /**
17
+ * Whether to preserve the submission count when resetting the form
18
+ * When true, the form's submitCount will be maintained after reset
19
+ */
20
+ keepCount?: boolean;
21
+ /**
22
+ * A unique identifier for the form associated with this reset button
23
+ * When provided, also clears persisted form data from storage
24
+ */
25
+ formKey?: string;
26
+ };
27
+ /**
28
+ * Props for the FormSubmitButton component
29
+ */
30
+ export type FormSubmitButtonProps = Omit<LoadingButtonProps, "onClick"> & {
31
+ /**
32
+ * Whether to show the submission attempt count badge
33
+ */
34
+ showAttempts?: boolean;
35
+ /**
36
+ * Maximum number of submission attempts allowed
37
+ * When reached, the button displays a visual indicator
38
+ */
39
+ maxAttempts?: number;
40
+ };
41
+ /**
42
+ * Props for the LoadingButton component
43
+ */
44
+ export type LoadingButtonProps = ButtonProps & {
45
+ /**
46
+ * Controls the loading state of the button
47
+ * When false, displays a loading spinner; when true or undefined, displays normal content
48
+ */
49
+ loading?: boolean;
50
+ /**
51
+ * Optional icon to display when the button is not in loading state
52
+ * Can be used to provide a visual indicator of the button's action
53
+ */
54
+ altIcon?: ReactNode;
55
+ };
56
+ export type BaseDialogProps = BlackoutDialogProps & {
57
+ /**
58
+ * Title content for the dialog
59
+ * When provided, renders a DialogTitle component
60
+ */
61
+ title?: ReactNode;
62
+ /**
63
+ * Props passed to the DialogTitle component
64
+ * Only applied when the title is provided
65
+ */
66
+ titleProps?: DialogTitleProps;
67
+ /**
68
+ * Props passed to the DialogContent component
69
+ * Only applied when children are provided
70
+ */
71
+ contentProps?: DialogContentProps;
72
+ /**
73
+ * Action buttons for the dialog footer
74
+ * When provided, renders a DialogActions component
75
+ */
76
+ actions?: ReactNode;
77
+ /**
78
+ * Props passed to the DialogActions component
79
+ * Only applied when actions are provided
80
+ */
81
+ actionsProps?: DialogActionsProps;
82
+ /**
83
+ * Optional close button that appears in the header
84
+ * Positioned adjacent to the title
85
+ */
86
+ closeButton?: ReactNode;
87
+ };
88
+ export type BlackoutDialogProps = Omit<DialogProps, "title"> & {
89
+ /**
90
+ * An optional unique string identifier
91
+ * @default 'blackout-dialog'
92
+ */
93
+ id?: string;
94
+ /**
95
+ * Whether the dialog is currently visible.
96
+ * @default false
97
+ */
98
+ open: boolean;
99
+ /**
100
+ * Whether to apply a black overlay behind the dialog.
101
+ * @default false
102
+ */
103
+ blackout?: boolean;
104
+ };
105
+ /**
106
+ * Props for the FormDialog component
107
+ */
108
+ export type FormDialogProps<T extends FieldValues> = Omit<BaseDialogProps, "PaperComponent"> & CommonFormProps<T>;
109
+ /**
110
+ * Props for the FormDialogActions component
111
+ */
112
+ export type FormDialogActionsProps = Partial<PropsWithChildren> & {
113
+ /**
114
+ * Props to customize the cancel button
115
+ */
116
+ cancelProps?: FormCancelButtonProps;
117
+ /**
118
+ * Props to customize the reset button
119
+ */
120
+ resetProps?: FormResetButtonProps;
121
+ /**
122
+ * Props to customize the "submit button"
123
+ */
124
+ submitProps?: FormSubmitButtonProps;
125
+ /**
126
+ * Display variant for the buttons
127
+ * - "icon": Shows only icons
128
+ * - "text": Shows only text
129
+ * - "iconText": Shows both icons and text
130
+ */
131
+ variant?: "icon" | "text" | "iconText";
132
+ /**
133
+ * Whether to hide the cancel button completely
134
+ * @default false
135
+ */
136
+ removeCancelButton?: boolean;
137
+ /**
138
+ * Whether to hide the reset button completely
139
+ * @default false
140
+ */
141
+ removeResetButton?: boolean;
142
+ /**
143
+ * Props to customize the containing Grid
144
+ */
145
+ gridProps?: GridProps;
146
+ };
147
+ export type CommonFormProps<T extends FieldValues> = {
148
+ /**
149
+ * Props to configure the form container
150
+ * This includes settings for form state, validation, and submission handling
151
+ */
152
+ formProps: FormContainerProps<T>;
153
+ /**
154
+ * Optional key to use for form state persistence
155
+ * When provided, the form state will be persisted in
156
+ * session storage with a fallback to local storage (TODO: make configurable)
157
+ * and restored on form reload/mount.
158
+ */
159
+ persistKey?: string;
160
+ };
161
+ /**
162
+ * Props for the PaperForm component
163
+ */
164
+ export type PaperFormProps<T extends FieldValues> = PaperProps & CommonFormProps<T>;
165
+ /**
166
+ * Props for the PersistForm component
167
+ */
168
+ export interface PersistFormProps extends PropsWithChildren {
169
+ /**
170
+ * A unique identifier for the form
171
+ * This key is used to store and retrieve form data in the persistence layer
172
+ */
173
+ formName: string;
174
+ }
175
+ /**
176
+ * Props for the AutoGrid component
177
+ */
178
+ export type AutoGridProps = Omit<GridProps, "container" | "children"> & {
179
+ /**
180
+ * Array of React components to be arranged in the grid
181
+ */
182
+ components?: ReactNode[];
183
+ /**
184
+ * Number of columns to display (maximum 12 due to MUI Grid system)
185
+ * @default 1
186
+ */
187
+ columnCount?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
188
+ /**
189
+ * Alternative to columnCount, specifies the exact column widths (total must sum to 12)
190
+ *
191
+ * @default undefined
192
+ * @example
193
+ * // 3 columns
194
+ * columnWidths: [4, 4, 4]
195
+ * // 2 columns
196
+ * columnWidths: [4, 8]
197
+ * // 1 column
198
+ * columnWidths: [12] | columnCount: 1 | leave both blank
199
+ */
200
+ columnWidths?: number[];
201
+ };
202
+ export interface UseDialogProps {
203
+ /** Initial open state of the dialog */
204
+ open?: boolean;
205
+ /** Always keep the children in the DOM. */
206
+ keepMounted?: boolean;
207
+ }
208
+ export interface UseDialogReturn {
209
+ /** Function to close the dialog */
210
+ closeDialog: () => void;
211
+ /** Function to open the dialog */
212
+ openDialog: (e?: MouseEvent) => void;
213
+ /** Props to spread onto the dialog component */
214
+ dialogProps: {
215
+ open: boolean;
216
+ onClose: () => void;
217
+ keepMounted: boolean;
218
+ };
219
+ }
220
+ export type UseMaxAttemptProps = {
221
+ maxAttempts?: number;
222
+ };
223
+ export type PersistedFormProviderProps<T extends FieldValues> = {
224
+ /**
225
+ * A unique key for the form
226
+ */
227
+ formName: string | undefined;
228
+ /**
229
+ * Represents the context of a form, which is used to manage the state and actions of the form.
230
+ * The context is typically provided by a form management library and used to handle form inputs,
231
+ * validation, and submission.
232
+ */
233
+ formContext: UseFormReturn<T, any, T> | UseFormReturn<T> | undefined;
234
+ };
235
+ export interface FormStore<T extends FieldValues> {
236
+ formData: Partial<Record<keyof T, FieldValue<T>>>;
237
+ updateFormData: <K extends keyof T>(key: K, value: FieldValue<T>) => void;
238
+ resetFormData: (key?: keyof T) => void;
239
+ }
240
+ export type FormDialogContextType = {
241
+ open?: boolean;
242
+ closeDialog?: DialogProps['onClose'];
243
+ disabled: boolean;
244
+ setDisabled: Dispatch<SetStateAction<boolean>>;
245
+ };
246
+ /**
247
+ * Props for the FormDialogProvider component
248
+ *
249
+ * Extends React's PropsWithChildren and allows optional passing of dialog state
250
+ * (open state and close handler) directly to the provider.
251
+ */
252
+ export interface FormDialogProviderProps extends PropsWithChildren, Partial<Pick<FormDialogContextType, "open" | "closeDialog">> {
253
+ }
254
+ export type ApplyDefaultFormDialogPropsProps = Pick<FormDialogActionsProps, "resetProps" | "submitProps" | "variant"> & Partial<Pick<FormDialogActionsProps, "cancelProps">> & {
255
+ gridProps?: GridProps;
256
+ };
@@ -1,6 +1,2 @@
1
- import React, { ReactNode } from 'react';
2
- interface ThemeBridgeProps {
3
- children: ReactNode;
4
- }
5
- export declare const ThemeBridge: React.FC<ThemeBridgeProps>;
6
- export {};
1
+ import React, { PropsWithChildren } from 'react';
2
+ export declare const ThemeBridge: React.FC<PropsWithChildren>;