react-motion-modal 1.1.9 → 1.2.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/CHANGELOG.md +45 -0
- package/dist/index.d.ts +172 -10
- package/dist/index.js +1945 -1921
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
### Deprecated
|
|
15
|
+
|
|
16
|
+
### Removed
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Type definitions now properly import required dependencies
|
|
20
|
+
- Documentation examples updated to reflect current API
|
|
21
|
+
|
|
22
|
+
## [1.1.9]
|
|
23
|
+
### Added
|
|
24
|
+
- Responsive design improvements
|
|
25
|
+
- Better modal stacking behavior
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- Modal closing logic issues
|
|
29
|
+
- CSS rendering problems
|
|
30
|
+
|
|
31
|
+
## [1.1.8]
|
|
32
|
+
### Added
|
|
33
|
+
- Streamlined modal closing logic
|
|
34
|
+
- Performance optimizations
|
|
35
|
+
|
|
36
|
+
### Removed
|
|
37
|
+
- Unused CSS styles
|
|
38
|
+
|
|
39
|
+
## [1.1.7]
|
|
40
|
+
### Fixed
|
|
41
|
+
- Bug fixes and stability improvements
|
|
42
|
+
|
|
43
|
+
## [Previous Versions]
|
|
44
|
+
|
|
45
|
+
For versions prior to 1.1.7, please refer to the git commit history.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,60 +4,183 @@ import { StoreApi } from 'zustand/vanilla';
|
|
|
4
4
|
import { TargetAndTransition } from 'motion';
|
|
5
5
|
import { UseBoundStore } from 'zustand/react';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Represents a currently active (opened) modal instance.
|
|
9
|
+
* Each modal gets a unique ID and maintains its state in the modal stack.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const modal: ActiveModal = {
|
|
14
|
+
* id: 'uuid-123',
|
|
15
|
+
* name: 'alert',
|
|
16
|
+
* params: { message: 'Hello', closeModal: () => {}, onClose: () => {} }
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
7
20
|
declare type ActiveModal = {
|
|
21
|
+
/**
|
|
22
|
+
* Unique identifier for this modal instance.
|
|
23
|
+
* Generated automatically when the modal is opened.
|
|
24
|
+
*/
|
|
8
25
|
id: string;
|
|
26
|
+
/**
|
|
27
|
+
* The name/type of the modal (key from ModalDefinition).
|
|
28
|
+
*/
|
|
9
29
|
name: ModalName;
|
|
30
|
+
/**
|
|
31
|
+
* Parameters passed to the modal, including both custom params and base modal params.
|
|
32
|
+
*/
|
|
10
33
|
params?: Params<ModalName>;
|
|
11
34
|
};
|
|
12
35
|
|
|
13
36
|
declare type BaseModalParams = {
|
|
14
37
|
/**
|
|
15
|
-
* Function to close the modal
|
|
38
|
+
* Function to close the modal programmatically.
|
|
39
|
+
* This is automatically injected by the modal system and should not be provided when opening a modal.
|
|
16
40
|
*/
|
|
17
41
|
closeModal: () => void;
|
|
18
42
|
/**
|
|
19
|
-
* Callback triggered when the modal is closed.
|
|
43
|
+
* Callback triggered when the modal is closed (either by user action or programmatically).
|
|
44
|
+
* Use this for cleanup operations or side effects after modal close.
|
|
20
45
|
*/
|
|
21
46
|
onClose?: () => void;
|
|
22
47
|
/**
|
|
23
|
-
*
|
|
48
|
+
* Controls whether the modal should close when the user clicks outside the modal content.
|
|
49
|
+
* @default true
|
|
24
50
|
*/
|
|
25
51
|
closeOnClickOutside?: boolean;
|
|
26
52
|
/**
|
|
27
|
-
*
|
|
53
|
+
* Controls whether the modal should close when the user presses the Escape key.
|
|
54
|
+
* @default true
|
|
28
55
|
*/
|
|
29
56
|
closeOnPressEsc?: boolean;
|
|
30
57
|
/**
|
|
31
|
-
* Styling options for the outer
|
|
58
|
+
* Styling options for the outer backdrop (overlay) of the modal.
|
|
59
|
+
* This backdrop typically provides the backdrop and centers the modal content.
|
|
32
60
|
*/
|
|
33
|
-
|
|
61
|
+
backdrop?: {
|
|
62
|
+
/**
|
|
63
|
+
* CSS class name to apply to the modal backdrop.
|
|
64
|
+
* Useful for custom styling or responsive behavior.
|
|
65
|
+
*/
|
|
34
66
|
className?: string;
|
|
35
|
-
override?: boolean;
|
|
36
67
|
};
|
|
37
68
|
/**
|
|
38
69
|
* Styling options for the modal content/body.
|
|
70
|
+
* This is the actual modal content area where your component is rendered.
|
|
39
71
|
*/
|
|
40
72
|
body?: {
|
|
73
|
+
/**
|
|
74
|
+
* CSS class name to apply to the modal body.
|
|
75
|
+
* Useful for custom styling, sizing, or positioning of modal content.
|
|
76
|
+
*/
|
|
41
77
|
className?: string;
|
|
42
|
-
override?: boolean;
|
|
43
78
|
};
|
|
44
79
|
/**
|
|
45
|
-
* Framer Motion animation settings for entrance and exit.
|
|
80
|
+
* Framer Motion animation settings for modal entrance and exit animations.
|
|
81
|
+
* These settings define how the modal appears and disappears.
|
|
46
82
|
*/
|
|
47
83
|
animate?: {
|
|
84
|
+
/**
|
|
85
|
+
* Animation properties for the exit transition (when modal is closing).
|
|
86
|
+
* Accepts any valid Framer Motion TargetAndTransition properties.
|
|
87
|
+
* Example: { opacity: 0, scale: 0.8, transition: { duration: 0.2 } }
|
|
88
|
+
*/
|
|
48
89
|
exit?: TargetAndTransition;
|
|
90
|
+
/**
|
|
91
|
+
* Animation properties for the animate state (when modal is visible).
|
|
92
|
+
* Accepts any valid Framer Motion TargetAndTransition properties.
|
|
93
|
+
* Example: { opacity: 1, scale: 1, transition: { duration: 0.3 } }
|
|
94
|
+
*/
|
|
49
95
|
animate?: TargetAndTransition;
|
|
50
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Optional positioning string for modal placement.
|
|
99
|
+
* This can be used to override default modal positioning behavior.
|
|
100
|
+
* import { MODAL_POSITIONS } from 'react-motion-modal';
|
|
101
|
+
*/
|
|
102
|
+
position?: string;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export declare const MODAL_POSITIONS: {
|
|
106
|
+
TOP: string;
|
|
107
|
+
CENTER: string;
|
|
108
|
+
BOTTOM: string;
|
|
51
109
|
};
|
|
52
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Actions that can be performed on the modal system.
|
|
113
|
+
* These are the functions available to control modal behavior.
|
|
114
|
+
*/
|
|
53
115
|
declare type ModalAction = {
|
|
116
|
+
/**
|
|
117
|
+
* Closes a specific modal by name or the topmost modal if no name is provided.
|
|
118
|
+
*
|
|
119
|
+
* @param name - Optional modal name to close. If not provided, closes the topmost modal.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* closeModal('alert'); // Closes the alert modal
|
|
124
|
+
* closeModal(); // Closes the current (topmost) modal
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
54
127
|
closeModal: (name?: ModalName) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Closes all open modals immediately.
|
|
130
|
+
* This is useful for clearing the modal stack, such as during route navigation.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* closeAllModal(); // Closes all modals
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
55
137
|
closeAllModal: () => void;
|
|
138
|
+
/**
|
|
139
|
+
* Opens a new modal with optional parameters.
|
|
140
|
+
*
|
|
141
|
+
* @template T - The modal name type
|
|
142
|
+
* @param name - The name of the modal to open
|
|
143
|
+
* @param params - Optional parameters to pass to the modal (excluding closeModal which is auto-injected)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* openModal('alert', {
|
|
148
|
+
* message: 'Hello World',
|
|
149
|
+
* onClose: () => console.log('Alert closed'),
|
|
150
|
+
* closeOnClickOutside: false
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
56
154
|
openModal: <T extends ModalName>(name: T, params?: Omit<Params<T>, 'closeModal'>) => void;
|
|
57
155
|
};
|
|
58
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Represents a modal component that accepts props and returns a React element.
|
|
159
|
+
* This is the type definition for modal components that can be registered in the modal system.
|
|
160
|
+
*
|
|
161
|
+
* @template T - The type of props the component accepts, defaults to any
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const AlertModal: ModalComponent<{ message: string; closeModal: () => void }> =
|
|
166
|
+
* ({ message, closeModal }) => <div>{message}<button onClick={closeModal}>Close</button></div>;
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
59
169
|
declare type ModalComponent<T = any> = (props: T) => ReactElement;
|
|
60
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Configuration object that maps modal names to their corresponding components.
|
|
173
|
+
* This is used to register all available modals in the system.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const modalConfig: ModalConfig = {
|
|
178
|
+
* alert: AlertModal,
|
|
179
|
+
* confirm: ConfirmModal,
|
|
180
|
+
* // ... other modals
|
|
181
|
+
* };
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
61
184
|
declare type ModalConfig = {
|
|
62
185
|
[K in ModalName]: ModalComponent<Params<K>>;
|
|
63
186
|
};
|
|
@@ -65,17 +188,56 @@ declare type ModalConfig = {
|
|
|
65
188
|
export declare interface ModalDefinition {
|
|
66
189
|
}
|
|
67
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Extracts the key type from the ModalDefinition interface.
|
|
193
|
+
* This represents all available modal names that can be opened in the application.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // If ModalDefinition is { alert: AlertParams, confirm: ConfirmParams }
|
|
198
|
+
* type ModalName = 'alert' | 'confirm';
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
68
201
|
declare type ModalName = keyof ModalDefinition;
|
|
69
202
|
|
|
70
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Extracts only the closeModal function from the modal parameters.
|
|
205
|
+
* This is useful when you need to pass only the close functionality to components.
|
|
206
|
+
*
|
|
207
|
+
* @template T - The modal name type
|
|
208
|
+
*/
|
|
209
|
+
export declare type ModalParams<T extends ModalName> = Pick<Params<T>, 'closeModal'>;
|
|
71
210
|
|
|
72
211
|
export declare const ModalProvider: ({ modals, initialParams }: Props) => ReactPortal | null;
|
|
73
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Represents the current state of all modals in the application.
|
|
215
|
+
* This includes the modal stack and the currently active modal.
|
|
216
|
+
*/
|
|
74
217
|
declare type ModalState = {
|
|
218
|
+
/**
|
|
219
|
+
* Array of all currently open modals, ordered by their opening sequence.
|
|
220
|
+
* The last modal in the array is the topmost modal.
|
|
221
|
+
*/
|
|
75
222
|
modals: ActiveModal[];
|
|
223
|
+
/**
|
|
224
|
+
* The currently active (topmost) modal, or undefined if no modals are open.
|
|
225
|
+
*/
|
|
76
226
|
active?: ActiveModal;
|
|
77
227
|
};
|
|
78
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Combines the modal-specific parameters from ModalDefinition with the base modal parameters.
|
|
231
|
+
* This represents the complete set of props that a modal component will receive.
|
|
232
|
+
*
|
|
233
|
+
* @template T - The modal name type
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* // For a modal named 'alert' with AlertParams defined in ModalDefinition
|
|
238
|
+
* type AlertModalParams = Params<'alert'>; // AlertParams & BaseModalParams
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
79
241
|
declare type Params<T extends ModalName> = ModalDefinition[T] & BaseModalParams;
|
|
80
242
|
|
|
81
243
|
declare type Props = {
|