@chris-c-brine/form-dialog 1.1.0 → 1.1.1
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 +0 -2
- package/dist/components/AutoGrid.d.ts +2 -16
- package/dist/components/buttons/FormCancelButton.d.ts +0 -5
- package/dist/components/buttons/FormResetButton.d.ts +0 -16
- package/dist/components/buttons/FormSubmitButton.d.ts +1 -15
- package/dist/components/buttons/LoadingButton.d.ts +1 -17
- package/dist/components/dialogs/BaseDialog.d.ts +2 -35
- package/dist/components/dialogs/BlackoutDialog.d.ts +1 -18
- package/dist/components/dialogs/FormDialog.d.ts +1 -6
- package/dist/components/dialogs/FormDialogActions.d.ts +2 -43
- package/dist/components/forms/PaperForm.d.ts +2 -20
- package/dist/components/forms/PersistForm.d.ts +1 -11
- package/dist/hooks/useDialog.d.ts +1 -19
- package/dist/hooks/useFormDialog.d.ts +1 -1
- package/dist/hooks/useMaxAttempts.d.ts +1 -4
- package/dist/hooks/usePersistForm.d.ts +2 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +2 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/state/FormDialogContext.d.ts +1 -8
- package/dist/state/FormDialogProvider.d.ts +2 -10
- package/dist/state/createFormChangeStore.d.ts +2 -6
- package/dist/types.d.ts +243 -0
- package/dist/utils/ThemeBridge.d.ts +2 -6
- package/dist/utils/applyDefaultFormDialogProps.d.ts +109 -114
- package/package.json +1 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
export interface UseDialogProps {
|
|
190
|
+
/** Initial open state of the dialog */
|
|
191
|
+
open?: boolean;
|
|
192
|
+
/** Always keep the children in the DOM. */
|
|
193
|
+
keepMounted?: boolean;
|
|
194
|
+
}
|
|
195
|
+
export interface UseDialogReturn {
|
|
196
|
+
/** Function to close the dialog */
|
|
197
|
+
closeDialog: () => void;
|
|
198
|
+
/** Function to open the dialog */
|
|
199
|
+
openDialog: (e?: MouseEvent) => void;
|
|
200
|
+
/** Props to spread onto the dialog component */
|
|
201
|
+
dialogProps: {
|
|
202
|
+
open: boolean;
|
|
203
|
+
onClose: () => void;
|
|
204
|
+
keepMounted: boolean;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export type UseMaxAttemptProps = {
|
|
208
|
+
maxAttempts?: number;
|
|
209
|
+
};
|
|
210
|
+
export type PersistedFormProviderProps<T extends FieldValues> = {
|
|
211
|
+
/**
|
|
212
|
+
* A unique key for the form
|
|
213
|
+
*/
|
|
214
|
+
formName: string | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Represents the context of a form, which is used to manage the state and actions of the form.
|
|
217
|
+
* The context is typically provided by a form management library and used to handle form inputs,
|
|
218
|
+
* validation, and submission.
|
|
219
|
+
*/
|
|
220
|
+
formContext: UseFormReturn<T, any, T> | UseFormReturn<T> | undefined;
|
|
221
|
+
};
|
|
222
|
+
export interface FormStore<T extends FieldValues> {
|
|
223
|
+
formData: Partial<Record<keyof T, FieldValue<T>>>;
|
|
224
|
+
updateFormData: <K extends keyof T>(key: K, value: FieldValue<T>) => void;
|
|
225
|
+
resetFormData: (key?: keyof T) => void;
|
|
226
|
+
}
|
|
227
|
+
export type FormDialogContextType = {
|
|
228
|
+
open?: boolean;
|
|
229
|
+
closeDialog?: DialogProps['onClose'];
|
|
230
|
+
disabled: boolean;
|
|
231
|
+
setDisabled: Dispatch<SetStateAction<boolean>>;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Props for the FormDialogProvider component
|
|
235
|
+
*
|
|
236
|
+
* Extends React's PropsWithChildren and allows optional passing of dialog state
|
|
237
|
+
* (open state and close handler) directly to the provider.
|
|
238
|
+
*/
|
|
239
|
+
export interface FormDialogProviderProps extends PropsWithChildren, Partial<Pick<FormDialogContextType, "open" | "closeDialog">> {
|
|
240
|
+
}
|
|
241
|
+
export type ApplyDefaultFormDialogPropsProps = Pick<FormDialogActionsProps, "resetProps" | "submitProps" | "variant"> & Partial<Pick<FormDialogActionsProps, "cancelProps">> & {
|
|
242
|
+
gridProps?: GridProps;
|
|
243
|
+
};
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
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>;
|