react-motion-modal 1.2.5 → 1.2.8
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/LICENSE +21 -0
- package/README.md +86 -37
- package/dist/index.css +1 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +1877 -1837
- package/package.json +15 -11
- package/CHANGELOG.md +0 -73
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ngo Van Son
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# react-motion-modal
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/react-motion-modal)
|
|
4
|
+
[](https://www.npmjs.com/package/react-motion-modal)
|
|
5
|
+
[](https://github.com/sonnv1912/react-motion-modal/blob/main/LICENSE)
|
|
6
|
+
[](https://bundlephobia.com/package/react-motion-modal)
|
|
7
|
+
[](https://www.npmjs.com/package/react-motion-modal)
|
|
8
|
+
[](https://www.npmjs.com/package/react-motion-modal)
|
|
9
|
+
[](https://www.npmjs.com/package/react-motion-modal)
|
|
10
|
+
[](https://github.com/sonnv1912/react-motion-modal/issues)
|
|
11
|
+
[](https://socket.dev/npm/package/react-motion-modal)
|
|
12
|
+
|
|
3
13
|
`react-motion-modal` is a flexible modal management library built with [Zustand](https://zustand-demo.pmnd.rs/) for state management and powered by [Framer Motion](https://www.framer.com/motion/) for beautiful animations. It offers full TypeScript type-safety and allows dynamic modal opening with custom parameters.
|
|
4
14
|
|
|
5
15
|
## ✨ Features
|
|
@@ -13,23 +23,30 @@
|
|
|
13
23
|
## 🧱 Installation
|
|
14
24
|
|
|
15
25
|
```bash
|
|
16
|
-
npm install react-motion-modal
|
|
26
|
+
npm install react-motion-modal motion zustand
|
|
17
27
|
```
|
|
18
28
|
|
|
19
29
|
or with yarn:
|
|
20
30
|
|
|
21
31
|
```bash
|
|
22
|
-
yarn add react-motion-modal zustand
|
|
32
|
+
yarn add react-motion-modal motion zustand
|
|
23
33
|
```
|
|
24
34
|
|
|
25
35
|
## 🚀 Usage
|
|
26
36
|
|
|
27
|
-
### 1.
|
|
37
|
+
### 1. Import styles
|
|
38
|
+
|
|
39
|
+
Import the package stylesheet once in your app entry:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import 'react-motion-modal/style.css';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Define modal types
|
|
28
46
|
|
|
29
47
|
Create a `modal.d.ts` file in your project (make sure to include it in tsconfig.json):
|
|
30
48
|
|
|
31
49
|
```ts
|
|
32
|
-
import type { ReactElement } from 'react';
|
|
33
50
|
import type { ModalDefinition } from 'react-motion-modal';
|
|
34
51
|
|
|
35
52
|
declare module 'react-motion-modal' {
|
|
@@ -44,7 +61,7 @@ declare module 'react-motion-modal' {
|
|
|
44
61
|
}
|
|
45
62
|
```
|
|
46
63
|
|
|
47
|
-
###
|
|
64
|
+
### 3. Import <ModalProvider />
|
|
48
65
|
|
|
49
66
|
Import <ModalProvider /> to define your modals
|
|
50
67
|
|
|
@@ -52,40 +69,45 @@ Import <ModalProvider /> to define your modals
|
|
|
52
69
|
import { ModalProvider } from 'react-motion-modal';
|
|
53
70
|
|
|
54
71
|
export const App = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
return (
|
|
73
|
+
<div>
|
|
74
|
+
{/* rest of your app */}
|
|
75
|
+
|
|
76
|
+
<ModalProvider
|
|
77
|
+
modals={{
|
|
78
|
+
AlertModal,
|
|
79
|
+
ConfirmModal,
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
67
85
|
```
|
|
68
86
|
|
|
69
|
-
###
|
|
87
|
+
### 4. Open modal anywhere
|
|
70
88
|
|
|
71
89
|
```tsx
|
|
72
|
-
import { useModal } from 'react-motion-modal';
|
|
90
|
+
import { MODAL_POSITIONS, useModal } from 'react-motion-modal';
|
|
73
91
|
|
|
74
92
|
const { openModal } = useModal();
|
|
75
93
|
|
|
76
|
-
openModal('ConfirmModal', {
|
|
77
|
-
|
|
94
|
+
openModal('ConfirmModal', {
|
|
95
|
+
title: 'Are you sure you want to delete?',
|
|
96
|
+
position: MODAL_POSITIONS.RIGHT,
|
|
97
|
+
closeOnClickOutside: true,
|
|
78
98
|
});
|
|
79
99
|
```
|
|
80
100
|
|
|
81
|
-
###
|
|
101
|
+
### 5. Use `closeModal` inside your modal component
|
|
82
102
|
|
|
83
103
|
```tsx
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
import type { ModalParams } from 'react-motion-modal';
|
|
105
|
+
|
|
106
|
+
const ConfirmModal = ({ title, closeModal }: ModalParams<'ConfirmModal'>) => (
|
|
107
|
+
<div>
|
|
108
|
+
<h1>{title}</h1>
|
|
109
|
+
<button onClick={closeModal}>Close</button>
|
|
110
|
+
</div>
|
|
89
111
|
);
|
|
90
112
|
```
|
|
91
113
|
|
|
@@ -104,15 +126,42 @@ Opens a modal by name. The `params` will be inferred based on modal type.
|
|
|
104
126
|
|
|
105
127
|
Each modal automatically receives the following props:
|
|
106
128
|
|
|
107
|
-
| Prop
|
|
108
|
-
|
|
109
|
-
| `closeModal`
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
129
|
+
| Prop | Type | Description |
|
|
130
|
+
|-----------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------|
|
|
131
|
+
| `closeModal` | `() => void` | Close function for the modal |
|
|
132
|
+
| `onClose` | `() => void` | Callback triggered when modal is closed |
|
|
133
|
+
| `closeOnClickOutside` | `boolean` | Close modal when clicking outside |
|
|
134
|
+
| `closeOnPressEsc` | `boolean` | Close modal when Escape key is pressed |
|
|
135
|
+
| `position` | `string` | Modal placement. Unknown values fall back to `center`. |
|
|
136
|
+
| `backdrop` | `{ className?: string; style?: CSSProperties; }` | Customize the backdrop layer |
|
|
137
|
+
| `body` | `{ className?: string; style?: CSSProperties; }` | Customize the modal body wrapper |
|
|
138
|
+
| `animate` | `{ animate?: TargetAndTransition; exit?: TargetAndTransition; }` | Animation powered by Framer Motion. Custom animation disables defaults. |
|
|
139
|
+
| `blur` | `boolean` | Apply backdrop blur |
|
|
140
|
+
|
|
141
|
+
### `MODAL_POSITIONS`
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
MODAL_POSITIONS.TOP;
|
|
145
|
+
MODAL_POSITIONS.TOP_LEFT;
|
|
146
|
+
MODAL_POSITIONS.TOP_RIGHT;
|
|
147
|
+
MODAL_POSITIONS.TOP_CENTER;
|
|
148
|
+
MODAL_POSITIONS.LEFT;
|
|
149
|
+
MODAL_POSITIONS.RIGHT;
|
|
150
|
+
MODAL_POSITIONS.CENTER;
|
|
151
|
+
MODAL_POSITIONS.CENTER_FULL;
|
|
152
|
+
MODAL_POSITIONS.BOTTOM;
|
|
153
|
+
MODAL_POSITIONS.BOTTOM_LEFT;
|
|
154
|
+
MODAL_POSITIONS.BOTTOM_RIGHT;
|
|
155
|
+
MODAL_POSITIONS.BOTTOM_CENTER;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Default body animation follows the position. For example, `left` slides in from the left, `right` slides in from the right, `top` slides down, and `bottom` slides up.
|
|
159
|
+
|
|
160
|
+
## 🔐 Release Security
|
|
161
|
+
|
|
162
|
+
- CI runs from `.github/workflows/ci.yml` on pushes and pull requests.
|
|
163
|
+
- npm publishing is defined in `.github/workflows/publish.yml` and uses `npm publish --provenance --access public`.
|
|
164
|
+
- Trusted publishing still needs to be enabled in npm package settings for this repository before the workflow can publish official releases.
|
|
116
165
|
|
|
117
166
|
## 📝 Notes
|
|
118
167
|
|
|
@@ -122,4 +171,4 @@ Each modal automatically receives the following props:
|
|
|
122
171
|
- Great for complex apps requiring nested or dynamic modal stacks
|
|
123
172
|
|
|
124
173
|
---
|
|
125
|
-
Made with ❤️ by react-motion-modal.
|
|
174
|
+
Made with ❤️ by react-motion-modal.
|
package/dist/index.css
ADDED
|
@@ -0,0 +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){inset:0 50% 50% 0}:where(.react-motion-modal__body--top-right){inset:0 0 50% 50%}:where(.react-motion-modal__body--top-center){top:0;left:50%;transform:translate(-50%);bottom:50%}:where(.react-motion-modal__body--bottom){right:0;bottom:0;left:0;width:100%}:where(.react-motion-modal__body--bottom-left){inset:50% 50% 0 0}:where(.react-motion-modal__body--bottom-right){inset:50% 0 0 50%}:where(.react-motion-modal__body--bottom-center){bottom:0;left:50%;transform:translate(-50%);top:50%}:where(.react-motion-modal__body--left){inset:0 50% 0 0}:where(.react-motion-modal__body--right){inset:0 0 0 50%}:where(.react-motion-modal__body--center){top:50%;left:50%;transform:translate(-50%,-50%);bottom:0}:where(.react-motion-modal__body--center-full){inset:0;width:100%;height:100%}
|
package/dist/index.d.ts
CHANGED
|
@@ -179,15 +179,18 @@ declare type BaseModalParams = {
|
|
|
179
179
|
* import { MODAL_POSITIONS } from 'react-motion-modal';
|
|
180
180
|
*
|
|
181
181
|
* // Available positions
|
|
182
|
+
* MODAL_POSITIONS.TOP // 'top' full width at the top
|
|
182
183
|
* MODAL_POSITIONS.TOP_LEFT // 'top-left'
|
|
183
|
-
* MODAL_POSITIONS.TOP_CENTER // 'top-center'
|
|
184
184
|
* MODAL_POSITIONS.TOP_RIGHT // 'top-right'
|
|
185
|
-
* MODAL_POSITIONS.
|
|
185
|
+
* MODAL_POSITIONS.TOP_CENTER // 'top-center'
|
|
186
|
+
* MODAL_POSITIONS.LEFT // 'left' full height at the left
|
|
187
|
+
* MODAL_POSITIONS.RIGHT // 'right' full height at the right
|
|
186
188
|
* MODAL_POSITIONS.CENTER // 'center' (default)
|
|
187
|
-
* MODAL_POSITIONS.
|
|
189
|
+
* MODAL_POSITIONS.CENTER_FULL // 'center-full'
|
|
190
|
+
* MODAL_POSITIONS.BOTTOM // 'bottom' full width at the bottom
|
|
188
191
|
* MODAL_POSITIONS.BOTTOM_LEFT // 'bottom-left'
|
|
189
|
-
* MODAL_POSITIONS.BOTTOM_CENTER// 'bottom-center'
|
|
190
192
|
* MODAL_POSITIONS.BOTTOM_RIGHT // 'bottom-right'
|
|
193
|
+
* MODAL_POSITIONS.BOTTOM_CENTER// 'bottom-center'
|
|
191
194
|
* ```
|
|
192
195
|
*/
|
|
193
196
|
position?: string;
|
|
@@ -202,15 +205,16 @@ declare type BaseModalParams = {
|
|
|
202
205
|
export declare const MODAL_POSITIONS: {
|
|
203
206
|
TOP: string;
|
|
204
207
|
TOP_LEFT: string;
|
|
205
|
-
TOP_CENTER: string;
|
|
206
208
|
TOP_RIGHT: string;
|
|
207
|
-
|
|
209
|
+
TOP_CENTER: string;
|
|
210
|
+
LEFT: string;
|
|
211
|
+
RIGHT: string;
|
|
208
212
|
CENTER: string;
|
|
209
|
-
|
|
213
|
+
CENTER_FULL: string;
|
|
210
214
|
BOTTOM: string;
|
|
211
215
|
BOTTOM_LEFT: string;
|
|
212
|
-
BOTTOM_CENTER: string;
|
|
213
216
|
BOTTOM_RIGHT: string;
|
|
217
|
+
BOTTOM_CENTER: string;
|
|
214
218
|
};
|
|
215
219
|
|
|
216
220
|
/**
|