react-motion-modal 1.0.7 → 1.1.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 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 { ModalStackParams } from 'react-motion-modal';
33
+ import type { ModalDefinition } from 'react-motion-modal';
34
34
 
35
35
  declare module 'react-motion-modal' {
36
- interface ModalStackParams {
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 }: ModalStackParams<'ConfirmModal'>) => (
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 | 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 |
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` | Callback triggered when modal is closed |
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/react';
4
+ import { TargetAndTransition } from 'motion';
5
5
  import { UseBoundStore } from 'zustand/react';
6
6
 
7
- declare type Action = {
8
- closeModal: (name?: ModalName) => void;
9
- openModal: <T extends ModalName>(name: T, params?: Omit<ModalParams<T>, 'closeModal'>) => void;
10
- };
11
-
12
7
  declare type ActiveModal = {
13
8
  id: string;
14
9
  name: ModalName;
15
- params?: ModalParams<ModalName>;
10
+ params?: Params<ModalName>;
16
11
  };
17
12
 
18
- export declare type BaseModalParams = {
13
+ declare type BaseModalParams = {
19
14
  /**
20
- * Function to close the modal. Automatically injected.
15
+ * Function to close the modal
21
16
  */
22
17
  closeModal: () => void;
23
18
  /**
@@ -55,30 +50,36 @@ export declare type BaseModalParams = {
55
50
  };
56
51
  };
57
52
 
53
+ 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
+
58
59
  declare type ModalComponent<T = any> = (props: T) => ReactElement;
59
60
 
60
- export declare type ModalConfig = {
61
- [K in ModalName]: ModalComponent<ModalParams<K>>;
61
+ declare type ModalConfig = {
62
+ [K in ModalName]: ModalComponent<Params<K>>;
62
63
  };
63
64
 
64
- export declare type ModalName = keyof ModalStackParams;
65
+ export declare interface ModalDefinition {
66
+ }
65
67
 
66
- export declare type ModalParams<T extends ModalName> = ModalStackParams[T] & BaseModalParams;
68
+ declare type ModalName = keyof ModalDefinition;
67
69
 
68
70
  export declare const ModalProvider: ({ modals, initialParams }: Props) => ReactPortal | null;
69
71
 
70
- export declare interface ModalStackParams {
71
- }
72
+ declare type ModalState = {
73
+ activeModals: ActiveModal[];
74
+ };
75
+
76
+ declare type Params<T extends ModalName> = ModalDefinition[T] & BaseModalParams;
72
77
 
73
78
  declare type Props = {
74
79
  modals: ModalConfig;
75
80
  initialParams?: Partial<BaseModalParams>;
76
81
  };
77
82
 
78
- declare type State = {
79
- activeModals: ActiveModal[];
80
- };
81
-
82
- export declare const useModal: UseBoundStore<StoreApi<State & Action>>;
83
+ export declare const useModal: UseBoundStore<StoreApi<ModalState & ModalAction>>;
83
84
 
84
85
  export { }