@rokku-x/react-hook-dialog 1.0.0 → 1.0.3

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 +1,238 @@
1
- export { }
1
+ /**
2
+ * Valid return values from dialog actions.
3
+ * Can be string, number, boolean, or undefined.
4
+ */
5
+ export type ValidValue = string | number | boolean | undefined;
6
+ /**
7
+ * Available button variant types for styling action buttons.
8
+ */
9
+ export declare const variantTypes: readonly ["primary", "secondary", "danger", "success", "warning", "info", "neutral"];
10
+ /**
11
+ * Type union of all available button variants.
12
+ * @see variantTypes
13
+ */
14
+ export type ModalVariant = typeof variantTypes[number];
15
+ /**
16
+ * Configuration for an individual action button in a dialog.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const action: ModalAction = {
21
+ * title: 'Delete',
22
+ * value: true,
23
+ * variant: 'danger',
24
+ * onClick: (e) => console.log('Clicked!')
25
+ * };
26
+ * ```
27
+ */
28
+ export interface ModalAction {
29
+ /** The label or content displayed on the button */
30
+ title: React.ReactNode;
31
+ /** The value returned when this action is clicked */
32
+ value?: ValidValue;
33
+ /** If true, treats this as a cancel button (respects rejectOnCancel config) */
34
+ isCancel?: boolean;
35
+ /** If true, positions the button on the left side of the row */
36
+ isOnLeft?: boolean;
37
+ /** If true, this action should receive initial focus when the dialog opens */
38
+ isFocused?: boolean;
39
+ /** Visual style variant for the button */
40
+ variant?: ModalVariant;
41
+ /** Additional CSS class to apply to the button */
42
+ className?: string;
43
+ /** Inline styles to apply to the button */
44
+ style?: React.CSSProperties;
45
+ /** If true, renders the button as `type="submit"` to participate in native form submission */
46
+ isSubmit?: boolean;
47
+ /** If true, the button will NOT perform the default dialog action (won't call `handleAction`) — useful for custom handlers */
48
+ noActionReturn?: boolean;
49
+ /**
50
+ * Click handler called before the default action handling.
51
+ * Can receive both the event and action object, or just be called with no args.
52
+ */
53
+ onClick?: ((event: React.MouseEvent<HTMLButtonElement>, action: ModalAction) => void) | (() => void);
54
+ }
55
+ /**
56
+ * Custom CSS class names for dialog elements.
57
+ * All properties are optional and will be appended to default classes.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * const classNames: DialogClassNames = {
62
+ * dialog: 'my-custom-dialog',
63
+ * actionButton: 'my-button'
64
+ * };
65
+ * ```
66
+ */
67
+ export interface DialogClassNames {
68
+ /** CSS class for the backdrop overlay */
69
+ backdrop?: string;
70
+ /** CSS class for the dialog container */
71
+ dialog?: string;
72
+ /** CSS class for the close button */
73
+ closeButton?: string;
74
+ /** CSS class for the title element */
75
+ title?: string;
76
+ /** CSS class for the content container */
77
+ content?: string;
78
+ /** CSS class for the actions container */
79
+ actions?: string;
80
+ /** CSS class for each action button row */
81
+ actionsRow?: string;
82
+ /** CSS class for action buttons */
83
+ actionButton?: string;
84
+ }
85
+ /**
86
+ * Custom inline styles for dialog elements.
87
+ * All properties are optional and will be merged with default styles.
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * const styles: DialogStyles = {
92
+ * dialog: { borderRadius: '20px' },
93
+ * actionButton: { fontWeight: 'bold' }
94
+ * };
95
+ * ```
96
+ */
97
+ export interface DialogStyles {
98
+ /** Inline styles for the backdrop overlay */
99
+ backdrop?: React.CSSProperties;
100
+ /** Inline styles for the dialog container */
101
+ dialog?: React.CSSProperties;
102
+ /** Inline styles for the close button */
103
+ closeButton?: React.CSSProperties;
104
+ /** Inline styles for the title element */
105
+ title?: React.CSSProperties;
106
+ /** Inline styles for the content container */
107
+ content?: React.CSSProperties;
108
+ /** Inline styles for the actions container */
109
+ actions?: React.CSSProperties;
110
+ /** Inline styles for each action button row */
111
+ actionsRow?: React.CSSProperties;
112
+ /** Inline styles for action buttons */
113
+ actionButton?: React.CSSProperties;
114
+ }
115
+ /**
116
+ * Custom styles for button variants.
117
+ * Allows overriding the default color scheme for each variant type.
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * const variantStyles: DialogVariantStyles = {
122
+ * primary: { backgroundColor: '#7c3aed', color: '#fff' }
123
+ * };
124
+ * ```
125
+ */
126
+ export type DialogVariantStyles = Partial<Record<ModalVariant, React.CSSProperties>>;
127
+ /**
128
+ * Configuration options for a dialog call.
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * const config: ConfirmConfig = {
133
+ * title: 'Confirm',
134
+ * content: 'Are you sure?',
135
+ * actions: [[
136
+ * { title: 'Cancel', isCancel: true },
137
+ * { title: 'OK', variant: 'primary', value: true }
138
+ * ]]
139
+ * };
140
+ * ```
141
+ */
142
+ export interface ConfirmConfig {
143
+ /** Dialog title (can be string or React element) */
144
+ title?: React.ReactNode;
145
+ /** Dialog content (can be string or React element) */
146
+ content?: React.ReactNode;
147
+ /** If true, allows closing the dialog by clicking the backdrop (default: false) */
148
+ backdropCancel?: boolean;
149
+ /** If true, rejects the promise on cancel instead of resolving (default: true) */
150
+ rejectOnCancel?: boolean;
151
+ /** Value returned/rejected when dialog is cancelled */
152
+ defaultCancelValue?: ValidValue;
153
+ /** If true, shows the X close button in the top-right corner (default: false) */
154
+ showCloseButton?: boolean;
155
+ /** Custom CSS class names for dialog elements */
156
+ classNames?: DialogClassNames;
157
+ /** Custom inline styles for dialog elements */
158
+ styles?: DialogStyles;
159
+ /** Custom styles for button variants */
160
+ variantStyles?: DialogVariantStyles;
161
+ /**
162
+ * Array of action button rows. Each inner array represents a row of buttons.
163
+ * Buttons without isOnLeft flag are positioned on the right.
164
+ */
165
+ actions?: ModalAction[][];
166
+ /**
167
+ * If true and `content` is a `<form>`, clicking a submit action will return the submitted
168
+ * form values as the dialog result instead of using the action's `value`.
169
+ */
170
+ isReturnSubmit?: boolean;
171
+ }
172
+ /**
173
+ * Default configuration options for the useHookDialog hook.
174
+ * These settings apply to all dialogs created by the hook unless overridden per-call.
175
+ *
176
+ * @example
177
+ * ```tsx
178
+ * const defaultConfig: UseHookDialogConfig = {
179
+ * showCloseButton: false,
180
+ * backdropCancel: false,
181
+ * styles: { dialog: { maxWidth: '500px' } }
182
+ * };
183
+ * ```
184
+ */
185
+ export interface UseHookDialogConfig {
186
+ /** If true, allows closing dialogs by clicking the backdrop (default: false) */
187
+ backdropCancel?: boolean;
188
+ /** If true, rejects the promise on cancel instead of resolving (default: true) */
189
+ rejectOnCancel?: boolean;
190
+ /** Default value returned/rejected when dialog is cancelled */
191
+ defaultCancelValue?: ValidValue;
192
+ /** If true, shows the X close button in the top-right corner (default: false) */
193
+ showCloseButton?: boolean;
194
+ /** Default CSS class names for dialog elements */
195
+ classNames?: DialogClassNames;
196
+ /** Default inline styles for dialog elements */
197
+ styles?: DialogStyles;
198
+ /** Default styles for button variants */
199
+ variantStyles?: DialogVariantStyles;
200
+ }
201
+ /**
202
+ * Internal interface representing a dialog instance in the store.
203
+ * Extends ConfirmConfig with instance-specific properties.
204
+ * @internal
205
+ */
206
+ export interface ConfirmInstance<T = ValidValue> extends ConfirmConfig {
207
+ /** Unique identifier for this dialog instance */
208
+ id: string;
209
+ /** The configuration used for this dialog */
210
+ config: ConfirmConfig;
211
+ /** Promise resolve function */
212
+ resolve: (value: T) => void;
213
+ /** Promise reject function */
214
+ reject: (reason?: any) => void;
215
+ }
216
+ /**
217
+ * Props for the ModalWindow component.
218
+ * @internal
219
+ */
220
+ export interface ModalWindowProps {
221
+ /** Callback to close the modal */
222
+ handleClose: (id: string) => void;
223
+ /** Callback when an action button is clicked */
224
+ handleAction: HandleActionCallback;
225
+ /** Dialog configuration */
226
+ config: ConfirmConfig;
227
+ /** Unique identifier for this modal window */
228
+ modalWindowId: string;
229
+ }
230
+ interface HandleActionCallback {
231
+ (id: string, action: ModalAction, formValues: FormDataObject): void;
232
+ (id: string, action: ModalAction): void;
233
+ }
234
+ /**
235
+ * Friendly Form Data object type
236
+ */
237
+ export type FormDataObject = Record<string, FormDataEntryValue | FormDataEntryValue[]>;
238
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokku-x/react-hook-dialog",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "author": "rokku-x",
5
5
  "repository": {
6
6
  "type": "git",