@lerx/promise-modal 0.8.3 → 0.8.5
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 +53 -0
- package/dist/app/ModalManager.d.ts +5 -2
- package/dist/components/Anchor/style.d.ts +1 -0
- package/dist/core/handle/alert.d.ts +16 -148
- package/dist/core/handle/confirm.d.ts +18 -151
- package/dist/core/handle/index.d.ts +5 -3
- package/dist/core/handle/prompt.d.ts +23 -212
- package/dist/core/handle/static.d.ts +105 -0
- package/dist/core/handle/type.d.ts +99 -0
- package/dist/core/node/ModalNode/AbstractNode.d.ts +7 -5
- package/dist/core/node/ModalNode/AlertNode.d.ts +2 -2
- package/dist/core/node/ModalNode/ConfirmNode.d.ts +2 -2
- package/dist/core/node/ModalNode/PromptNode.d.ts +2 -2
- package/dist/helpers/closeModal.d.ts +2 -0
- package/dist/helpers/subscribeAbortSignal.d.ts +2 -0
- package/dist/hooks/useModal.d.ts +6 -0
- package/dist/index.cjs +238 -171
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +239 -173
- package/dist/providers/ConfigurationContext/ConfigurationContext.d.ts +4 -2
- package/dist/providers/ConfigurationContext/useConfigurationContext.d.ts +3 -1
- package/dist/providers/ModalManagerContext/ModalManagerContext.d.ts +0 -1
- package/dist/providers/ModalManagerContext/index.d.ts +1 -1
- package/dist/providers/ModalManagerContext/useModalManagerContext.d.ts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/types/base.d.ts +2 -1
- package/dist/types/option.d.ts +2 -2
- package/package.json +2 -2
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,234 +1,45 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { BackgroundComponent, FooterOptions, ForegroundComponent, ModalBackground, PromptContentProps, PromptFooterRender, PromptInputProps } from '../../types';
|
|
4
|
-
interface PromptProps<InputValue, BackgroundValue = any> {
|
|
5
|
-
group?: string;
|
|
6
|
-
title?: ReactNode;
|
|
7
|
-
subtitle?: ReactNode;
|
|
8
|
-
content?: ReactNode | ComponentType<PromptContentProps>;
|
|
9
|
-
defaultValue?: InputValue;
|
|
10
|
-
Input: Fn<[props: PromptInputProps<InputValue>], ReactNode>;
|
|
11
|
-
disabled?: Fn<[value: InputValue], boolean>;
|
|
12
|
-
returnOnCancel?: boolean;
|
|
13
|
-
background?: ModalBackground<BackgroundValue>;
|
|
14
|
-
footer?: PromptFooterRender<InputValue> | FooterOptions | false;
|
|
15
|
-
dimmed?: boolean;
|
|
16
|
-
manualDestroy?: boolean;
|
|
17
|
-
closeOnBackdropClick?: boolean;
|
|
18
|
-
ForegroundComponent?: ForegroundComponent;
|
|
19
|
-
BackgroundComponent?: BackgroundComponent;
|
|
20
|
-
}
|
|
1
|
+
import type { PromptNode } from '../../core';
|
|
2
|
+
import type { PromptProps } from './type';
|
|
21
3
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* Creates a modal dialog with a custom input component and confirmation/cancel buttons.
|
|
25
|
-
* The promise resolves with the input value when confirmed, or rejects when cancelled
|
|
26
|
-
* (unless `returnOnCancel` is true).
|
|
4
|
+
* Creates and manages a Prompt modal.
|
|
27
5
|
*
|
|
28
6
|
* @typeParam InputValue - Type of the value collected from user input
|
|
29
7
|
* @typeParam BackgroundValue - Type of background data passed to BackgroundComponent
|
|
30
|
-
* @param
|
|
31
|
-
* @returns
|
|
32
|
-
*
|
|
8
|
+
* @param args - Prompt modal configuration options
|
|
9
|
+
* @returns Object containing modalNode and promiseHandler
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - modalNode: The created modal node instance
|
|
13
|
+
* - promiseHandler: Promise that resolves with user input value
|
|
14
|
+
* - Input component receives value, onChange, onConfirm, onCancel, and context props
|
|
15
|
+
* - Use disabled function to control confirm button's enabled state
|
|
16
|
+
* - If returnOnCancel is false (default), promise rejects on cancel
|
|
17
|
+
* - If returnOnCancel is true, returns defaultValue on cancel
|
|
33
18
|
*
|
|
34
19
|
* @example
|
|
35
|
-
* Basic text input:
|
|
36
20
|
* ```tsx
|
|
37
|
-
* const
|
|
21
|
+
* const { modalNode, promiseHandler } = promptHandler<string>({
|
|
38
22
|
* title: 'Enter Your Name',
|
|
39
|
-
* content: 'Please enter your full name for the certificate.',
|
|
40
23
|
* Input: ({ value, onChange, onConfirm }) => (
|
|
41
24
|
* <input
|
|
42
25
|
* type="text"
|
|
43
26
|
* value={value || ''}
|
|
44
27
|
* onChange={(e) => onChange(e.target.value)}
|
|
45
28
|
* onKeyPress={(e) => e.key === 'Enter' && onConfirm()}
|
|
46
|
-
* autoFocus
|
|
47
|
-
* />
|
|
48
|
-
* ),
|
|
49
|
-
* defaultValue: 'John Doe',
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* Number input with validation:
|
|
55
|
-
* ```tsx
|
|
56
|
-
* const age = await prompt<number>({
|
|
57
|
-
* title: 'Enter Your Age',
|
|
58
|
-
* content: 'Must be between 18 and 100',
|
|
59
|
-
* Input: ({ value, onChange }) => (
|
|
60
|
-
* <input
|
|
61
|
-
* type="number"
|
|
62
|
-
* min="18"
|
|
63
|
-
* max="100"
|
|
64
|
-
* value={value || ''}
|
|
65
|
-
* onChange={(e) => onChange(parseInt(e.target.value))}
|
|
66
29
|
* />
|
|
67
30
|
* ),
|
|
68
|
-
*
|
|
69
|
-
* defaultValue: 25,
|
|
31
|
+
* defaultValue: '',
|
|
70
32
|
* });
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* Select dropdown:
|
|
75
|
-
* ```tsx
|
|
76
|
-
* interface Theme {
|
|
77
|
-
* id: string;
|
|
78
|
-
* name: string;
|
|
79
|
-
* primary: string;
|
|
80
|
-
* }
|
|
81
|
-
*
|
|
82
|
-
* const theme = await prompt<Theme>({
|
|
83
|
-
* title: 'Choose Theme',
|
|
84
|
-
* Input: ({ value, onChange }) => (
|
|
85
|
-
* <select
|
|
86
|
-
* value={value?.id || ''}
|
|
87
|
-
* onChange={(e) => {
|
|
88
|
-
* const selected = themes.find(t => t.id === e.target.value);
|
|
89
|
-
* onChange(selected);
|
|
90
|
-
* }}
|
|
91
|
-
* >
|
|
92
|
-
* <option value="">Select a theme...</option>
|
|
93
|
-
* {themes.map(theme => (
|
|
94
|
-
* <option key={theme.id} value={theme.id}>
|
|
95
|
-
* {theme.name}
|
|
96
|
-
* </option>
|
|
97
|
-
* ))}
|
|
98
|
-
* </select>
|
|
99
|
-
* ),
|
|
100
|
-
* disabled: (value) => !value,
|
|
101
|
-
* });
|
|
102
|
-
* ```
|
|
103
33
|
*
|
|
104
|
-
* @example
|
|
105
|
-
* Multi-field form:
|
|
106
|
-
* ```tsx
|
|
107
|
-
* interface UserData {
|
|
108
|
-
* username: string;
|
|
109
|
-
* email: string;
|
|
110
|
-
* subscribe: boolean;
|
|
111
|
-
* }
|
|
112
|
-
*
|
|
113
|
-
* const userData = await prompt<UserData>({
|
|
114
|
-
* title: 'Create Account',
|
|
115
|
-
* Input: ({ value, onChange }) => {
|
|
116
|
-
* const data = value || { username: '', email: '', subscribe: false };
|
|
117
|
-
*
|
|
118
|
-
* return (
|
|
119
|
-
* <div className="form">
|
|
120
|
-
* <input
|
|
121
|
-
* placeholder="Username"
|
|
122
|
-
* value={data.username}
|
|
123
|
-
* onChange={(e) => onChange({ ...data, username: e.target.value })}
|
|
124
|
-
* />
|
|
125
|
-
* <input
|
|
126
|
-
* type="email"
|
|
127
|
-
* placeholder="Email"
|
|
128
|
-
* value={data.email}
|
|
129
|
-
* onChange={(e) => onChange({ ...data, email: e.target.value })}
|
|
130
|
-
* />
|
|
131
|
-
* <label>
|
|
132
|
-
* <input
|
|
133
|
-
* type="checkbox"
|
|
134
|
-
* checked={data.subscribe}
|
|
135
|
-
* onChange={(e) => onChange({ ...data, subscribe: e.target.checked })}
|
|
136
|
-
* />
|
|
137
|
-
* Subscribe to newsletter
|
|
138
|
-
* </label>
|
|
139
|
-
* </div>
|
|
140
|
-
* );
|
|
141
|
-
* },
|
|
142
|
-
* disabled: (value) => !value?.username || !value?.email,
|
|
143
|
-
* });
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* File upload:
|
|
148
|
-
* ```tsx
|
|
149
|
-
* const file = await prompt<File>({
|
|
150
|
-
* title: 'Upload Avatar',
|
|
151
|
-
* content: 'Select an image file (max 5MB)',
|
|
152
|
-
* Input: ({ value, onChange }) => (
|
|
153
|
-
* <div>
|
|
154
|
-
* <input
|
|
155
|
-
* type="file"
|
|
156
|
-
* accept="image/*"
|
|
157
|
-
* onChange={(e) => {
|
|
158
|
-
* const file = e.target.files?.[0];
|
|
159
|
-
* if (file && file.size <= 5 * 1024 * 1024) {
|
|
160
|
-
* onChange(file);
|
|
161
|
-
* }
|
|
162
|
-
* }}
|
|
163
|
-
* />
|
|
164
|
-
* {value && (
|
|
165
|
-
* <div>
|
|
166
|
-
* <img src={URL.createObjectURL(value)} alt="Preview" />
|
|
167
|
-
* <p>{value.name} ({(value.size / 1024).toFixed(1)} KB)</p>
|
|
168
|
-
* </div>
|
|
169
|
-
* )}
|
|
170
|
-
* </div>
|
|
171
|
-
* ),
|
|
172
|
-
* disabled: (value) => !value,
|
|
173
|
-
* });
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* With error handling:
|
|
178
|
-
* ```tsx
|
|
179
34
|
* try {
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* <EmailInput
|
|
185
|
-
* value={value}
|
|
186
|
-
* onChange={onChange}
|
|
187
|
-
* error={context.error}
|
|
188
|
-
* />
|
|
189
|
-
* ),
|
|
190
|
-
* });
|
|
191
|
-
*
|
|
192
|
-
* await sendResetEmail(email);
|
|
193
|
-
* } catch (error) {
|
|
194
|
-
* // User cancelled the prompt
|
|
195
|
-
* console.log('Password reset cancelled');
|
|
35
|
+
* const name = await promiseHandler;
|
|
36
|
+
* console.log('User entered:', name);
|
|
37
|
+
* } catch {
|
|
38
|
+
* console.log('User cancelled');
|
|
196
39
|
* }
|
|
197
40
|
* ```
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* Custom footer with validation:
|
|
201
|
-
* ```tsx
|
|
202
|
-
* const password = await prompt<string>({
|
|
203
|
-
* title: 'Set New Password',
|
|
204
|
-
* Input: ({ value, onChange }) => (
|
|
205
|
-
* <PasswordInput value={value} onChange={onChange} />
|
|
206
|
-
* ),
|
|
207
|
-
* footer: ({ value, onChange, onConfirm, onCancel, disabled }) => (
|
|
208
|
-
* <div>
|
|
209
|
-
* <PasswordStrength password={value} />
|
|
210
|
-
* <div className="buttons">
|
|
211
|
-
* <button onClick={onCancel}>Cancel</button>
|
|
212
|
-
* <button
|
|
213
|
-
* onClick={onConfirm}
|
|
214
|
-
* disabled={disabled}
|
|
215
|
-
* className={disabled ? 'disabled' : 'primary'}
|
|
216
|
-
* >
|
|
217
|
-
* Set Password
|
|
218
|
-
* </button>
|
|
219
|
-
* </div>
|
|
220
|
-
* </div>
|
|
221
|
-
* ),
|
|
222
|
-
* disabled: (value) => !value || value.length < 8,
|
|
223
|
-
* });
|
|
224
|
-
* ```
|
|
225
|
-
*
|
|
226
|
-
* @remarks
|
|
227
|
-
* - The Input component receives value, onChange, onConfirm, onCancel, and context props
|
|
228
|
-
* - Use the `disabled` function to control when the confirm button is enabled
|
|
229
|
-
* - Set `returnOnCancel: true` to return defaultValue instead of rejecting on cancel
|
|
230
|
-
* - The promise rejects when cancelled (unless returnOnCancel is set)
|
|
231
|
-
* - Use onConfirm prop in Input to handle Enter key submission
|
|
232
41
|
*/
|
|
233
|
-
export declare const
|
|
234
|
-
|
|
42
|
+
export declare const promptHandler: <InputValue, BackgroundValue = any>(args: PromptProps<InputValue, BackgroundValue>) => {
|
|
43
|
+
readonly modalNode: PromptNode<InputValue, BackgroundValue>;
|
|
44
|
+
readonly promiseHandler: Promise<InputValue>;
|
|
45
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { AlertProps, ConfirmProps, PromptProps } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* Displays a promise-based alert modal.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam BackgroundValue - Type of background data passed to BackgroundComponent
|
|
6
|
+
* @param args - Alert modal configuration options
|
|
7
|
+
* @returns Promise that resolves when the modal is closed
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* await alert({
|
|
12
|
+
* title: 'Success!',
|
|
13
|
+
* content: 'Your changes have been saved.',
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* With subtype styling:
|
|
19
|
+
* ```tsx
|
|
20
|
+
* alert({
|
|
21
|
+
* subtype: 'error',
|
|
22
|
+
* title: 'Operation Failed',
|
|
23
|
+
* content: 'Unable to connect to server.',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const alert: <BackgroundValue = any>(args: AlertProps<BackgroundValue>) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Displays a promise-based confirmation modal with boolean result.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam BackgroundValue - Type of background data passed to BackgroundComponent
|
|
32
|
+
* @param args - Confirmation modal configuration options
|
|
33
|
+
* @returns Promise that resolves to true if confirmed, false if cancelled
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const shouldDelete = await confirm({
|
|
38
|
+
* title: 'Delete Item?',
|
|
39
|
+
* content: 'This action cannot be undone.',
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* if (shouldDelete) {
|
|
43
|
+
* await deleteItem();
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* Destructive action warning:
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const shouldProceed = await confirm({
|
|
51
|
+
* subtype: 'error',
|
|
52
|
+
* title: 'Delete Account',
|
|
53
|
+
* content: 'All data will be permanently lost.',
|
|
54
|
+
* footer: {
|
|
55
|
+
* confirm: 'Delete Account',
|
|
56
|
+
* cancel: 'Keep Account',
|
|
57
|
+
* confirmDanger: true,
|
|
58
|
+
* },
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const confirm: <BackgroundValue = any>(args: ConfirmProps<BackgroundValue>) => Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Displays a promise-based prompt modal to collect user input.
|
|
65
|
+
*
|
|
66
|
+
* @typeParam InputValue - Type of the value collected from user input
|
|
67
|
+
* @typeParam BackgroundValue - Type of background data passed to BackgroundComponent
|
|
68
|
+
* @param args - Prompt modal configuration options
|
|
69
|
+
* @returns Promise that resolves with user input value
|
|
70
|
+
* @throws Rejects when cancelled (unless returnOnCancel is true)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* const name = await prompt<string>({
|
|
75
|
+
* title: 'Enter Your Name',
|
|
76
|
+
* Input: ({ value, onChange, onConfirm }) => (
|
|
77
|
+
* <input
|
|
78
|
+
* type="text"
|
|
79
|
+
* value={value || ''}
|
|
80
|
+
* onChange={(e) => onChange(e.target.value)}
|
|
81
|
+
* onKeyPress={(e) => e.key === 'Enter' && onConfirm()}
|
|
82
|
+
* autoFocus
|
|
83
|
+
* />
|
|
84
|
+
* ),
|
|
85
|
+
* defaultValue: 'John Doe',
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* Number input with validation:
|
|
91
|
+
* ```tsx
|
|
92
|
+
* const age = await prompt<number>({
|
|
93
|
+
* title: 'Enter Your Age',
|
|
94
|
+
* Input: ({ value, onChange }) => (
|
|
95
|
+
* <input
|
|
96
|
+
* type="number"
|
|
97
|
+
* value={value || ''}
|
|
98
|
+
* onChange={(e) => onChange(parseInt(e.target.value))}
|
|
99
|
+
* />
|
|
100
|
+
* ),
|
|
101
|
+
* disabled: (value) => !value || value < 18 || value > 100,
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare const prompt: <InputValue, BackgroundValue = any>(args: PromptProps<InputValue, BackgroundValue>) => Promise<InputValue>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { Fn } from '../../@aileron/declare';
|
|
3
|
+
import type { AlertContentProps, AlertFooterRender, BackgroundComponent, ConfirmContentProps, ConfirmFooterRender, FooterOptions, ForegroundComponent, ModalBackground, PromptContentProps, PromptFooterRender, PromptInputProps } from '../../types';
|
|
4
|
+
export interface AlertProps<BackgroundValue> {
|
|
5
|
+
/** Modal group identifier for managing related modals */
|
|
6
|
+
group?: string;
|
|
7
|
+
/** Alert subtype that affects UI styling */
|
|
8
|
+
subtype?: 'info' | 'success' | 'warning' | 'error';
|
|
9
|
+
/** Modal title */
|
|
10
|
+
title?: ReactNode;
|
|
11
|
+
/** Modal subtitle */
|
|
12
|
+
subtitle?: ReactNode;
|
|
13
|
+
/** Modal content. Can be a ReactNode or a component */
|
|
14
|
+
content?: ReactNode | ComponentType<AlertContentProps>;
|
|
15
|
+
/** Background layer data and configuration */
|
|
16
|
+
background?: ModalBackground<BackgroundValue>;
|
|
17
|
+
/** Footer configuration. Can be a render function, options object, or false */
|
|
18
|
+
footer?: AlertFooterRender | Pick<FooterOptions, 'confirm' | 'hideConfirm'> | false;
|
|
19
|
+
/** Abort signal to cancel the modal */
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
/** Whether to dim the background */
|
|
22
|
+
dimmed?: boolean;
|
|
23
|
+
/** Modal animation duration in milliseconds */
|
|
24
|
+
duration?: number;
|
|
25
|
+
/** If true, keeps modal in DOM after closing (for animations) */
|
|
26
|
+
manualDestroy?: boolean;
|
|
27
|
+
/** Whether to close modal on backdrop click */
|
|
28
|
+
closeOnBackdropClick?: boolean;
|
|
29
|
+
/** Custom foreground component */
|
|
30
|
+
ForegroundComponent?: ForegroundComponent;
|
|
31
|
+
/** Custom background component */
|
|
32
|
+
BackgroundComponent?: BackgroundComponent;
|
|
33
|
+
}
|
|
34
|
+
export interface ConfirmProps<BackgroundValue> {
|
|
35
|
+
/** Modal group identifier for managing related modals */
|
|
36
|
+
group?: string;
|
|
37
|
+
/** Confirmation subtype that affects UI styling */
|
|
38
|
+
subtype?: 'info' | 'success' | 'warning' | 'error';
|
|
39
|
+
/** Modal title */
|
|
40
|
+
title?: ReactNode;
|
|
41
|
+
/** Modal subtitle */
|
|
42
|
+
subtitle?: ReactNode;
|
|
43
|
+
/** Modal content. Can be a ReactNode or a component */
|
|
44
|
+
content?: ReactNode | ComponentType<ConfirmContentProps>;
|
|
45
|
+
/** Background layer data and configuration */
|
|
46
|
+
background?: ModalBackground<BackgroundValue>;
|
|
47
|
+
/** Footer configuration. Can be a render function, options object, or false */
|
|
48
|
+
footer?: ConfirmFooterRender | FooterOptions | false;
|
|
49
|
+
/** Abort signal to cancel the modal */
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
/** Whether to dim the background */
|
|
52
|
+
dimmed?: boolean;
|
|
53
|
+
/** Modal animation duration in milliseconds */
|
|
54
|
+
duration?: number;
|
|
55
|
+
/** If true, keeps modal in DOM after closing (for animations) */
|
|
56
|
+
manualDestroy?: boolean;
|
|
57
|
+
/** Whether to close modal on backdrop click */
|
|
58
|
+
closeOnBackdropClick?: boolean;
|
|
59
|
+
/** Custom foreground component */
|
|
60
|
+
ForegroundComponent?: ForegroundComponent;
|
|
61
|
+
/** Custom background component */
|
|
62
|
+
BackgroundComponent?: BackgroundComponent;
|
|
63
|
+
}
|
|
64
|
+
export interface PromptProps<InputValue, BackgroundValue = any> {
|
|
65
|
+
/** Modal group identifier for managing related modals */
|
|
66
|
+
group?: string;
|
|
67
|
+
/** Modal title */
|
|
68
|
+
title?: ReactNode;
|
|
69
|
+
/** Modal subtitle */
|
|
70
|
+
subtitle?: ReactNode;
|
|
71
|
+
/** Modal content. Can be a ReactNode or a component */
|
|
72
|
+
content?: ReactNode | ComponentType<PromptContentProps>;
|
|
73
|
+
/** Initial value for the input field */
|
|
74
|
+
defaultValue?: InputValue;
|
|
75
|
+
/** Input component that receives value, onChange, and other props */
|
|
76
|
+
Input: Fn<[props: PromptInputProps<InputValue>], ReactNode>;
|
|
77
|
+
/** Validation function. Returns true to disable the confirm button */
|
|
78
|
+
disabled?: Fn<[value: InputValue], boolean>;
|
|
79
|
+
/** If true, returns defaultValue instead of rejecting on cancel */
|
|
80
|
+
returnOnCancel?: boolean;
|
|
81
|
+
/** Background layer data and configuration */
|
|
82
|
+
background?: ModalBackground<BackgroundValue>;
|
|
83
|
+
/** Footer configuration. Can be a render function, options object, or false */
|
|
84
|
+
footer?: PromptFooterRender<InputValue> | FooterOptions | false;
|
|
85
|
+
/** Abort signal to cancel the modal */
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
/** Whether to dim the background */
|
|
88
|
+
dimmed?: boolean;
|
|
89
|
+
/** Modal animation duration in milliseconds */
|
|
90
|
+
duration?: number;
|
|
91
|
+
/** If true, keeps modal in DOM after closing (for animations) */
|
|
92
|
+
manualDestroy?: boolean;
|
|
93
|
+
/** Whether to close modal on backdrop click */
|
|
94
|
+
closeOnBackdropClick?: boolean;
|
|
95
|
+
/** Custom foreground component */
|
|
96
|
+
ForegroundComponent?: ForegroundComponent;
|
|
97
|
+
/** Custom background component */
|
|
98
|
+
BackgroundComponent?: BackgroundComponent;
|
|
99
|
+
}
|
|
@@ -10,21 +10,23 @@ export declare abstract class AbstractNode<T, B> {
|
|
|
10
10
|
readonly title?: ReactNode;
|
|
11
11
|
readonly subtitle?: ReactNode;
|
|
12
12
|
readonly background?: ModalBackground<B>;
|
|
13
|
+
readonly dimmed: boolean;
|
|
14
|
+
readonly duration: number;
|
|
13
15
|
readonly manualDestroy: boolean;
|
|
14
16
|
readonly closeOnBackdropClick: boolean;
|
|
15
|
-
readonly dimmed: boolean;
|
|
16
17
|
readonly ForegroundComponent?: ForegroundComponent;
|
|
17
18
|
readonly BackgroundComponent?: BackgroundComponent;
|
|
18
19
|
get alive(): boolean;
|
|
19
20
|
get visible(): boolean;
|
|
20
|
-
|
|
21
|
+
set handleResolve(handleResolve: Fn<[result: T | null]>);
|
|
22
|
+
constructor({ id, initiator, group, title, subtitle, background, dimmed, duration, manualDestroy, closeOnBackdropClick, handleResolve, ForegroundComponent, BackgroundComponent, }: AbstractNodeProps<T, B>);
|
|
23
|
+
abstract onClose(): void;
|
|
24
|
+
abstract onConfirm(): void;
|
|
25
|
+
protected onResolve(result: T | null): void;
|
|
21
26
|
subscribe(listener: Fn): () => void;
|
|
22
27
|
publish(): void;
|
|
23
|
-
protected resolve(result: T | null): void;
|
|
24
28
|
onDestroy(): void;
|
|
25
29
|
onShow(): void;
|
|
26
30
|
onHide(): void;
|
|
27
|
-
abstract onClose(): void;
|
|
28
|
-
abstract onConfirm(): void;
|
|
29
31
|
}
|
|
30
32
|
export {};
|
|
@@ -2,12 +2,12 @@ import type { ComponentType, ReactNode } from 'react';
|
|
|
2
2
|
import type { AlertContentProps, AlertFooterRender, AlertModal, FooterOptions, ManagedEntity } from '../../../types';
|
|
3
3
|
import { AbstractNode } from './AbstractNode';
|
|
4
4
|
type AlertNodeProps<B> = AlertModal<B> & ManagedEntity;
|
|
5
|
-
export declare class AlertNode<B> extends AbstractNode<null, B> {
|
|
5
|
+
export declare class AlertNode<B = any> extends AbstractNode<null, B> {
|
|
6
6
|
readonly type: 'alert';
|
|
7
7
|
readonly subtype?: 'info' | 'success' | 'warning' | 'error';
|
|
8
8
|
readonly content?: ReactNode | ComponentType<AlertContentProps>;
|
|
9
9
|
readonly footer?: AlertFooterRender | Pick<FooterOptions, 'confirm' | 'hideConfirm'> | false;
|
|
10
|
-
constructor({ id, group, initiator, type, subtype, title, subtitle, content, footer, background, dimmed, manualDestroy, closeOnBackdropClick,
|
|
10
|
+
constructor({ id, group, initiator, type, subtype, title, subtitle, content, footer, background, dimmed, duration, manualDestroy, closeOnBackdropClick, handleResolve, ForegroundComponent, BackgroundComponent, }: AlertNodeProps<B>);
|
|
11
11
|
onClose(): void;
|
|
12
12
|
onConfirm(): void;
|
|
13
13
|
}
|
|
@@ -2,12 +2,12 @@ import type { ComponentType, ReactNode } from 'react';
|
|
|
2
2
|
import type { ConfirmContentProps, ConfirmFooterRender, ConfirmModal, FooterOptions, ManagedEntity } from '../../../types';
|
|
3
3
|
import { AbstractNode } from './AbstractNode';
|
|
4
4
|
type ConfirmNodeProps<B> = ConfirmModal<B> & ManagedEntity;
|
|
5
|
-
export declare class ConfirmNode<B> extends AbstractNode<boolean, B> {
|
|
5
|
+
export declare class ConfirmNode<B = any> extends AbstractNode<boolean, B> {
|
|
6
6
|
readonly type: 'confirm';
|
|
7
7
|
readonly subtype?: 'info' | 'success' | 'warning' | 'error';
|
|
8
8
|
readonly content?: ReactNode | ComponentType<ConfirmContentProps>;
|
|
9
9
|
readonly footer?: ConfirmFooterRender | FooterOptions | false;
|
|
10
|
-
constructor({ id, group, initiator, type, subtype, title, subtitle, content, footer, background, dimmed, manualDestroy, closeOnBackdropClick,
|
|
10
|
+
constructor({ id, group, initiator, type, subtype, title, subtitle, content, footer, background, dimmed, duration, manualDestroy, closeOnBackdropClick, handleResolve, ForegroundComponent, BackgroundComponent, }: ConfirmNodeProps<B>);
|
|
11
11
|
onClose(): void;
|
|
12
12
|
onConfirm(): void;
|
|
13
13
|
}
|
|
@@ -3,7 +3,7 @@ import type { Fn } from '../../../@aileron/declare';
|
|
|
3
3
|
import type { FooterOptions, ManagedEntity, PromptContentProps, PromptFooterRender, PromptInputProps, PromptModal } from '../../../types';
|
|
4
4
|
import { AbstractNode } from './AbstractNode';
|
|
5
5
|
type PromptNodeProps<T, B> = PromptModal<T, B> & ManagedEntity;
|
|
6
|
-
export declare class PromptNode<T, B> extends AbstractNode<T, B> {
|
|
6
|
+
export declare class PromptNode<T = any, B = any> extends AbstractNode<T, B> {
|
|
7
7
|
#private;
|
|
8
8
|
readonly type: 'prompt';
|
|
9
9
|
readonly content?: ReactNode | ComponentType<PromptContentProps>;
|
|
@@ -12,7 +12,7 @@ export declare class PromptNode<T, B> extends AbstractNode<T, B> {
|
|
|
12
12
|
readonly disabled?: Fn<[value: T], boolean>;
|
|
13
13
|
readonly returnOnCancel?: boolean;
|
|
14
14
|
readonly footer?: PromptFooterRender<T> | FooterOptions | false;
|
|
15
|
-
constructor({ id, group, initiator, type, title, subtitle, content, defaultValue, Input, disabled, returnOnCancel, footer, background, dimmed, manualDestroy, closeOnBackdropClick,
|
|
15
|
+
constructor({ id, group, initiator, type, title, subtitle, content, defaultValue, Input, disabled, returnOnCancel, footer, background, dimmed, duration, manualDestroy, closeOnBackdropClick, handleResolve, ForegroundComponent, BackgroundComponent, }: PromptNodeProps<T, B>);
|
|
16
16
|
onChange(value: T): void;
|
|
17
17
|
onConfirm(): void;
|
|
18
18
|
onClose(): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AlertProps, type ConfirmProps, type PromptProps } from '../core';
|
|
2
|
+
export declare const useModal: () => {
|
|
3
|
+
readonly alert: <BackgroundValue = any>(args: AlertProps<BackgroundValue>) => Promise<void>;
|
|
4
|
+
readonly confirm: <BackgroundValue = any>(args: ConfirmProps<BackgroundValue>) => Promise<boolean>;
|
|
5
|
+
readonly prompt: <InputValue, BackgroundValue = any>(args: PromptProps<InputValue, BackgroundValue>) => Promise<InputValue>;
|
|
6
|
+
};
|