@trackunit/react-modal 1.3.26 → 1.3.31
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 +12 -32
- package/index.esm.js +10 -12
- package/package.json +7 -7
- package/src/modal/Modal.d.ts +10 -4
- package/src/modal/ModalBackdrop.d.ts +2 -3
- package/src/modal/useModal.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -4,29 +4,10 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
5
|
var reactComponents = require('@trackunit/react-components');
|
|
6
6
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
7
|
-
var
|
|
7
|
+
var react = require('react');
|
|
8
8
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
9
|
var usePortal = require('react-useportal');
|
|
10
10
|
|
|
11
|
-
function _interopNamespaceDefault(e) {
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
29
|
-
|
|
30
11
|
var defaultTranslations = {
|
|
31
12
|
|
|
32
13
|
};
|
|
@@ -133,12 +114,12 @@ const cvaModalBackdrop = cssClassVarianceUtilities.cvaMerge([
|
|
|
133
114
|
|
|
134
115
|
/**
|
|
135
116
|
* The Backdrop for the modal.
|
|
136
|
-
|
|
117
|
+
*
|
|
137
118
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
138
|
-
* @returns {
|
|
119
|
+
* @returns {ReactElement} ModalBackdrop component
|
|
139
120
|
*/
|
|
140
121
|
const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) => {
|
|
141
|
-
const ref =
|
|
122
|
+
const ref = react.useRef(null);
|
|
142
123
|
return (jsxRuntime.jsx("div", { className: cvaModalBackdrop({ show: isVisible, noShadow, isFastOpen }), onMouseDown: e => {
|
|
143
124
|
// only react on click on backdrop - accessing first child to get around styled element element
|
|
144
125
|
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
@@ -151,13 +132,12 @@ const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) =
|
|
|
151
132
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
152
133
|
* - Modals interrupt a user's workflow by design.
|
|
153
134
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
154
|
-
|
|
155
135
|
*/
|
|
156
|
-
const Modal =
|
|
136
|
+
const Modal = ({ isOpen, children, dataTestId, className, containerClassName, role = "", noBackdropShadow = false, isFastOpen = false, onDismissClick = () => {
|
|
157
137
|
return;
|
|
158
|
-
},
|
|
138
|
+
}, ref, }) => {
|
|
159
139
|
const { openModal, closeModal } = reactCoreHooks.useModalDialogContext();
|
|
160
|
-
|
|
140
|
+
react.useEffect(() => {
|
|
161
141
|
if (isOpen) {
|
|
162
142
|
openModal();
|
|
163
143
|
}
|
|
@@ -165,7 +145,7 @@ const Modal = React__namespace.forwardRef(({ isOpen, children, dataTestId, class
|
|
|
165
145
|
closeModal();
|
|
166
146
|
}
|
|
167
147
|
}, [isOpen, openModal, closeModal]);
|
|
168
|
-
|
|
148
|
+
react.useEffect(() => {
|
|
169
149
|
return () => {
|
|
170
150
|
if (isOpen) {
|
|
171
151
|
closeModal();
|
|
@@ -174,17 +154,17 @@ const Modal = React__namespace.forwardRef(({ isOpen, children, dataTestId, class
|
|
|
174
154
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
175
155
|
}, []); // Empty dependency array means this effect runs only on mount and unmount
|
|
176
156
|
return (jsxRuntime.jsx(ModalBackdrop, { isFastOpen: isFastOpen, isVisible: isOpen, noShadow: noBackdropShadow, onClick: onDismissClick, children: isOpen ? (jsxRuntime.jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsxRuntime.jsx(reactComponents.Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) })) : null }));
|
|
177
|
-
}
|
|
157
|
+
};
|
|
178
158
|
Modal.displayName = "Modal";
|
|
179
159
|
|
|
180
160
|
/**
|
|
181
161
|
* The useModal component should be used to inform the user of important information.
|
|
182
|
-
|
|
162
|
+
*
|
|
183
163
|
* @param {UseModalProps} props - The props for the useModal hook
|
|
184
164
|
* @returns {*} useModal return
|
|
185
165
|
*/
|
|
186
166
|
const useModal = ({ closeOnOutsideClick, bindTo, closeOnEsc = true } = {}) => {
|
|
187
|
-
const modalRef =
|
|
167
|
+
const modalRef = react.useRef(null);
|
|
188
168
|
const { isOpen, togglePortal, openPortal, closePortal, Portal } = usePortal({
|
|
189
169
|
closeOnOutsideClick,
|
|
190
170
|
closeOnEsc,
|
|
@@ -202,7 +182,7 @@ const useModal = ({ closeOnOutsideClick, bindTo, closeOnEsc = true } = {}) => {
|
|
|
202
182
|
});
|
|
203
183
|
const PortalWrapper = (props) => (jsxRuntime.jsx(Portal, { children: jsxRuntime.jsx(Modal, { isOpen: isOpen, ref: modalRef, ...props }) }));
|
|
204
184
|
PortalWrapper.displayName = "Modal";
|
|
205
|
-
const WrappedModal =
|
|
185
|
+
const WrappedModal = react.useCallback(PortalWrapper, [Portal, isOpen]);
|
|
206
186
|
return {
|
|
207
187
|
Modal: WrappedModal,
|
|
208
188
|
toggleModal: (e) => {
|
package/index.esm.js
CHANGED
|
@@ -2,8 +2,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { Card } from '@trackunit/react-components';
|
|
4
4
|
import { useModalDialogContext } from '@trackunit/react-core-hooks';
|
|
5
|
-
import
|
|
6
|
-
import { useRef, useCallback } from 'react';
|
|
5
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
7
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
8
7
|
import usePortal from 'react-useportal';
|
|
9
8
|
|
|
@@ -113,12 +112,12 @@ const cvaModalBackdrop = cvaMerge([
|
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* The Backdrop for the modal.
|
|
116
|
-
|
|
115
|
+
*
|
|
117
116
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
118
|
-
* @returns {
|
|
117
|
+
* @returns {ReactElement} ModalBackdrop component
|
|
119
118
|
*/
|
|
120
119
|
const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) => {
|
|
121
|
-
const ref =
|
|
120
|
+
const ref = useRef(null);
|
|
122
121
|
return (jsx("div", { className: cvaModalBackdrop({ show: isVisible, noShadow, isFastOpen }), onMouseDown: e => {
|
|
123
122
|
// only react on click on backdrop - accessing first child to get around styled element element
|
|
124
123
|
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
@@ -131,13 +130,12 @@ const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) =
|
|
|
131
130
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
132
131
|
* - Modals interrupt a user's workflow by design.
|
|
133
132
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
134
|
-
|
|
135
133
|
*/
|
|
136
|
-
const Modal =
|
|
134
|
+
const Modal = ({ isOpen, children, dataTestId, className, containerClassName, role = "", noBackdropShadow = false, isFastOpen = false, onDismissClick = () => {
|
|
137
135
|
return;
|
|
138
|
-
},
|
|
136
|
+
}, ref, }) => {
|
|
139
137
|
const { openModal, closeModal } = useModalDialogContext();
|
|
140
|
-
|
|
138
|
+
useEffect(() => {
|
|
141
139
|
if (isOpen) {
|
|
142
140
|
openModal();
|
|
143
141
|
}
|
|
@@ -145,7 +143,7 @@ const Modal = React.forwardRef(({ isOpen, children, dataTestId, className, conta
|
|
|
145
143
|
closeModal();
|
|
146
144
|
}
|
|
147
145
|
}, [isOpen, openModal, closeModal]);
|
|
148
|
-
|
|
146
|
+
useEffect(() => {
|
|
149
147
|
return () => {
|
|
150
148
|
if (isOpen) {
|
|
151
149
|
closeModal();
|
|
@@ -154,12 +152,12 @@ const Modal = React.forwardRef(({ isOpen, children, dataTestId, className, conta
|
|
|
154
152
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
153
|
}, []); // Empty dependency array means this effect runs only on mount and unmount
|
|
156
154
|
return (jsx(ModalBackdrop, { isFastOpen: isFastOpen, isVisible: isOpen, noShadow: noBackdropShadow, onClick: onDismissClick, children: isOpen ? (jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsx(Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) })) : null }));
|
|
157
|
-
}
|
|
155
|
+
};
|
|
158
156
|
Modal.displayName = "Modal";
|
|
159
157
|
|
|
160
158
|
/**
|
|
161
159
|
* The useModal component should be used to inform the user of important information.
|
|
162
|
-
|
|
160
|
+
*
|
|
163
161
|
* @param {UseModalProps} props - The props for the useModal hook
|
|
164
162
|
* @returns {*} useModal return
|
|
165
163
|
*/
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-modal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.31",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"react": "
|
|
11
|
-
"react-useportal": "1.0.
|
|
12
|
-
"@trackunit/react-components": "1.4.
|
|
13
|
-
"@trackunit/react-core-hooks": "1.3.
|
|
14
|
-
"@trackunit/css-class-variance-utilities": "1.3.
|
|
15
|
-
"@trackunit/i18n-library-translation": "1.3.
|
|
10
|
+
"react": "19.0.0",
|
|
11
|
+
"react-useportal": "1.0.19",
|
|
12
|
+
"@trackunit/react-components": "1.4.28",
|
|
13
|
+
"@trackunit/react-core-hooks": "1.3.29",
|
|
14
|
+
"@trackunit/css-class-variance-utilities": "1.3.28",
|
|
15
|
+
"@trackunit/i18n-library-translation": "1.3.29"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"main": "./index.cjs.js",
|
package/src/modal/Modal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode, Ref } from "react";
|
|
3
3
|
export interface ModalProps extends CommonProps {
|
|
4
4
|
/**
|
|
5
5
|
* Whether modal is open or not.
|
|
@@ -12,7 +12,7 @@ export interface ModalProps extends CommonProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* Child elements to be rendered inside the modal.
|
|
14
14
|
*/
|
|
15
|
-
children:
|
|
15
|
+
children: ReactNode;
|
|
16
16
|
/**
|
|
17
17
|
* Test id to be applied to the modal.
|
|
18
18
|
*/
|
|
@@ -29,6 +29,10 @@ export interface ModalProps extends CommonProps {
|
|
|
29
29
|
* A custom class name to be attached to modal container
|
|
30
30
|
*/
|
|
31
31
|
containerClassName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* A ref for the component
|
|
34
|
+
*/
|
|
35
|
+
ref?: Ref<HTMLDivElement>;
|
|
32
36
|
/**
|
|
33
37
|
* Whether modal should open with a fast animation or not.
|
|
34
38
|
*/
|
|
@@ -38,6 +42,8 @@ export interface ModalProps extends CommonProps {
|
|
|
38
42
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
39
43
|
* - Modals interrupt a user's workflow by design.
|
|
40
44
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
41
|
-
|
|
42
45
|
*/
|
|
43
|
-
export declare const Modal:
|
|
46
|
+
export declare const Modal: {
|
|
47
|
+
({ isOpen, children, dataTestId, className, containerClassName, role, noBackdropShadow, isFastOpen, onDismissClick, ref, }: ModalProps): import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
displayName: string;
|
|
49
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
export interface ModalBackdropProps {
|
|
3
2
|
onClick: () => void;
|
|
4
3
|
children: React.ReactNode;
|
|
@@ -8,8 +7,8 @@ export interface ModalBackdropProps {
|
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
10
9
|
* The Backdrop for the modal.
|
|
11
|
-
|
|
10
|
+
*
|
|
12
11
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
13
|
-
* @returns {
|
|
12
|
+
* @returns {ReactElement} ModalBackdrop component
|
|
14
13
|
*/
|
|
15
14
|
export declare const ModalBackdrop: ({ children, isVisible, onClick, noShadow, isFastOpen }: ModalBackdropProps) => import("react/jsx-runtime").JSX.Element;
|
package/src/modal/useModal.d.ts
CHANGED