react-motion-modal 1.2.5 → 1.2.6
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 +70 -37
- package/dist/index.css +1 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +1877 -1837
- package/package.json +5 -5
- package/CHANGELOG.md +0 -73
package/README.md
CHANGED
|
@@ -13,23 +13,30 @@
|
|
|
13
13
|
## 🧱 Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install react-motion-modal
|
|
16
|
+
npm install react-motion-modal motion zustand
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
or with yarn:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
yarn add react-motion-modal zustand
|
|
22
|
+
yarn add react-motion-modal motion zustand
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## 🚀 Usage
|
|
26
26
|
|
|
27
|
-
### 1.
|
|
27
|
+
### 1. Import styles
|
|
28
|
+
|
|
29
|
+
Import the package stylesheet once in your app entry:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import 'react-motion-modal/style.css';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Define modal types
|
|
28
36
|
|
|
29
37
|
Create a `modal.d.ts` file in your project (make sure to include it in tsconfig.json):
|
|
30
38
|
|
|
31
39
|
```ts
|
|
32
|
-
import type { ReactElement } from 'react';
|
|
33
40
|
import type { ModalDefinition } from 'react-motion-modal';
|
|
34
41
|
|
|
35
42
|
declare module 'react-motion-modal' {
|
|
@@ -44,7 +51,7 @@ declare module 'react-motion-modal' {
|
|
|
44
51
|
}
|
|
45
52
|
```
|
|
46
53
|
|
|
47
|
-
###
|
|
54
|
+
### 3. Import <ModalProvider />
|
|
48
55
|
|
|
49
56
|
Import <ModalProvider /> to define your modals
|
|
50
57
|
|
|
@@ -52,40 +59,45 @@ Import <ModalProvider /> to define your modals
|
|
|
52
59
|
import { ModalProvider } from 'react-motion-modal';
|
|
53
60
|
|
|
54
61
|
export const App = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
return (
|
|
63
|
+
<div>
|
|
64
|
+
{/* rest of your app */}
|
|
65
|
+
|
|
66
|
+
<ModalProvider
|
|
67
|
+
modals={{
|
|
68
|
+
AlertModal,
|
|
69
|
+
ConfirmModal,
|
|
70
|
+
}}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
67
75
|
```
|
|
68
76
|
|
|
69
|
-
###
|
|
77
|
+
### 4. Open modal anywhere
|
|
70
78
|
|
|
71
79
|
```tsx
|
|
72
|
-
import { useModal } from 'react-motion-modal';
|
|
80
|
+
import { MODAL_POSITIONS, useModal } from 'react-motion-modal';
|
|
73
81
|
|
|
74
82
|
const { openModal } = useModal();
|
|
75
83
|
|
|
76
|
-
openModal('ConfirmModal', {
|
|
77
|
-
|
|
84
|
+
openModal('ConfirmModal', {
|
|
85
|
+
title: 'Are you sure you want to delete?',
|
|
86
|
+
position: MODAL_POSITIONS.RIGHT,
|
|
87
|
+
closeOnClickOutside: true,
|
|
78
88
|
});
|
|
79
89
|
```
|
|
80
90
|
|
|
81
|
-
###
|
|
91
|
+
### 5. Use `closeModal` inside your modal component
|
|
82
92
|
|
|
83
93
|
```tsx
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
import type { ModalParams } from 'react-motion-modal';
|
|
95
|
+
|
|
96
|
+
const ConfirmModal = ({ title, closeModal }: ModalParams<'ConfirmModal'>) => (
|
|
97
|
+
<div>
|
|
98
|
+
<h1>{title}</h1>
|
|
99
|
+
<button onClick={closeModal}>Close</button>
|
|
100
|
+
</div>
|
|
89
101
|
);
|
|
90
102
|
```
|
|
91
103
|
|
|
@@ -104,15 +116,36 @@ Opens a modal by name. The `params` will be inferred based on modal type.
|
|
|
104
116
|
|
|
105
117
|
Each modal automatically receives the following props:
|
|
106
118
|
|
|
107
|
-
| Prop
|
|
108
|
-
|
|
109
|
-
| `closeModal`
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
119
|
+
| Prop | Type | Description |
|
|
120
|
+
|-----------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------|
|
|
121
|
+
| `closeModal` | `() => void` | Close function for the modal |
|
|
122
|
+
| `onClose` | `() => void` | Callback triggered when modal is closed |
|
|
123
|
+
| `closeOnClickOutside` | `boolean` | Close modal when clicking outside |
|
|
124
|
+
| `closeOnPressEsc` | `boolean` | Close modal when Escape key is pressed |
|
|
125
|
+
| `position` | `string` | Modal placement. Unknown values fall back to `center`. |
|
|
126
|
+
| `backdrop` | `{ className?: string; style?: CSSProperties; }` | Customize the backdrop layer |
|
|
127
|
+
| `body` | `{ className?: string; style?: CSSProperties; }` | Customize the modal body wrapper |
|
|
128
|
+
| `animate` | `{ animate?: TargetAndTransition; exit?: TargetAndTransition; }` | Animation powered by Framer Motion. Custom animation disables defaults. |
|
|
129
|
+
| `blur` | `boolean` | Apply backdrop blur |
|
|
130
|
+
|
|
131
|
+
### `MODAL_POSITIONS`
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
MODAL_POSITIONS.TOP;
|
|
135
|
+
MODAL_POSITIONS.TOP_LEFT;
|
|
136
|
+
MODAL_POSITIONS.TOP_RIGHT;
|
|
137
|
+
MODAL_POSITIONS.TOP_CENTER;
|
|
138
|
+
MODAL_POSITIONS.LEFT;
|
|
139
|
+
MODAL_POSITIONS.RIGHT;
|
|
140
|
+
MODAL_POSITIONS.CENTER;
|
|
141
|
+
MODAL_POSITIONS.CENTER_FULL;
|
|
142
|
+
MODAL_POSITIONS.BOTTOM;
|
|
143
|
+
MODAL_POSITIONS.BOTTOM_LEFT;
|
|
144
|
+
MODAL_POSITIONS.BOTTOM_RIGHT;
|
|
145
|
+
MODAL_POSITIONS.BOTTOM_CENTER;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
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.
|
|
116
149
|
|
|
117
150
|
## 📝 Notes
|
|
118
151
|
|
|
@@ -122,4 +155,4 @@ Each modal automatically receives the following props:
|
|
|
122
155
|
- Great for complex apps requiring nested or dynamic modal stacks
|
|
123
156
|
|
|
124
157
|
---
|
|
125
|
-
Made with ❤️ by react-motion-modal.
|
|
158
|
+
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
|
/**
|