react-motion-modal 1.0.8 → 1.1.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/README.md +11 -11
- package/dist/index.d.ts +23 -20
- package/dist/index.js +887 -881
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,10 +30,10 @@ Create a `modal.d.ts` file in your project (make sure to include it in tsconfig.
|
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import type { ReactElement } from 'react';
|
|
33
|
-
import type {
|
|
33
|
+
import type { ModalDefinition } from 'react-motion-modal';
|
|
34
34
|
|
|
35
35
|
declare module 'react-motion-modal' {
|
|
36
|
-
interface
|
|
36
|
+
interface ModalDefinition {
|
|
37
37
|
AlertModal: {
|
|
38
38
|
title: string;
|
|
39
39
|
};
|
|
@@ -59,7 +59,7 @@ openModal('ConfirmModal', {1
|
|
|
59
59
|
### 3. Use `closeModal` inside your modal component
|
|
60
60
|
|
|
61
61
|
```tsx
|
|
62
|
-
const ConfirmModal = ({ title, closeModal }:
|
|
62
|
+
const ConfirmModal = ({ title, closeModal }: ModalDefinition<'ConfirmModal'>) => (
|
|
63
63
|
<div>
|
|
64
64
|
<h1>{title}</h1>
|
|
65
65
|
<button onClick={closeModal}>Close</button>
|
|
@@ -82,15 +82,15 @@ Opens a modal by name. The `params` will be inferred based on modal type.
|
|
|
82
82
|
|
|
83
83
|
Each modal automatically receives the following props:
|
|
84
84
|
|
|
85
|
-
| Prop | Type
|
|
86
|
-
|
|
87
|
-
| `closeModal` | `() => void`
|
|
88
|
-
| `closeOnClickOutside` | `boolean`
|
|
89
|
-
| `closeOnPressEsc` | `boolean`
|
|
90
|
-
| `container` | `{ className?: string; override?: boolean; }`
|
|
91
|
-
| `body` | `{ className?: string; override?: boolean; }`
|
|
85
|
+
| Prop | Type | Description |
|
|
86
|
+
|-------------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------|
|
|
87
|
+
| `closeModal` | `() => void` | Close function for the modal |
|
|
88
|
+
| `closeOnClickOutside` | `boolean` | Close modal when clicking outside |
|
|
89
|
+
| `closeOnPressEsc` | `boolean` | Close modal when Escape key is pressed |
|
|
90
|
+
| `container` | `{ className?: string; override?: boolean; }` | Customize wrapper styles |
|
|
91
|
+
| `body` | `{ className?: string; override?: boolean; }` | Customize inner modal styles |
|
|
92
92
|
| `animate` | `{ animate?: TargetAndTransition; exit?: TargetAndTransition; }` | Animation powered by Framer Motion. Customize how the modal enters and exits. |
|
|
93
|
-
| `onClose` | `() => void`
|
|
93
|
+
| `onClose` | `() => void` | Callback triggered when modal is closed |
|
|
94
94
|
|
|
95
95
|
## 📝 Notes
|
|
96
96
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { ReactPortal } from 'react';
|
|
3
3
|
import { StoreApi } from 'zustand/vanilla';
|
|
4
|
-
import { TargetAndTransition } from 'motion
|
|
4
|
+
import { TargetAndTransition } from 'motion';
|
|
5
5
|
import { UseBoundStore } from 'zustand/react';
|
|
6
6
|
|
|
7
|
-
declare type
|
|
8
|
-
closeModal: (name?: ModalName) => void;
|
|
9
|
-
openModal: <T extends ModalName>(name: T, params?: Omit<ModalParams<T>, 'closeModal'>) => void;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare type ActiveModal = {
|
|
7
|
+
export declare type ActiveModal = {
|
|
13
8
|
id: string;
|
|
14
9
|
name: ModalName;
|
|
15
|
-
params?:
|
|
10
|
+
params?: Params<ModalName>;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
13
|
export declare type BaseModalParams = {
|
|
19
14
|
/**
|
|
20
|
-
* Function to close the modal
|
|
15
|
+
* Function to close the modal
|
|
21
16
|
*/
|
|
22
17
|
closeModal: () => void;
|
|
23
18
|
/**
|
|
@@ -55,30 +50,38 @@ export declare type BaseModalParams = {
|
|
|
55
50
|
};
|
|
56
51
|
};
|
|
57
52
|
|
|
58
|
-
declare type
|
|
53
|
+
export declare type ModalAction = {
|
|
54
|
+
closeModal: (name?: ModalName) => void;
|
|
55
|
+
closeAllModal: () => void;
|
|
56
|
+
openModal: <T extends ModalName>(name: T, params?: Omit<Params<T>, 'closeModal'>) => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export declare type ModalComponent<T = any> = (props: T) => ReactElement;
|
|
59
60
|
|
|
60
61
|
export declare type ModalConfig = {
|
|
61
|
-
[K in ModalName]: ModalComponent<
|
|
62
|
+
[K in ModalName]: ModalComponent<Params<K>>;
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
export declare
|
|
65
|
+
export declare interface ModalDefinition {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export declare type ModalName = keyof ModalDefinition;
|
|
65
69
|
|
|
66
|
-
export declare type ModalParams<T extends ModalName> =
|
|
70
|
+
export declare type ModalParams<T extends ModalName> = Omit<Params<T>, 'animate' | 'body' | 'container' | 'onClose'>;
|
|
67
71
|
|
|
68
72
|
export declare const ModalProvider: ({ modals, initialParams }: Props) => ReactPortal | null;
|
|
69
73
|
|
|
70
|
-
export declare
|
|
71
|
-
|
|
74
|
+
export declare type ModalState = {
|
|
75
|
+
activeModals: ActiveModal[];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export declare type Params<T extends ModalName> = ModalDefinition[T] & BaseModalParams;
|
|
72
79
|
|
|
73
80
|
declare type Props = {
|
|
74
81
|
modals: ModalConfig;
|
|
75
82
|
initialParams?: Partial<BaseModalParams>;
|
|
76
83
|
};
|
|
77
84
|
|
|
78
|
-
declare
|
|
79
|
-
activeModals: ActiveModal[];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export declare const useModal: UseBoundStore<StoreApi<State & Action>>;
|
|
85
|
+
export declare const useModal: UseBoundStore<StoreApi<ModalState & ModalAction>>;
|
|
83
86
|
|
|
84
87
|
export { }
|