@trackunit/react-modal 1.12.0 → 1.12.7
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/index.cjs.js +407 -97
- package/index.esm.js +408 -100
- package/package.json +7 -8
- package/src/index.d.ts +1 -1
- package/src/modal/Modal.d.ts +5 -5
- package/src/modal/Modal.stories.d.ts +3 -19
- package/src/modal/Modal.variants.d.ts +7 -2
- package/src/modal/ModalHeader/ModalHeader.d.ts +6 -6
- package/src/modal/ModalHeader/ModalHeader.stories.d.ts +1 -1
- package/src/modal/modalStackRegistry.d.ts +119 -0
- package/src/modal/useModal.d.ts +97 -27
- package/src/modal/useModalStack.d.ts +25 -0
- package/src/translation.d.ts +4 -7
- package/src/modal/ModalBackdrop.d.ts +0 -12
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./modal/Modal";
|
|
2
|
-
export * from "./modal/ModalBackdrop";
|
|
3
2
|
export * from "./modal/ModalBody/ModalBody";
|
|
4
3
|
export * from "./modal/ModalFooter/ModalFooter";
|
|
5
4
|
export * from "./modal/ModalHeader/ModalHeader";
|
|
5
|
+
export * from "./modal/modalStackRegistry";
|
|
6
6
|
export * from "./modal/useModal";
|
package/src/modal/Modal.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Size } from "@trackunit/react-components";
|
|
2
2
|
import { PropsWithChildren, ReactElement } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { UseModalReturnValue } from "./useModal";
|
|
4
4
|
/**
|
|
5
5
|
* Modal props extend the return type of useModal and add presentational-only props.
|
|
6
6
|
*/
|
|
7
|
-
export type ModalProps
|
|
7
|
+
export type ModalProps = PropsWithChildren<UseModalReturnValue & {
|
|
8
8
|
/**
|
|
9
9
|
* The size of the modal card.
|
|
10
10
|
*/
|
|
@@ -34,9 +34,9 @@ export type ModalProps<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOp
|
|
|
34
34
|
* );
|
|
35
35
|
* };
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const ChildComponent = ({...modalProps}: UseModalReturnValue) => {
|
|
38
38
|
* return (* <Modal {...modalProps}>
|
|
39
|
-
* <ModalHeader
|
|
39
|
+
* <ModalHeader onClickClose={modalProps.close} heading="My Modal" />
|
|
40
40
|
* <ModalBody>
|
|
41
41
|
* <p>This is a modal</p>
|
|
42
42
|
* </ModalBody>
|
|
@@ -46,6 +46,6 @@ export type ModalProps<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOp
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export declare const Modal: {
|
|
49
|
-
|
|
49
|
+
({ children, isOpen, role, "data-testid": dataTestId, className, size, floatingUi, ref, }: ModalProps): ReactElement;
|
|
50
50
|
displayName: string;
|
|
51
51
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { StoryObjWithOptionalArgs } from "@trackunit/shared-utils";
|
|
2
2
|
import { ReactElement } from "react";
|
|
3
|
-
type Story = StoryObjWithOptionalArgs<typeof meta, "ref" | "isOpen" | "close" | "open" | "toggle" | "
|
|
3
|
+
type Story = StoryObjWithOptionalArgs<typeof meta, "ref" | "isOpen" | "close" | "open" | "toggle" | "floatingUi" | "children">;
|
|
4
4
|
declare const meta: {
|
|
5
5
|
title: string;
|
|
6
6
|
component: {
|
|
7
|
-
|
|
7
|
+
({ children, isOpen, role, "data-testid": dataTestId, className, size, floatingUi, ref, }: import("./Modal").ModalProps): ReactElement;
|
|
8
8
|
displayName: string;
|
|
9
9
|
};
|
|
10
10
|
tags: string[];
|
|
@@ -34,13 +34,6 @@ declare const meta: {
|
|
|
34
34
|
category: string;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
onBackdropClick: {
|
|
38
|
-
control: false;
|
|
39
|
-
description: string;
|
|
40
|
-
table: {
|
|
41
|
-
category: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
37
|
open: {
|
|
45
38
|
control: false;
|
|
46
39
|
description: string;
|
|
@@ -69,16 +62,6 @@ declare const meta: {
|
|
|
69
62
|
category: string;
|
|
70
63
|
};
|
|
71
64
|
};
|
|
72
|
-
closeOnOutsideClick: {
|
|
73
|
-
control: false;
|
|
74
|
-
description: string;
|
|
75
|
-
table: {
|
|
76
|
-
category: string;
|
|
77
|
-
defaultValue: {
|
|
78
|
-
summary: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
65
|
size: {
|
|
83
66
|
control: {
|
|
84
67
|
type: "select";
|
|
@@ -98,3 +81,4 @@ export declare const PackageName: () => ReactElement;
|
|
|
98
81
|
export declare const Default: Story;
|
|
99
82
|
export declare const WithScrollableContent: Story;
|
|
100
83
|
export declare const MultiColumnLayout: Story;
|
|
84
|
+
export declare const UnsavedChangesConfirmation: Story;
|
|
@@ -5,5 +5,10 @@ export declare const cvaModalContainer: (props?: import("class-variance-authorit
|
|
|
5
5
|
* Returns the CSS properties for the modal card based on the size.
|
|
6
6
|
*/
|
|
7
7
|
export declare const getModalCardCSSVariables: (size: Size) => CSSProperties;
|
|
8
|
-
export declare const cvaModalCard: (props?:
|
|
9
|
-
|
|
8
|
+
export declare const cvaModalCard: (props?: ({
|
|
9
|
+
animation?: "fade" | "rise" | null | undefined;
|
|
10
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
11
|
+
export declare const cvaModalBackdrop: (props?: ({
|
|
12
|
+
isFrontmost?: boolean | null | undefined;
|
|
13
|
+
shouldAnimate?: boolean | null | undefined;
|
|
14
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
-
import {
|
|
2
|
+
import { MouseEventHandler, ReactNode } from "react";
|
|
3
3
|
export interface ModalHeaderProps extends CommonProps {
|
|
4
4
|
/**
|
|
5
5
|
* Main title displayed in the modal header.
|
|
@@ -9,11 +9,11 @@ export interface ModalHeaderProps extends CommonProps {
|
|
|
9
9
|
* Optional subtitle displayed below the main title.
|
|
10
10
|
* Not rendered when undefined.
|
|
11
11
|
*/
|
|
12
|
-
subHeading?:
|
|
12
|
+
subHeading?: ReactNode;
|
|
13
13
|
/**
|
|
14
14
|
* Click handler for the close button.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
onClickClose: MouseEventHandler<HTMLButtonElement>;
|
|
17
17
|
/**
|
|
18
18
|
* The id of the element.
|
|
19
19
|
*/
|
|
@@ -21,7 +21,7 @@ export interface ModalHeaderProps extends CommonProps {
|
|
|
21
21
|
/**
|
|
22
22
|
* Children to render in the header
|
|
23
23
|
*/
|
|
24
|
-
children?: ReactNode
|
|
24
|
+
children?: ReactNode;
|
|
25
25
|
/**
|
|
26
26
|
* Items to render next to the heading
|
|
27
27
|
*/
|
|
@@ -74,9 +74,9 @@ export interface ModalHeaderProps extends CommonProps {
|
|
|
74
74
|
* @param {ModalHeaderProps} props Component props.
|
|
75
75
|
* @param {string} [props.heading] Main heading text.
|
|
76
76
|
* @param {string} [props.subHeading] Optional subheading content.
|
|
77
|
-
* @param {() => void} props.
|
|
77
|
+
* @param {() => void} props.onClickClose Close button click handler.
|
|
78
78
|
* @param {string} [props."data-testid"] Optional test id for the container.
|
|
79
79
|
* @param {string} [props.className] Optional additional class name(s).
|
|
80
|
-
* @returns
|
|
80
|
+
* @returns The modal header element.
|
|
81
81
|
*/
|
|
82
82
|
export declare const ModalHeader: import("react").ForwardRefExoticComponent<ModalHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modal Stack Registry - Cross-Bundle Modal Awareness
|
|
3
|
+
*
|
|
4
|
+
* ## Architecture Overview
|
|
5
|
+
*
|
|
6
|
+
* This module provides a registry for tracking open modals across bundle boundaries
|
|
7
|
+
* (host application + Iris app iframes). It enables proper modal stacking behavior
|
|
8
|
+
* where modals can visually indicate their depth (scale, backdrop visibility, animations).
|
|
9
|
+
*
|
|
10
|
+
* ## Why postMessage Instead of Penpal?
|
|
11
|
+
*
|
|
12
|
+
* While most host-iframe communication uses Penpal (RPC-style), modal stack changes
|
|
13
|
+
* use raw postMessage for these reasons:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Package Independence**: This module is part of `@trackunit/react-modal`, a standalone
|
|
16
|
+
* UI component library. It should not depend on `iris-app-runtime` to avoid circular
|
|
17
|
+
* dependencies and keep the modal component reusable.
|
|
18
|
+
*
|
|
19
|
+
* 2. **Broadcast Semantics**: When a host modal opens, ALL iframe modals need to know
|
|
20
|
+
* simultaneously (not just one specific connection). postMessage with broadcast
|
|
21
|
+
* to all iframes fits this pattern naturally.
|
|
22
|
+
*
|
|
23
|
+
* 3. **Low Latency**: Stack count changes need real-time sync for smooth animations
|
|
24
|
+
* (scale transforms, backdrop fading). Raw postMessage has less overhead than Penpal.
|
|
25
|
+
*
|
|
26
|
+
* 4. **Module Isolation**: Each bundle (host + each iframe) gets its own instance of
|
|
27
|
+
* this registry. They need cross-window synchronization, not shared state.
|
|
28
|
+
*
|
|
29
|
+
* ## Communication Flow
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* ┌─────────────────────────────────────────────────────────────────────┐
|
|
33
|
+
* │ HOST APPLICATION │
|
|
34
|
+
* │ │
|
|
35
|
+
* │ modalStackRegistry ←───────────────────────────────────────────┐ │
|
|
36
|
+
* │ │ │ │
|
|
37
|
+
* │ │ subscribe() │ │
|
|
38
|
+
* │ ▼ │ │
|
|
39
|
+
* │ ModalDialogProviderHost │ │
|
|
40
|
+
* │ │ │ │
|
|
41
|
+
* │ ├─► broadcasts MODAL_STACK_MESSAGE_TYPE to all iframes │ │
|
|
42
|
+
* │ │ │ │
|
|
43
|
+
* │ └─► listens for IFRAME_MODAL_STACK_MESSAGE_TYPE ──────────┘ │
|
|
44
|
+
* │ (aggregates per-iframe, cleans up on iframe removal) │
|
|
45
|
+
* └─────────────────────────────────────────────────────────────────────┘
|
|
46
|
+
* │
|
|
47
|
+
* postMessage (bidirectional)
|
|
48
|
+
* │
|
|
49
|
+
* ┌─────────────────────────────────────────────────────────────────────┐
|
|
50
|
+
* │ IFRAME (Iris App) │
|
|
51
|
+
* │ │
|
|
52
|
+
* │ modalStackRegistry (separate instance) │
|
|
53
|
+
* │ │ │
|
|
54
|
+
* │ ├─► listens for MODAL_STACK_MESSAGE_TYPE from host │
|
|
55
|
+
* │ │ (updates hostModalCount) │
|
|
56
|
+
* │ │ │
|
|
57
|
+
* │ └─► on register/unregister, broadcasts │
|
|
58
|
+
* │ IFRAME_MODAL_STACK_MESSAGE_TYPE to parent │
|
|
59
|
+
* └─────────────────────────────────────────────────────────────────────┘
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ## Usage with useModalStack Hook
|
|
63
|
+
*
|
|
64
|
+
* The `useModalStack` hook consumes this registry to calculate:
|
|
65
|
+
* - `depthFromFront`: How many modals are in front of this one (0 = frontmost)
|
|
66
|
+
* - `stackSize`: Total modals open (local + host + iframe)
|
|
67
|
+
* - `stackSizeAtOpen`: Stack size when this modal opened (for animation decisions)
|
|
68
|
+
*
|
|
69
|
+
* This enables the Modal component to:
|
|
70
|
+
* - Scale down non-frontmost modals (visual stacking effect)
|
|
71
|
+
* - Show backdrop only on the frontmost modal
|
|
72
|
+
* - Choose appropriate animations based on whether it's opening over another modal
|
|
73
|
+
*
|
|
74
|
+
* @module modalStackRegistry
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Message type for host → iframe modal stack communication.
|
|
78
|
+
* The host broadcasts this to all iframes when its modal count changes.
|
|
79
|
+
* Iframes listen for this to update their `hostModalCount`.
|
|
80
|
+
*/
|
|
81
|
+
export declare const MODAL_STACK_MESSAGE_TYPE = "IRIS_APP_HOST_MODAL_STACK_CHANGE";
|
|
82
|
+
/**
|
|
83
|
+
* Message type for iframe → host modal stack communication.
|
|
84
|
+
* Each iframe sends this to the parent when its modal count changes.
|
|
85
|
+
* The host aggregates these per-iframe for accurate total tracking.
|
|
86
|
+
*/
|
|
87
|
+
export declare const IFRAME_MODAL_STACK_MESSAGE_TYPE = "IRIS_APP_IFRAME_MODAL_STACK_CHANGE";
|
|
88
|
+
/**
|
|
89
|
+
* Module-level registry to track the stack of open modals.
|
|
90
|
+
*
|
|
91
|
+
* This registry enables:
|
|
92
|
+
* - Tracking modal order within a single bundle (local stack)
|
|
93
|
+
* - Awareness of modals in other bundles (host ↔ iframe communication)
|
|
94
|
+
* - Subscriber notifications for React integration via useSyncExternalStore
|
|
95
|
+
*
|
|
96
|
+
* Cross-bundle counts:
|
|
97
|
+
* - `hostModalCount`: Number of modals open in the host (relevant for iframes)
|
|
98
|
+
* - `iframeModalCount`: Number of modals open in iframes (relevant for host)
|
|
99
|
+
*
|
|
100
|
+
* Note: This is intentionally NOT a React hook because:
|
|
101
|
+
* 1. It needs to be a singleton that persists across React component lifecycles
|
|
102
|
+
* 2. It must work with postMessage for cross-bundle communication (host ↔ iframe)
|
|
103
|
+
* 3. The useModalStack hook consumes this registry via useSyncExternalStore for React integration
|
|
104
|
+
*/
|
|
105
|
+
export declare const modalStackRegistry: {
|
|
106
|
+
register: (id: string) => void;
|
|
107
|
+
unregister: (id: string) => void;
|
|
108
|
+
getStackPosition: (id: string) => number;
|
|
109
|
+
getStackSize: () => number;
|
|
110
|
+
/** Get the number of modals open in the host (only relevant for Iris apps in iframes) */
|
|
111
|
+
getHostModalCount: () => number;
|
|
112
|
+
/** Get the number of modals open in iframes (only relevant for host) */
|
|
113
|
+
getIframeModalCount: () => number;
|
|
114
|
+
/** Set the host modal count (called when receiving messages from host) */
|
|
115
|
+
setHostModalCount: (count: number) => void;
|
|
116
|
+
/** Set the iframe modal count (called when receiving messages from iframes) */
|
|
117
|
+
setIframeModalCount: (count: number) => void;
|
|
118
|
+
subscribe: (listener: () => void) => (() => void);
|
|
119
|
+
};
|
package/src/modal/useModal.d.ts
CHANGED
|
@@ -1,19 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseDismissProps, UseFloatingReturn, useInteractions } from "@floating-ui/react";
|
|
2
2
|
import { UseFloatingReturn as UseFloatingReturn_Dom } from "@floating-ui/react-dom";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { AriaRole, Ref } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Reasons why a modal's open state changed.
|
|
6
|
+
* - `escape-key`: User pressed the ESC key
|
|
7
|
+
* - `outside-press`: User clicked outside the modal
|
|
8
|
+
* - `programmatic`: The close() function was called (e.g., from a close button)
|
|
9
|
+
*/
|
|
10
|
+
export type ModalCloseReason = "escape-key" | "outside-press" | "programmatic";
|
|
11
|
+
/**
|
|
12
|
+
* Callback fired BEFORE the modal closes on ESC or outside click.
|
|
13
|
+
* Return `false` (or Promise resolving to `false`) to prevent closing.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // With confirmation dialog
|
|
17
|
+
* onBeforeClose: async (event, reason) => {
|
|
18
|
+
* if (reason === "escape-key") return true; // Allow ESC to close without confirmation
|
|
19
|
+
* const result = await confirm({ title: "Discard changes?" });
|
|
20
|
+
* return result === "PRIMARY";
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
type OnBeforeCloseFn = (event?: Event, reason?: ModalCloseReason) => boolean | Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Options for configuring modal dismissal behavior.
|
|
26
|
+
* Maps directly to FloatingUI's useDismiss options.
|
|
27
|
+
*
|
|
28
|
+
* @see https://floating-ui.com/docs/usedismiss
|
|
29
|
+
*/
|
|
30
|
+
export type ModalDismissOptions = Omit<UseDismissProps, "enabled">;
|
|
31
|
+
export type UseModalProps = {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the modal is open (controlled mode).
|
|
34
|
+
*
|
|
35
|
+
* Prefer uncontrolled mode using `modal.open()` and `modal.close()`.
|
|
36
|
+
*
|
|
37
|
+
* **Controlled mode limitations:**
|
|
38
|
+
* - `onBeforeClose` only fires for ESC, outside click, and `modal.close()` calls
|
|
39
|
+
* - `onBeforeClose` does NOT fire for browser back/forward, link navigation, or external state changes
|
|
40
|
+
*
|
|
41
|
+
* **Alternatives:**
|
|
42
|
+
* - Use `defaultOpen` to start the modal in open state
|
|
43
|
+
* - If you need to manage modal state from a parent, lift the whole `useModal()` instance to the parent
|
|
44
|
+
* - Only use `isOpen` for route-based modals where the modal is always open when the route is active
|
|
45
|
+
*/
|
|
10
46
|
isOpen?: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Whether the modal should start open (uncontrolled mode).
|
|
49
|
+
* Unlike `isOpen`, this only sets the initial state and does not trigger `onOpen`.
|
|
50
|
+
*/
|
|
51
|
+
defaultOpen?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Callback fired when the modal closes.
|
|
54
|
+
*/
|
|
55
|
+
onClose?: (event?: Event, reason?: ModalCloseReason) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Callback fired when the modal opens.
|
|
58
|
+
*/
|
|
59
|
+
onOpen?: (event?: Event) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Callback fired when the modal open state changes.
|
|
62
|
+
* Alternative to using separate onOpen/onClose callbacks.
|
|
63
|
+
*/
|
|
64
|
+
onOpenChange?: (open: boolean, event?: Event, reason?: ModalCloseReason) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Callback fired BEFORE the modal closes on ESC, outside click, or close().
|
|
67
|
+
* Return `false` (or Promise resolving to `false`) to prevent closing.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // With confirmation dialog for unsaved changes
|
|
71
|
+
* onBeforeClose: async () => {
|
|
72
|
+
* if (!isDirty) return true;
|
|
73
|
+
* const result = await confirm({ title: "Discard changes?" });
|
|
74
|
+
* return result === "PRIMARY";
|
|
75
|
+
* }
|
|
76
|
+
*/
|
|
77
|
+
onBeforeClose?: OnBeforeCloseFn;
|
|
78
|
+
/**
|
|
79
|
+
* The root element to render the modal portal into.
|
|
80
|
+
*/
|
|
14
81
|
rootElement?: HTMLElement;
|
|
15
|
-
|
|
16
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for modal dismissal behavior.
|
|
84
|
+
* Maps directly to FloatingUI's useDismiss options.
|
|
85
|
+
*
|
|
86
|
+
* @default { escapeKey: true, outsidePress: true }
|
|
87
|
+
* @example
|
|
88
|
+
* // Disable outside click dismissal
|
|
89
|
+
* dismiss: { outsidePress: false }
|
|
90
|
+
*/
|
|
91
|
+
dismiss?: ModalDismissOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Custom ref for the modal container.
|
|
94
|
+
*/
|
|
17
95
|
ref?: Ref<HTMLDivElement>;
|
|
18
96
|
/**
|
|
19
97
|
* The aria role for the modal.
|
|
@@ -24,9 +102,9 @@ type FloatingUiProps = {
|
|
|
24
102
|
refs: UseFloatingReturn_Dom["refs"];
|
|
25
103
|
rootElement?: HTMLElement;
|
|
26
104
|
context: UseFloatingReturn["context"];
|
|
27
|
-
getFloatingProps:
|
|
105
|
+
getFloatingProps: ReturnType<typeof useInteractions>["getFloatingProps"];
|
|
28
106
|
};
|
|
29
|
-
export type UseModalReturnValue
|
|
107
|
+
export type UseModalReturnValue = {
|
|
30
108
|
/**
|
|
31
109
|
* The ref for the modal.
|
|
32
110
|
*/
|
|
@@ -35,26 +113,18 @@ export type UseModalReturnValue<TOnCloseFnArgs extends BaseUseModalActionArgs =
|
|
|
35
113
|
* Whether the modal is open.
|
|
36
114
|
*/
|
|
37
115
|
isOpen: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Whether the modal should close when the user clicks outside of the modal.
|
|
40
|
-
*/
|
|
41
|
-
closeOnOutsideClick: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* The callback function to call when the user clicks outside of the modal.
|
|
44
|
-
*/
|
|
45
|
-
onBackdropClick: () => void;
|
|
46
116
|
/**
|
|
47
117
|
* A function to call for opening the modal.
|
|
48
118
|
*/
|
|
49
|
-
open:
|
|
119
|
+
open: () => void;
|
|
50
120
|
/**
|
|
51
121
|
* A function to call for toggling the modal visibility.
|
|
52
122
|
*/
|
|
53
|
-
toggle: (
|
|
123
|
+
toggle: () => void;
|
|
54
124
|
/**
|
|
55
125
|
* A function to call for closing the modal.
|
|
56
126
|
*/
|
|
57
|
-
close:
|
|
127
|
+
close: () => void;
|
|
58
128
|
/**
|
|
59
129
|
* The floating UI properties for the modal.
|
|
60
130
|
*/
|
|
@@ -71,5 +141,5 @@ export type UseModalReturnValue<TOnCloseFnArgs extends BaseUseModalActionArgs =
|
|
|
71
141
|
* - const modal = useModal();
|
|
72
142
|
* - <Modal {...modal} size="medium" />
|
|
73
143
|
*/
|
|
74
|
-
export declare const useModal:
|
|
144
|
+
export declare const useModal: (props?: UseModalProps) => UseModalReturnValue;
|
|
75
145
|
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type UseModalStackResult = {
|
|
2
|
+
/**
|
|
3
|
+
* How many modals are in front of this one (0 = frontmost)
|
|
4
|
+
*/
|
|
5
|
+
depthFromFront: number;
|
|
6
|
+
/**
|
|
7
|
+
* Current number of open modals in the stack
|
|
8
|
+
*/
|
|
9
|
+
stackSize: number;
|
|
10
|
+
/**
|
|
11
|
+
* The stack size when this modal opened (stable after open, useful for one-time decisions)
|
|
12
|
+
*/
|
|
13
|
+
stackSizeAtOpen: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Hook to track this modal's position in the stack of open modals.
|
|
17
|
+
* Returns the depth from front (0 = frontmost, 1 = one modal in front, etc.)
|
|
18
|
+
*
|
|
19
|
+
* This hook is aware of modals across bundle boundaries (host + Iris apps)
|
|
20
|
+
* by listening for host modal count changes via postMessage.
|
|
21
|
+
*
|
|
22
|
+
* @param isOpen - Whether the modal is currently open
|
|
23
|
+
*/
|
|
24
|
+
export declare const useModalStack: (isOpen: boolean) => UseModalStackResult;
|
|
25
|
+
export {};
|
package/src/translation.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { NamespaceTransProps, TransForLibs, TranslationResource } from "@trackunit/i18n-library-translation";
|
|
1
|
+
import { NamespaceTransProps, TransForLibs, TranslationResource, useNamespaceTranslation } from "@trackunit/i18n-library-translation";
|
|
2
|
+
import { ReactElement } from "react";
|
|
2
3
|
import defaultTranslations from "./locales/en/translation.json";
|
|
3
4
|
/** A type for all available translation keys in this library */
|
|
4
5
|
export type TranslationKeys = keyof typeof defaultTranslations;
|
|
@@ -14,11 +15,7 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
14
15
|
/**
|
|
15
16
|
* Local useTranslation for this specific library
|
|
16
17
|
*/
|
|
17
|
-
export declare const useTranslation: () =>
|
|
18
|
-
t: TransForLibs<never>;
|
|
19
|
-
i18n: import("i18next").i18n;
|
|
20
|
-
ready: boolean;
|
|
21
|
-
};
|
|
18
|
+
export declare const useTranslation: () => ReturnType<typeof useNamespaceTranslation<TranslationKeys>>;
|
|
22
19
|
/**
|
|
23
20
|
* Type of the t function for the local useTranslation for this specific library
|
|
24
21
|
*/
|
|
@@ -26,7 +23,7 @@ export type TranslationFunction = TransForLibs<TranslationKeys>;
|
|
|
26
23
|
/**
|
|
27
24
|
* Trans for this specific library.
|
|
28
25
|
*/
|
|
29
|
-
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) =>
|
|
26
|
+
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => ReactElement;
|
|
30
27
|
/**
|
|
31
28
|
* Registers the translations for this library
|
|
32
29
|
*/
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
export interface ModalBackdropProps {
|
|
3
|
-
onClick: () => void;
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* The Backdrop for the modal.
|
|
8
|
-
*
|
|
9
|
-
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
10
|
-
* @returns {ReactElement} ModalBackdrop component
|
|
11
|
-
*/
|
|
12
|
-
export declare const ModalBackdrop: ({ children, onClick }: ModalBackdropProps) => import("react/jsx-runtime").JSX.Element;
|