react-motion-modal 1.3.2 → 1.4.0
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 +12 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +37 -15
- package/dist/index.js +211 -161
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -123,6 +123,11 @@ Opens a modal by name. The `params` will be inferred based on modal type.
|
|
|
123
123
|
- If `name` is provided, closes that specific modal.
|
|
124
124
|
- If not, closes the most recent modal (top of the stack).
|
|
125
125
|
|
|
126
|
+
### `closeAllModal()`
|
|
127
|
+
|
|
128
|
+
Closes every modal from top to bottom and invokes each instance's `onClose`
|
|
129
|
+
callback once.
|
|
130
|
+
|
|
126
131
|
### `BaseModalParams`
|
|
127
132
|
|
|
128
133
|
Each modal automatically receives the following props:
|
|
@@ -131,6 +136,9 @@ Each modal automatically receives the following props:
|
|
|
131
136
|
|-----------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------|
|
|
132
137
|
| `closeModal` | `() => void` | Close function for the modal |
|
|
133
138
|
| `onClose` | `() => void` | Callback triggered when modal is closed |
|
|
139
|
+
| `ariaLabel` | `string` | Accessible dialog name. Defaults to `Modal` |
|
|
140
|
+
| `ariaLabelledBy` | `string` | ID of the visible element that labels the dialog |
|
|
141
|
+
| `ariaDescribedBy` | `string` | ID of the element that describes the dialog |
|
|
134
142
|
| `closeOnClickOutside` | `boolean` | Close modal when clicking outside |
|
|
135
143
|
| `closeOnPressEsc` | `boolean` | Close modal when Escape key is pressed |
|
|
136
144
|
| `position` | `string` | Modal placement. Unknown values fall back to `center`. |
|
|
@@ -139,6 +147,9 @@ Each modal automatically receives the following props:
|
|
|
139
147
|
| `animate` | `{ animate?: TargetAndTransition; exit?: TargetAndTransition; }` | Animation powered by Framer Motion. Custom animation disables defaults. |
|
|
140
148
|
| `blur` | `boolean` | Apply backdrop blur |
|
|
141
149
|
|
|
150
|
+
The package also exports `Params`, `BaseModalParams`, `ModalConfig`,
|
|
151
|
+
`ModalInitialParams`, and the store state/action types for advanced usage.
|
|
152
|
+
|
|
142
153
|
### `MODAL_POSITIONS`
|
|
143
154
|
|
|
144
155
|
```ts
|
|
@@ -161,7 +172,7 @@ Default body animation follows the position. For example, `left` slides in from
|
|
|
161
172
|
## 🔐 Release Security
|
|
162
173
|
|
|
163
174
|
- CI runs from `.github/workflows/ci.yml` on pushes and pull requests.
|
|
164
|
-
- npm publishing is defined in `.github/workflows/publish.yml` and uses
|
|
175
|
+
- npm publishing is defined in `.github/workflows/publish.yml` and uses npm trusted publishing with provenance.
|
|
165
176
|
- Trusted publishing still needs to be enabled in npm package settings for this repository before the workflow can publish official releases.
|
|
166
177
|
|
|
167
178
|
## 📝 Notes
|
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:where(.react-motion-modal__root){position:fixed;inset:0}:where(.react-motion-modal__backdrop){position:absolute;inset:0;background-color:#0006}:where(.react-motion-modal__backdrop--custom){background-color:transparent}:where(.react-motion-modal__body){position:absolute;max-height:100vh;max-width:100vw;overflow:hidden;padding:20px}:where(.react-motion-modal__content){width:100%;height:100%}:where(.react-motion-modal__body--top){top:0;left:0;right:0;width:100%}:where(.react-motion-modal__body--top-left){
|
|
1
|
+
:where(.react-motion-modal__root){position:fixed;inset:0}:where(.react-motion-modal__backdrop){position:absolute;inset:0;background-color:#0006}:where(.react-motion-modal__backdrop--custom){background-color:transparent}:where(.react-motion-modal__body){position:absolute;box-sizing:border-box;max-height:100vh;max-height:100dvh;max-width:100vw;max-width:100dvw;overflow-x:hidden;overflow-y:auto;padding:20px}:where(.react-motion-modal__content){width:100%;height:100%}:where(.react-motion-modal__body--top){top:0;left:0;right:0;width:100%}:where(.react-motion-modal__body--top-left){top:0;left:0}:where(.react-motion-modal__body--top-right){top:0;right:0}:where(.react-motion-modal__body--top-center){top:0;left:50%;transform:translate(-50%)}:where(.react-motion-modal__body--bottom){right:0;bottom:0;left:0;width:100%}:where(.react-motion-modal__body--bottom-left){bottom:0;left:0}:where(.react-motion-modal__body--bottom-right){right:0;bottom:0}:where(.react-motion-modal__body--bottom-center){bottom:0;left:50%;transform:translate(-50%)}:where(.react-motion-modal__body--left){top:0;bottom:0;left:0}:where(.react-motion-modal__body--right){top:0;right:0;bottom:0}:where(.react-motion-modal__body--center){top:50%;left:50%;transform:translate(-50%,-50%)}:where(.react-motion-modal__body--center-full){inset:0;width:100%;height:100%}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { UseBoundStore } from 'zustand/react';
|
|
|
18
18
|
* };
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
declare type ActiveModal = {
|
|
21
|
+
export declare type ActiveModal = {
|
|
22
22
|
/**
|
|
23
23
|
* Unique identifier for this modal instance.
|
|
24
24
|
* Generated automatically when the modal is opened.
|
|
@@ -38,7 +38,7 @@ declare type ActiveModal = {
|
|
|
38
38
|
* Base parameters available for all modals.
|
|
39
39
|
* These parameters control modal behavior, styling, and animation.
|
|
40
40
|
*/
|
|
41
|
-
declare type BaseModalParams = {
|
|
41
|
+
export declare type BaseModalParams = {
|
|
42
42
|
/**
|
|
43
43
|
* Function to close the modal programmatically.
|
|
44
44
|
* This is automatically injected by the modal system and should not be provided when opening a modal.
|
|
@@ -49,6 +49,21 @@ declare type BaseModalParams = {
|
|
|
49
49
|
* Use this for cleanup operations or side effects after modal close.
|
|
50
50
|
*/
|
|
51
51
|
onClose?: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Accessible name for the dialog when there is no visible heading that can
|
|
54
|
+
* be referenced with `ariaLabelledBy`.
|
|
55
|
+
* @default "Modal"
|
|
56
|
+
*/
|
|
57
|
+
ariaLabel?: string;
|
|
58
|
+
/**
|
|
59
|
+
* ID of the visible element that labels the dialog.
|
|
60
|
+
* Takes precedence over `ariaLabel` when provided.
|
|
61
|
+
*/
|
|
62
|
+
ariaLabelledBy?: string;
|
|
63
|
+
/**
|
|
64
|
+
* ID of the element that describes the dialog.
|
|
65
|
+
*/
|
|
66
|
+
ariaDescribedBy?: string;
|
|
52
67
|
/**
|
|
53
68
|
* Controls whether the modal should close when the user clicks outside the modal content.
|
|
54
69
|
* @default true
|
|
@@ -235,7 +250,7 @@ export declare const MODAL_Z_INDEX = 1000;
|
|
|
235
250
|
* Actions that can be performed on the modal system.
|
|
236
251
|
* These are the functions available to control modal behavior.
|
|
237
252
|
*/
|
|
238
|
-
declare type ModalAction = {
|
|
253
|
+
export declare type ModalAction = {
|
|
239
254
|
/**
|
|
240
255
|
* Closes a specific modal by name or the topmost modal if no name is provided.
|
|
241
256
|
*
|
|
@@ -325,7 +340,7 @@ declare type ModalAction = {
|
|
|
325
340
|
* );
|
|
326
341
|
* ```
|
|
327
342
|
*/
|
|
328
|
-
declare type ModalComponent<T = any> = (props: T) => ReactElement;
|
|
343
|
+
export declare type ModalComponent<T = any> = (props: T) => ReactElement;
|
|
329
344
|
|
|
330
345
|
/**
|
|
331
346
|
* Configuration object that maps modal names to their corresponding components.
|
|
@@ -368,18 +383,25 @@ declare type ModalComponent<T = any> = (props: T) => ReactElement;
|
|
|
368
383
|
* };
|
|
369
384
|
*
|
|
370
385
|
* // Use with ModalProvider
|
|
371
|
-
* <ModalProvider
|
|
386
|
+
* <ModalProvider modals={modalConfig}>
|
|
372
387
|
* <App />
|
|
373
388
|
* </ModalProvider>
|
|
374
389
|
* ```
|
|
375
390
|
*/
|
|
376
|
-
declare type ModalConfig = {
|
|
391
|
+
export declare type ModalConfig = {
|
|
377
392
|
[K in ModalName]: ModalComponent<Params<K>>;
|
|
378
393
|
};
|
|
379
394
|
|
|
380
395
|
export declare interface ModalDefinition {
|
|
381
396
|
}
|
|
382
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Provider-level defaults for modal rendering and interaction.
|
|
400
|
+
* Lifecycle callbacks and the injected close handler belong to each modal
|
|
401
|
+
* instance, so they cannot be configured as provider defaults.
|
|
402
|
+
*/
|
|
403
|
+
export declare type ModalInitialParams = Partial<Omit<BaseModalParams, 'closeModal' | 'onClose'>>;
|
|
404
|
+
|
|
383
405
|
/**
|
|
384
406
|
* Extracts the key type from the ModalDefinition interface.
|
|
385
407
|
* This represents all available modal names that can be opened in the application.
|
|
@@ -390,7 +412,7 @@ export declare interface ModalDefinition {
|
|
|
390
412
|
* type ModalName = 'alert' | 'confirm';
|
|
391
413
|
* ```
|
|
392
414
|
*/
|
|
393
|
-
declare type ModalName = keyof ModalDefinition;
|
|
415
|
+
export declare type ModalName = keyof ModalDefinition;
|
|
394
416
|
|
|
395
417
|
/**
|
|
396
418
|
* Extracts only the closeModal function from the modal parameters.
|
|
@@ -400,13 +422,18 @@ declare type ModalName = keyof ModalDefinition;
|
|
|
400
422
|
*/
|
|
401
423
|
export declare type ModalParams<T extends ModalName> = ModalDefinition[T] & Pick<BaseModalParams, 'closeModal'>;
|
|
402
424
|
|
|
403
|
-
export declare const ModalProvider: ({ modals, initialParams }:
|
|
425
|
+
export declare const ModalProvider: ({ modals, initialParams, }: ModalProviderProps) => ReactPortal | null;
|
|
426
|
+
|
|
427
|
+
export declare type ModalProviderProps = {
|
|
428
|
+
modals: ModalConfig;
|
|
429
|
+
initialParams?: ModalInitialParams;
|
|
430
|
+
};
|
|
404
431
|
|
|
405
432
|
/**
|
|
406
433
|
* Represents the current state of all modals in the application.
|
|
407
434
|
* This includes the modal stack and the currently active modal.
|
|
408
435
|
*/
|
|
409
|
-
declare type ModalState = {
|
|
436
|
+
export declare type ModalState = {
|
|
410
437
|
/**
|
|
411
438
|
* Array of all currently open modals, ordered by their opening sequence.
|
|
412
439
|
* The last modal in the array is the topmost modal.
|
|
@@ -432,11 +459,6 @@ export declare const modalStore: UseBoundStore<StoreApi<ModalState & ModalAction
|
|
|
432
459
|
* type AlertModalParams = Params<'alert'>; // AlertParams & BaseModalParams
|
|
433
460
|
* ```
|
|
434
461
|
*/
|
|
435
|
-
declare type Params<T extends ModalName> = ModalDefinition[T] & BaseModalParams;
|
|
436
|
-
|
|
437
|
-
declare type Props = {
|
|
438
|
-
modals: ModalConfig;
|
|
439
|
-
initialParams?: Partial<BaseModalParams>;
|
|
440
|
-
};
|
|
462
|
+
export declare type Params<T extends ModalName> = ModalDefinition[T] & BaseModalParams;
|
|
441
463
|
|
|
442
464
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { create as
|
|
3
|
-
import { motion as
|
|
4
|
-
import { useRef as
|
|
5
|
-
import { createPortal as
|
|
6
|
-
const
|
|
1
|
+
import { jsxs as g, jsx as f } from "react/jsx-runtime";
|
|
2
|
+
import { create as A } from "zustand/react";
|
|
3
|
+
import { motion as I, AnimatePresence as F } from "motion/react";
|
|
4
|
+
import { useState as P, useRef as h, useEffect as y } from "react";
|
|
5
|
+
import { createPortal as k } from "react-dom";
|
|
6
|
+
const t = {
|
|
7
7
|
TOP: "top",
|
|
8
8
|
TOP_LEFT: "top-left",
|
|
9
9
|
TOP_RIGHT: "top-right",
|
|
@@ -16,195 +16,218 @@ const o = {
|
|
|
16
16
|
BOTTOM_LEFT: "bottom-left",
|
|
17
17
|
BOTTOM_RIGHT: "bottom-right",
|
|
18
18
|
BOTTOM_CENTER: "bottom-center"
|
|
19
|
-
},
|
|
19
|
+
}, M = 1e3, w = {
|
|
20
20
|
duration: 0.24,
|
|
21
21
|
ease: "easeOut"
|
|
22
|
-
},
|
|
22
|
+
}, N = {
|
|
23
23
|
duration: 0.18,
|
|
24
24
|
ease: "easeIn"
|
|
25
|
-
},
|
|
25
|
+
}, R = {
|
|
26
26
|
opacity: 1,
|
|
27
27
|
scale: 1,
|
|
28
28
|
x: 0,
|
|
29
29
|
y: 0,
|
|
30
|
-
transition:
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
30
|
+
transition: w
|
|
31
|
+
}, D = () => `modal-${Date.now()}-${Math.random().toString(36).slice(2)}`, E = A((e, a) => {
|
|
32
|
+
const s = (o) => {
|
|
33
|
+
const n = [...a().modals];
|
|
34
|
+
if (o < 0 || o >= n.length)
|
|
35
|
+
return;
|
|
36
|
+
const [c] = n.splice(o, 1);
|
|
37
|
+
e({
|
|
38
|
+
modals: n,
|
|
39
|
+
active: n[n.length - 1]
|
|
40
|
+
}), c?.params?.onClose?.();
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
modals: [],
|
|
44
|
+
openModal(o, n) {
|
|
45
|
+
const c = D(), m = {
|
|
46
|
+
...n,
|
|
47
|
+
closeModal: () => {
|
|
48
|
+
const r = a().modals.findIndex((i) => i.id === c);
|
|
49
|
+
s(r);
|
|
50
|
+
}
|
|
51
|
+
}, u = {
|
|
52
|
+
id: c,
|
|
53
|
+
name: o,
|
|
54
|
+
params: m
|
|
55
|
+
}, d = [...a().modals, u];
|
|
56
|
+
e({
|
|
57
|
+
modals: d,
|
|
58
|
+
active: u
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
closeAllModal() {
|
|
62
|
+
const o = a().modals;
|
|
63
|
+
e({
|
|
64
|
+
modals: [],
|
|
65
|
+
active: void 0
|
|
66
|
+
});
|
|
67
|
+
for (const n of [...o].reverse())
|
|
68
|
+
n.params?.onClose?.();
|
|
69
|
+
},
|
|
70
|
+
closeModal(o) {
|
|
71
|
+
const n = a().modals, c = o ? n.findIndex((l) => l.name === o) : n.length - 1;
|
|
72
|
+
s(c);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}), L = (...e) => e.filter(Boolean).join(" "), T = (e, a) => {
|
|
76
|
+
const s = {
|
|
62
77
|
opacity: 0,
|
|
63
|
-
x:
|
|
64
|
-
y:
|
|
65
|
-
transition:
|
|
78
|
+
x: e,
|
|
79
|
+
y: a,
|
|
80
|
+
transition: N
|
|
66
81
|
};
|
|
67
82
|
return {
|
|
68
|
-
initial:
|
|
69
|
-
animate:
|
|
70
|
-
exit:
|
|
83
|
+
initial: s,
|
|
84
|
+
animate: R,
|
|
85
|
+
exit: s
|
|
71
86
|
};
|
|
72
|
-
}, C = (
|
|
73
|
-
switch (
|
|
74
|
-
case
|
|
75
|
-
return
|
|
76
|
-
case
|
|
77
|
-
return
|
|
78
|
-
case
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
case
|
|
83
|
-
return
|
|
84
|
-
case
|
|
85
|
-
return
|
|
86
|
-
case
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
return
|
|
90
|
-
case
|
|
91
|
-
return
|
|
92
|
-
case
|
|
87
|
+
}, C = (e) => {
|
|
88
|
+
switch (e) {
|
|
89
|
+
case t.LEFT:
|
|
90
|
+
return T("-100%", 0);
|
|
91
|
+
case t.RIGHT:
|
|
92
|
+
return T("100%", 0);
|
|
93
|
+
case t.TOP:
|
|
94
|
+
case t.TOP_CENTER:
|
|
95
|
+
return T(0, "-100%");
|
|
96
|
+
case t.BOTTOM:
|
|
97
|
+
case t.BOTTOM_CENTER:
|
|
98
|
+
return T(0, "100%");
|
|
99
|
+
case t.TOP_LEFT:
|
|
100
|
+
return T("-100%", "-100%");
|
|
101
|
+
case t.TOP_RIGHT:
|
|
102
|
+
return T("100%", "-100%");
|
|
103
|
+
case t.BOTTOM_LEFT:
|
|
104
|
+
return T("-100%", "100%");
|
|
105
|
+
case t.BOTTOM_RIGHT:
|
|
106
|
+
return T("100%", "100%");
|
|
107
|
+
case t.CENTER:
|
|
93
108
|
return {
|
|
94
109
|
initial: {
|
|
95
110
|
opacity: 0,
|
|
96
111
|
scale: 0.96
|
|
97
112
|
},
|
|
98
|
-
animate:
|
|
113
|
+
animate: R,
|
|
99
114
|
exit: {
|
|
100
115
|
opacity: 0,
|
|
101
116
|
scale: 0.96,
|
|
102
|
-
transition:
|
|
117
|
+
transition: N
|
|
103
118
|
}
|
|
104
119
|
};
|
|
105
|
-
case
|
|
120
|
+
case t.CENTER_FULL:
|
|
106
121
|
return {
|
|
107
122
|
initial: {
|
|
108
123
|
opacity: 0
|
|
109
124
|
},
|
|
110
|
-
animate:
|
|
125
|
+
animate: R,
|
|
111
126
|
exit: {
|
|
112
127
|
opacity: 0,
|
|
113
|
-
transition:
|
|
128
|
+
transition: N
|
|
114
129
|
}
|
|
115
130
|
};
|
|
116
131
|
default:
|
|
117
|
-
return C(
|
|
132
|
+
return C(t.CENTER);
|
|
118
133
|
}
|
|
119
|
-
},
|
|
120
|
-
switch (
|
|
121
|
-
case
|
|
134
|
+
}, B = (e) => {
|
|
135
|
+
switch (e) {
|
|
136
|
+
case t.TOP:
|
|
122
137
|
return "react-motion-modal__body--top";
|
|
123
|
-
case
|
|
138
|
+
case t.TOP_LEFT:
|
|
124
139
|
return "react-motion-modal__body--top-left";
|
|
125
|
-
case
|
|
140
|
+
case t.TOP_RIGHT:
|
|
126
141
|
return "react-motion-modal__body--top-right";
|
|
127
|
-
case
|
|
142
|
+
case t.TOP_CENTER:
|
|
128
143
|
return "react-motion-modal__body--top-center";
|
|
129
|
-
case
|
|
144
|
+
case t.BOTTOM:
|
|
130
145
|
return "react-motion-modal__body--bottom";
|
|
131
|
-
case
|
|
146
|
+
case t.BOTTOM_LEFT:
|
|
132
147
|
return "react-motion-modal__body--bottom-left";
|
|
133
|
-
case
|
|
148
|
+
case t.BOTTOM_RIGHT:
|
|
134
149
|
return "react-motion-modal__body--bottom-right";
|
|
135
|
-
case
|
|
150
|
+
case t.BOTTOM_CENTER:
|
|
136
151
|
return "react-motion-modal__body--bottom-center";
|
|
137
|
-
case
|
|
152
|
+
case t.LEFT:
|
|
138
153
|
return "react-motion-modal__body--left";
|
|
139
|
-
case
|
|
154
|
+
case t.RIGHT:
|
|
140
155
|
return "react-motion-modal__body--right";
|
|
141
|
-
case
|
|
156
|
+
case t.CENTER:
|
|
142
157
|
return "react-motion-modal__body--center";
|
|
143
|
-
case
|
|
158
|
+
case t.CENTER_FULL:
|
|
144
159
|
return "react-motion-modal__body--center-full";
|
|
145
160
|
default:
|
|
146
|
-
return
|
|
161
|
+
return B(t.CENTER);
|
|
147
162
|
}
|
|
148
|
-
},
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
}, S = ({ data: e, modals: a, index: s, initialParams: o }) => {
|
|
164
|
+
const n = a[e.name], c = e.params, l = {
|
|
165
|
+
...o,
|
|
166
|
+
...c
|
|
167
|
+
}, m = l?.animate ?? o?.animate, u = l?.blur ?? o?.blur ?? !0, d = l?.backdrop ?? o?.backdrop, r = l?.body ?? o?.body, i = l?.position ?? o?.position ?? t.CENTER, O = l?.closeOnClickOutside ?? o?.closeOnClickOutside ?? !0, b = m ? void 0 : C(i), _ = E((v) => v.active)?.id === e.id;
|
|
168
|
+
return /* @__PURE__ */ g(
|
|
169
|
+
I.div,
|
|
152
170
|
{
|
|
153
171
|
className: "react-motion-modal__root",
|
|
154
|
-
exit:
|
|
155
|
-
initial:
|
|
156
|
-
animate:
|
|
172
|
+
exit: m?.exit ?? { opacity: 0 },
|
|
173
|
+
initial: m?.exit ?? { opacity: 0 },
|
|
174
|
+
animate: m?.animate ?? { opacity: 1 },
|
|
157
175
|
layout: !0,
|
|
158
176
|
style: {
|
|
159
|
-
zIndex:
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
zIndex: M + s,
|
|
178
|
+
pointerEvents: _ ? void 0 : "none",
|
|
179
|
+
backdropFilter: u ? "blur(8px)" : void 0,
|
|
180
|
+
WebkitBackdropFilter: u ? "blur(8px)" : void 0
|
|
162
181
|
},
|
|
163
182
|
children: [
|
|
164
|
-
/* @__PURE__ */
|
|
183
|
+
/* @__PURE__ */ f(
|
|
165
184
|
"div",
|
|
166
185
|
{
|
|
167
|
-
className:
|
|
186
|
+
className: L(
|
|
168
187
|
"react-motion-modal__backdrop",
|
|
169
|
-
|
|
188
|
+
_ && "react-motion-modal__active",
|
|
170
189
|
d?.className && "react-motion-modal__backdrop--custom",
|
|
171
190
|
d?.className
|
|
172
191
|
),
|
|
173
192
|
style: {
|
|
174
|
-
zIndex:
|
|
193
|
+
zIndex: M + s,
|
|
175
194
|
...d?.style
|
|
176
195
|
},
|
|
177
196
|
onClick: () => {
|
|
178
|
-
|
|
197
|
+
O && l.closeModal();
|
|
179
198
|
}
|
|
180
199
|
}
|
|
181
200
|
),
|
|
182
|
-
/* @__PURE__ */
|
|
201
|
+
/* @__PURE__ */ f(
|
|
183
202
|
"div",
|
|
184
203
|
{
|
|
185
204
|
role: "dialog",
|
|
186
|
-
"aria-modal": "true",
|
|
205
|
+
"aria-modal": _ ? "true" : void 0,
|
|
206
|
+
"aria-hidden": _ ? void 0 : !0,
|
|
207
|
+
"aria-label": l.ariaLabelledBy ? void 0 : l.ariaLabel ?? "Modal",
|
|
208
|
+
"aria-labelledby": l.ariaLabelledBy,
|
|
209
|
+
"aria-describedby": l.ariaDescribedBy,
|
|
187
210
|
tabIndex: -1,
|
|
188
|
-
"data-modal-id":
|
|
189
|
-
className:
|
|
211
|
+
"data-modal-id": e.id,
|
|
212
|
+
className: L(
|
|
190
213
|
"react-motion-modal__body",
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
214
|
+
B(i),
|
|
215
|
+
_ && "react-motion-modal__body--active",
|
|
216
|
+
r?.className
|
|
194
217
|
),
|
|
195
218
|
style: {
|
|
196
|
-
...
|
|
197
|
-
zIndex:
|
|
219
|
+
...r?.style,
|
|
220
|
+
zIndex: M + s + 1
|
|
198
221
|
},
|
|
199
|
-
onClick: (
|
|
200
|
-
children: /* @__PURE__ */
|
|
201
|
-
|
|
222
|
+
onClick: (v) => v.stopPropagation(),
|
|
223
|
+
children: /* @__PURE__ */ f(
|
|
224
|
+
I.div,
|
|
202
225
|
{
|
|
203
226
|
className: "react-motion-modal__content",
|
|
204
|
-
initial:
|
|
205
|
-
animate:
|
|
206
|
-
exit:
|
|
207
|
-
children: /* @__PURE__ */
|
|
227
|
+
initial: b?.initial,
|
|
228
|
+
animate: b?.animate,
|
|
229
|
+
exit: b?.exit,
|
|
230
|
+
children: /* @__PURE__ */ f(n, { ...l })
|
|
208
231
|
}
|
|
209
232
|
)
|
|
210
233
|
}
|
|
@@ -212,71 +235,98 @@ const o = {
|
|
|
212
235
|
]
|
|
213
236
|
}
|
|
214
237
|
);
|
|
215
|
-
},
|
|
238
|
+
}, G = [
|
|
216
239
|
"a[href]",
|
|
217
240
|
"button:not([disabled])",
|
|
218
241
|
"textarea:not([disabled])",
|
|
219
242
|
"input:not([disabled])",
|
|
220
243
|
"select:not([disabled])",
|
|
221
244
|
'[tabindex]:not([tabindex="-1"])'
|
|
222
|
-
].join(","),
|
|
223
|
-
|
|
224
|
-
).filter((
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
245
|
+
].join(","), x = (e) => e ? Array.from(
|
|
246
|
+
e.querySelectorAll(G)
|
|
247
|
+
).filter((a) => a.getClientRects().length > 0) : [], H = (e, a) => {
|
|
248
|
+
if (!e || a.key !== "Tab")
|
|
249
|
+
return;
|
|
250
|
+
const s = x(e), o = s[0], n = s[s.length - 1], c = document.activeElement;
|
|
251
|
+
if (!o || !n) {
|
|
252
|
+
a.preventDefault(), e.focus();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!c || !e.contains(c)) {
|
|
256
|
+
a.preventDefault(), (a.shiftKey ? n : o).focus();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
a.shiftKey && c === o ? (a.preventDefault(), n.focus()) : !a.shiftKey && c === n && (a.preventDefault(), o.focus());
|
|
260
|
+
}, z = ({
|
|
261
|
+
modals: e,
|
|
262
|
+
initialParams: a
|
|
263
|
+
}) => {
|
|
264
|
+
const s = E((r) => r.modals), o = E((r) => r.active), n = E((r) => r.closeModal), [c, l] = P(null), m = h(null), u = h(null);
|
|
265
|
+
y(() => {
|
|
266
|
+
l(document.body);
|
|
228
267
|
}, []);
|
|
229
|
-
const d =
|
|
230
|
-
return
|
|
231
|
-
|
|
268
|
+
const d = s.length > 0;
|
|
269
|
+
return y(() => {
|
|
270
|
+
const i = s[s.length - 1]?.params?.closeOnPressEsc ?? a?.closeOnPressEsc ?? !0;
|
|
271
|
+
if (!d)
|
|
232
272
|
return;
|
|
233
|
-
const
|
|
234
|
-
|
|
273
|
+
const O = (b) => {
|
|
274
|
+
if (b.key === "Escape" && i) {
|
|
275
|
+
n();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const p = o?.id, _ = p ? m.current?.querySelector(
|
|
279
|
+
`[data-modal-id="${p}"]`
|
|
280
|
+
) : void 0;
|
|
281
|
+
H(_, b);
|
|
235
282
|
};
|
|
236
|
-
return window.addEventListener("keydown",
|
|
283
|
+
return window.addEventListener("keydown", O), () => window.removeEventListener("keydown", O);
|
|
237
284
|
}, [
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
285
|
+
s,
|
|
286
|
+
o?.id,
|
|
287
|
+
n,
|
|
288
|
+
a?.closeOnPressEsc,
|
|
241
289
|
d
|
|
242
|
-
]),
|
|
290
|
+
]), y(() => {
|
|
243
291
|
if (!d)
|
|
244
292
|
return;
|
|
245
|
-
const { body:
|
|
246
|
-
return
|
|
247
|
-
|
|
293
|
+
const { body: r } = document, i = r.style.overflow;
|
|
294
|
+
return r.style.overflow = "hidden", () => {
|
|
295
|
+
r.style.overflow = i;
|
|
248
296
|
};
|
|
249
|
-
}, [d]),
|
|
250
|
-
|
|
297
|
+
}, [d]), y(() => {
|
|
298
|
+
if (!c)
|
|
299
|
+
return;
|
|
300
|
+
const r = o?.id;
|
|
251
301
|
if (!d) {
|
|
252
|
-
|
|
302
|
+
u.current?.focus?.(), u.current = null;
|
|
253
303
|
return;
|
|
254
304
|
}
|
|
255
|
-
|
|
256
|
-
const i =
|
|
257
|
-
`[data-modal-id="${
|
|
305
|
+
u.current === null && (u.current = document.activeElement ?? null);
|
|
306
|
+
const i = r ? m.current?.querySelector(
|
|
307
|
+
`[data-modal-id="${r}"]`
|
|
258
308
|
) : void 0;
|
|
259
|
-
i && (
|
|
260
|
-
}, [
|
|
261
|
-
/* @__PURE__ */
|
|
262
|
-
|
|
309
|
+
i && (x(i)[0] ?? i).focus();
|
|
310
|
+
}, [o, d, c]), c && k(
|
|
311
|
+
/* @__PURE__ */ f("div", { className: "react-motion-modal", ref: m, children: /* @__PURE__ */ f(F, { initial: !0, mode: "sync", children: s?.map((r, i) => /* @__PURE__ */ f(
|
|
312
|
+
S,
|
|
263
313
|
{
|
|
264
|
-
data:
|
|
314
|
+
data: r,
|
|
265
315
|
index: i,
|
|
266
|
-
initialParams:
|
|
267
|
-
modals:
|
|
316
|
+
initialParams: a,
|
|
317
|
+
modals: e
|
|
268
318
|
},
|
|
269
|
-
|
|
319
|
+
r.id
|
|
270
320
|
)) }) }),
|
|
271
|
-
c
|
|
321
|
+
c
|
|
272
322
|
);
|
|
273
323
|
};
|
|
274
324
|
export {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
325
|
+
R as MODAL_BODY_ANIMATION_VISIBLE,
|
|
326
|
+
w as MODAL_ENTER_TRANSITION,
|
|
327
|
+
N as MODAL_EXIT_TRANSITION,
|
|
328
|
+
t as MODAL_POSITIONS,
|
|
329
|
+
M as MODAL_Z_INDEX,
|
|
280
330
|
z as ModalProvider,
|
|
281
|
-
|
|
331
|
+
E as modalStore
|
|
282
332
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-motion-modal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -49,13 +49,15 @@
|
|
|
49
49
|
"build": "tsc -b && vite build",
|
|
50
50
|
"ci": "yarn build",
|
|
51
51
|
"check-types": "tsc -b --pretty false",
|
|
52
|
-
"test": "
|
|
52
|
+
"test": "yarn test:unit && yarn test:browser",
|
|
53
|
+
"test:unit": "vitest run",
|
|
54
|
+
"test:browser": "vitest run --config vite.browser.config.ts",
|
|
53
55
|
"test:watch": "vitest",
|
|
54
56
|
"preview": "vite preview",
|
|
55
57
|
"bump:patch": "yarn version --patch --no-git-tag-version",
|
|
56
58
|
"bump:minor": "yarn version --minor --no-git-tag-version",
|
|
57
59
|
"bump:major": "yarn version --major --no-git-tag-version",
|
|
58
|
-
"release:check": "yarn build && npm pack --dry-run"
|
|
60
|
+
"release:check": "yarn test && yarn build && npm pack --dry-run"
|
|
59
61
|
},
|
|
60
62
|
"dependencies": {},
|
|
61
63
|
"devDependencies": {
|