react-motion-modal 1.3.1 → 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 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 `npm publish --provenance --access public`.
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){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%}
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
@@ -197,7 +212,7 @@ declare type BaseModalParams = {
197
212
  /**
198
213
  * Enables backdrop blur effect when modal is open.
199
214
  * When set to true, the background content will be blurred.
200
- * @default false
215
+ * @default true
201
216
  */
202
217
  blur?: boolean;
203
218
  };
@@ -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 config={modalConfig}>
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 }: Props) => ReactPortal | null;
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 { }