@trackunit/react-modal 1.3.200 → 1.3.202
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 +107 -79
- package/index.esm.js +108 -80
- package/package.json +9 -7
- package/src/modal/Modal.d.ts +11 -39
- package/src/modal/Modal.variants.d.ts +1 -5
- package/src/modal/ModalBackdrop.d.ts +3 -5
- package/src/modal/useModal.d.ts +40 -18
package/index.cjs.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
|
+
var react$1 = require('@floating-ui/react');
|
|
5
6
|
var reactComponents = require('@trackunit/react-components');
|
|
6
|
-
var
|
|
7
|
-
var react = require('react');
|
|
7
|
+
var uiDesignTokens = require('@trackunit/ui-design-tokens');
|
|
8
8
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
|
-
var
|
|
9
|
+
var react = require('react');
|
|
10
|
+
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
10
11
|
|
|
11
12
|
var defaultTranslations = {
|
|
12
13
|
|
|
@@ -83,34 +84,9 @@ const cvaModalBackdrop = cssClassVarianceUtilities.cvaMerge([
|
|
|
83
84
|
"invisible",
|
|
84
85
|
"opacity-0",
|
|
85
86
|
"transition-all",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
true: "",
|
|
90
|
-
false: "",
|
|
91
|
-
},
|
|
92
|
-
noShadow: {
|
|
93
|
-
true: "",
|
|
94
|
-
false: "bg-black/50",
|
|
95
|
-
},
|
|
96
|
-
isFastOpen: {
|
|
97
|
-
true: "",
|
|
98
|
-
false: "",
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
compoundVariants: [
|
|
102
|
-
{
|
|
103
|
-
show: true,
|
|
104
|
-
isFastOpen: true,
|
|
105
|
-
class: "animate-modal-fade-fast",
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
show: true,
|
|
109
|
-
isFastOpen: false,
|
|
110
|
-
class: "animate-modal-fade",
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
});
|
|
87
|
+
"bg-black/50",
|
|
88
|
+
"animate-modal-fade",
|
|
89
|
+
]);
|
|
114
90
|
|
|
115
91
|
/**
|
|
116
92
|
* The Backdrop for the modal.
|
|
@@ -118,10 +94,10 @@ const cvaModalBackdrop = cssClassVarianceUtilities.cvaMerge([
|
|
|
118
94
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
119
95
|
* @returns {ReactElement} ModalBackdrop component
|
|
120
96
|
*/
|
|
121
|
-
const ModalBackdrop = ({ children,
|
|
97
|
+
const ModalBackdrop = ({ children, onClick }) => {
|
|
122
98
|
const ref = react.useRef(null);
|
|
123
|
-
return (jsxRuntime.jsx("div", { className: cvaModalBackdrop(
|
|
124
|
-
// only react on click on backdrop - accessing first child to get around styled element
|
|
99
|
+
return (jsxRuntime.jsx("div", { className: cvaModalBackdrop(), onMouseDown: e => {
|
|
100
|
+
// only react on click on backdrop - accessing first child to get around styled element
|
|
125
101
|
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
126
102
|
onClick();
|
|
127
103
|
}
|
|
@@ -132,11 +108,52 @@ const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) =
|
|
|
132
108
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
133
109
|
* - Modals interrupt a user's workflow by design.
|
|
134
110
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
111
|
+
*
|
|
112
|
+
* - Modals should be used with the `useModal` hook.
|
|
113
|
+
* - const modal = useModal();
|
|
114
|
+
* - <Modal {...modal} />
|
|
115
|
+
*/
|
|
116
|
+
const Modal = ({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
|
|
117
|
+
const { rootElement, refs, floatingStyles, context, getFloatingProps } = floatingUi;
|
|
118
|
+
return (jsxRuntime.jsx(reactComponents.Portal, { root: rootElement, children: isOpen ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { context: context, children: jsxRuntime.jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: uiDesignTokens.zIndex.overlay }, ...getFloatingProps(), children: jsxRuntime.jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsxRuntime.jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsxRuntime.jsx(reactComponents.Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
|
|
119
|
+
};
|
|
120
|
+
Modal.displayName = "Modal";
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A hook to handle the state and configuration of Modal components.
|
|
124
|
+
*
|
|
125
|
+
* - `useModal` should be used with the `Modal` component.
|
|
126
|
+
* - const modal = useModal();
|
|
127
|
+
* - <Modal {...modal} />
|
|
135
128
|
*/
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
const useModal = (props = {}) => {
|
|
130
|
+
const [isOpen, setIsOpen] = react.useState(Boolean(props.isOpen));
|
|
131
|
+
return useModalInner({
|
|
132
|
+
...props,
|
|
133
|
+
setIsOpen,
|
|
134
|
+
isOpen: typeof props.isOpen === "boolean" ? props.isOpen : isOpen,
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
const useModalInner = ({ isOpen, setIsOpen, onOpenChange, rootElement, closeOnOutsideClick = true, closeOnEsc = true, onClose, onOpen, ref: customRef, }) => {
|
|
138
|
+
const ref = react.useRef(null);
|
|
139
139
|
const { openModal, closeModal } = reactCoreHooks.useModalDialogContext();
|
|
140
|
+
const { refs, floatingStyles, context } = react$1.useFloating({
|
|
141
|
+
open: isOpen,
|
|
142
|
+
onOpenChange: (bool, event, openChangeReason) => {
|
|
143
|
+
if (onOpenChange) {
|
|
144
|
+
return onOpenChange(bool, event, openChangeReason);
|
|
145
|
+
}
|
|
146
|
+
setIsOpen(bool);
|
|
147
|
+
},
|
|
148
|
+
whileElementsMounted: react$1.autoUpdate,
|
|
149
|
+
middleware: [react$1.shift()],
|
|
150
|
+
});
|
|
151
|
+
const dismiss = react$1.useDismiss(context, {
|
|
152
|
+
escapeKey: closeOnEsc,
|
|
153
|
+
outsidePress: closeOnOutsideClick,
|
|
154
|
+
});
|
|
155
|
+
const { getFloatingProps } = react$1.useInteractions([dismiss]);
|
|
156
|
+
// Handles closing and opening the modal outside of Iris apps/outside an iframe.
|
|
140
157
|
react.useEffect(() => {
|
|
141
158
|
if (isOpen) {
|
|
142
159
|
openModal();
|
|
@@ -149,51 +166,62 @@ const Modal = ({ isOpen, children, dataTestId, className, containerClassName, ro
|
|
|
149
166
|
closeModal();
|
|
150
167
|
};
|
|
151
168
|
}, [isOpen, openModal, closeModal]);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The useModal component should be used to inform the user of important information.
|
|
158
|
-
*
|
|
159
|
-
* @param {UseModalProps} props - The props for the useModal hook
|
|
160
|
-
* @returns {*} useModal return
|
|
161
|
-
*/
|
|
162
|
-
const useModal = ({ closeOnOutsideClick, bindTo, closeOnEsc = true } = {}) => {
|
|
163
|
-
const modalRef = react.useRef(null);
|
|
164
|
-
const { isOpen, togglePortal, openPortal, closePortal, Portal } = usePortal({
|
|
165
|
-
closeOnOutsideClick,
|
|
166
|
-
closeOnEsc,
|
|
167
|
-
onPortalClick: ({ target }) => {
|
|
168
|
-
if (!closeOnOutsideClick) {
|
|
169
|
-
return;
|
|
169
|
+
const open = react.useCallback((...args) => {
|
|
170
|
+
for (const arg of args) {
|
|
171
|
+
if (!arg) {
|
|
172
|
+
continue;
|
|
170
173
|
}
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
closePortal();
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
if ("preventDefault" in arg) {
|
|
176
|
+
arg.preventDefault();
|
|
175
177
|
}
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
if ("stopPropagation" in arg) {
|
|
180
|
+
arg.stopPropagation();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
onOpen?.(...args);
|
|
184
|
+
setIsOpen(true);
|
|
185
|
+
}, [onOpen, setIsOpen]);
|
|
186
|
+
const close = react.useCallback((...args) => {
|
|
187
|
+
onClose?.(...args);
|
|
188
|
+
setIsOpen(false);
|
|
189
|
+
}, [onClose, setIsOpen]);
|
|
190
|
+
const toggle = react.useCallback((...args) => {
|
|
191
|
+
if (isOpen) {
|
|
192
|
+
return close(...args);
|
|
193
|
+
}
|
|
194
|
+
return open(...args);
|
|
195
|
+
}, [close, isOpen, open]);
|
|
196
|
+
return react.useMemo(() => ({
|
|
197
|
+
isOpen,
|
|
198
|
+
closeOnOutsideClick,
|
|
199
|
+
toggle,
|
|
200
|
+
open,
|
|
201
|
+
close,
|
|
202
|
+
ref: customRef ?? ref,
|
|
203
|
+
// @ts-ignore TOnCloseArgs could be instantiated with a different subtype of constraint BaseUseModalActionArgs
|
|
204
|
+
onBackdropClick: () => (closeOnOutsideClick ? close() : null),
|
|
205
|
+
floatingUi: {
|
|
206
|
+
refs,
|
|
207
|
+
rootElement,
|
|
208
|
+
floatingStyles,
|
|
209
|
+
context,
|
|
210
|
+
getFloatingProps,
|
|
176
211
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
e?.stopPropagation();
|
|
191
|
-
e?.preventDefault();
|
|
192
|
-
closePortal(e);
|
|
193
|
-
},
|
|
194
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
195
|
-
isOpen: isOpen,
|
|
196
|
-
};
|
|
212
|
+
}), [
|
|
213
|
+
close,
|
|
214
|
+
closeOnOutsideClick,
|
|
215
|
+
context,
|
|
216
|
+
customRef,
|
|
217
|
+
floatingStyles,
|
|
218
|
+
getFloatingProps,
|
|
219
|
+
isOpen,
|
|
220
|
+
open,
|
|
221
|
+
refs,
|
|
222
|
+
rootElement,
|
|
223
|
+
toggle,
|
|
224
|
+
]);
|
|
197
225
|
};
|
|
198
226
|
|
|
199
227
|
/*
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { FloatingFocusManager, useFloating, autoUpdate, shift, useDismiss, useInteractions } from '@floating-ui/react';
|
|
4
|
+
import { Portal, Card } from '@trackunit/react-components';
|
|
5
|
+
import { zIndex } from '@trackunit/ui-design-tokens';
|
|
6
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
7
|
-
import
|
|
7
|
+
import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
8
|
+
import { useModalDialogContext } from '@trackunit/react-core-hooks';
|
|
8
9
|
|
|
9
10
|
var defaultTranslations = {
|
|
10
11
|
|
|
@@ -81,34 +82,9 @@ const cvaModalBackdrop = cvaMerge([
|
|
|
81
82
|
"invisible",
|
|
82
83
|
"opacity-0",
|
|
83
84
|
"transition-all",
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
true: "",
|
|
88
|
-
false: "",
|
|
89
|
-
},
|
|
90
|
-
noShadow: {
|
|
91
|
-
true: "",
|
|
92
|
-
false: "bg-black/50",
|
|
93
|
-
},
|
|
94
|
-
isFastOpen: {
|
|
95
|
-
true: "",
|
|
96
|
-
false: "",
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
compoundVariants: [
|
|
100
|
-
{
|
|
101
|
-
show: true,
|
|
102
|
-
isFastOpen: true,
|
|
103
|
-
class: "animate-modal-fade-fast",
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
show: true,
|
|
107
|
-
isFastOpen: false,
|
|
108
|
-
class: "animate-modal-fade",
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
});
|
|
85
|
+
"bg-black/50",
|
|
86
|
+
"animate-modal-fade",
|
|
87
|
+
]);
|
|
112
88
|
|
|
113
89
|
/**
|
|
114
90
|
* The Backdrop for the modal.
|
|
@@ -116,10 +92,10 @@ const cvaModalBackdrop = cvaMerge([
|
|
|
116
92
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
117
93
|
* @returns {ReactElement} ModalBackdrop component
|
|
118
94
|
*/
|
|
119
|
-
const ModalBackdrop = ({ children,
|
|
95
|
+
const ModalBackdrop = ({ children, onClick }) => {
|
|
120
96
|
const ref = useRef(null);
|
|
121
|
-
return (jsx("div", { className: cvaModalBackdrop(
|
|
122
|
-
// only react on click on backdrop - accessing first child to get around styled element
|
|
97
|
+
return (jsx("div", { className: cvaModalBackdrop(), onMouseDown: e => {
|
|
98
|
+
// only react on click on backdrop - accessing first child to get around styled element
|
|
123
99
|
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
124
100
|
onClick();
|
|
125
101
|
}
|
|
@@ -130,11 +106,52 @@ const ModalBackdrop = ({ children, isVisible, onClick, noShadow, isFastOpen }) =
|
|
|
130
106
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
131
107
|
* - Modals interrupt a user's workflow by design.
|
|
132
108
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
109
|
+
*
|
|
110
|
+
* - Modals should be used with the `useModal` hook.
|
|
111
|
+
* - const modal = useModal();
|
|
112
|
+
* - <Modal {...modal} />
|
|
133
113
|
*/
|
|
134
|
-
const Modal = ({ isOpen,
|
|
135
|
-
|
|
136
|
-
}, ref, })
|
|
114
|
+
const Modal = ({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
|
|
115
|
+
const { rootElement, refs, floatingStyles, context, getFloatingProps } = floatingUi;
|
|
116
|
+
return (jsx(Portal, { root: rootElement, children: isOpen ? (jsx(FloatingFocusManager, { context: context, children: jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: zIndex.overlay }, ...getFloatingProps(), children: jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsx(Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
|
|
117
|
+
};
|
|
118
|
+
Modal.displayName = "Modal";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A hook to handle the state and configuration of Modal components.
|
|
122
|
+
*
|
|
123
|
+
* - `useModal` should be used with the `Modal` component.
|
|
124
|
+
* - const modal = useModal();
|
|
125
|
+
* - <Modal {...modal} />
|
|
126
|
+
*/
|
|
127
|
+
const useModal = (props = {}) => {
|
|
128
|
+
const [isOpen, setIsOpen] = useState(Boolean(props.isOpen));
|
|
129
|
+
return useModalInner({
|
|
130
|
+
...props,
|
|
131
|
+
setIsOpen,
|
|
132
|
+
isOpen: typeof props.isOpen === "boolean" ? props.isOpen : isOpen,
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const useModalInner = ({ isOpen, setIsOpen, onOpenChange, rootElement, closeOnOutsideClick = true, closeOnEsc = true, onClose, onOpen, ref: customRef, }) => {
|
|
136
|
+
const ref = useRef(null);
|
|
137
137
|
const { openModal, closeModal } = useModalDialogContext();
|
|
138
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
139
|
+
open: isOpen,
|
|
140
|
+
onOpenChange: (bool, event, openChangeReason) => {
|
|
141
|
+
if (onOpenChange) {
|
|
142
|
+
return onOpenChange(bool, event, openChangeReason);
|
|
143
|
+
}
|
|
144
|
+
setIsOpen(bool);
|
|
145
|
+
},
|
|
146
|
+
whileElementsMounted: autoUpdate,
|
|
147
|
+
middleware: [shift()],
|
|
148
|
+
});
|
|
149
|
+
const dismiss = useDismiss(context, {
|
|
150
|
+
escapeKey: closeOnEsc,
|
|
151
|
+
outsidePress: closeOnOutsideClick,
|
|
152
|
+
});
|
|
153
|
+
const { getFloatingProps } = useInteractions([dismiss]);
|
|
154
|
+
// Handles closing and opening the modal outside of Iris apps/outside an iframe.
|
|
138
155
|
useEffect(() => {
|
|
139
156
|
if (isOpen) {
|
|
140
157
|
openModal();
|
|
@@ -147,51 +164,62 @@ const Modal = ({ isOpen, children, dataTestId, className, containerClassName, ro
|
|
|
147
164
|
closeModal();
|
|
148
165
|
};
|
|
149
166
|
}, [isOpen, openModal, closeModal]);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The useModal component should be used to inform the user of important information.
|
|
156
|
-
*
|
|
157
|
-
* @param {UseModalProps} props - The props for the useModal hook
|
|
158
|
-
* @returns {*} useModal return
|
|
159
|
-
*/
|
|
160
|
-
const useModal = ({ closeOnOutsideClick, bindTo, closeOnEsc = true } = {}) => {
|
|
161
|
-
const modalRef = useRef(null);
|
|
162
|
-
const { isOpen, togglePortal, openPortal, closePortal, Portal } = usePortal({
|
|
163
|
-
closeOnOutsideClick,
|
|
164
|
-
closeOnEsc,
|
|
165
|
-
onPortalClick: ({ target }) => {
|
|
166
|
-
if (!closeOnOutsideClick) {
|
|
167
|
-
return;
|
|
167
|
+
const open = useCallback((...args) => {
|
|
168
|
+
for (const arg of args) {
|
|
169
|
+
if (!arg) {
|
|
170
|
+
continue;
|
|
168
171
|
}
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
closePortal();
|
|
172
|
+
// @ts-ignore
|
|
173
|
+
if ("preventDefault" in arg) {
|
|
174
|
+
arg.preventDefault();
|
|
173
175
|
}
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
if ("stopPropagation" in arg) {
|
|
178
|
+
arg.stopPropagation();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
onOpen?.(...args);
|
|
182
|
+
setIsOpen(true);
|
|
183
|
+
}, [onOpen, setIsOpen]);
|
|
184
|
+
const close = useCallback((...args) => {
|
|
185
|
+
onClose?.(...args);
|
|
186
|
+
setIsOpen(false);
|
|
187
|
+
}, [onClose, setIsOpen]);
|
|
188
|
+
const toggle = useCallback((...args) => {
|
|
189
|
+
if (isOpen) {
|
|
190
|
+
return close(...args);
|
|
191
|
+
}
|
|
192
|
+
return open(...args);
|
|
193
|
+
}, [close, isOpen, open]);
|
|
194
|
+
return useMemo(() => ({
|
|
195
|
+
isOpen,
|
|
196
|
+
closeOnOutsideClick,
|
|
197
|
+
toggle,
|
|
198
|
+
open,
|
|
199
|
+
close,
|
|
200
|
+
ref: customRef ?? ref,
|
|
201
|
+
// @ts-ignore TOnCloseArgs could be instantiated with a different subtype of constraint BaseUseModalActionArgs
|
|
202
|
+
onBackdropClick: () => (closeOnOutsideClick ? close() : null),
|
|
203
|
+
floatingUi: {
|
|
204
|
+
refs,
|
|
205
|
+
rootElement,
|
|
206
|
+
floatingStyles,
|
|
207
|
+
context,
|
|
208
|
+
getFloatingProps,
|
|
174
209
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
e?.stopPropagation();
|
|
189
|
-
e?.preventDefault();
|
|
190
|
-
closePortal(e);
|
|
191
|
-
},
|
|
192
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
193
|
-
isOpen: isOpen,
|
|
194
|
-
};
|
|
210
|
+
}), [
|
|
211
|
+
close,
|
|
212
|
+
closeOnOutsideClick,
|
|
213
|
+
context,
|
|
214
|
+
customRef,
|
|
215
|
+
floatingStyles,
|
|
216
|
+
getFloatingProps,
|
|
217
|
+
isOpen,
|
|
218
|
+
open,
|
|
219
|
+
refs,
|
|
220
|
+
rootElement,
|
|
221
|
+
toggle,
|
|
222
|
+
]);
|
|
195
223
|
};
|
|
196
224
|
|
|
197
225
|
/*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-modal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.202",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"react": "19.0.0",
|
|
11
|
-
"react-
|
|
12
|
-
"@trackunit/react-
|
|
13
|
-
"@trackunit/
|
|
14
|
-
"@trackunit/
|
|
15
|
-
"@trackunit/
|
|
16
|
-
"@
|
|
11
|
+
"@trackunit/react-components": "1.4.185",
|
|
12
|
+
"@trackunit/react-core-hooks": "1.3.165",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.3.151",
|
|
14
|
+
"@trackunit/i18n-library-translation": "1.3.172",
|
|
15
|
+
"@trackunit/react-test-setup": "1.0.41",
|
|
16
|
+
"@floating-ui/react": "^0.26.25",
|
|
17
|
+
"@floating-ui/react-dom": "2.1.2",
|
|
18
|
+
"@trackunit/ui-design-tokens": "1.3.149"
|
|
17
19
|
},
|
|
18
20
|
"module": "./index.esm.js",
|
|
19
21
|
"main": "./index.cjs.js",
|
package/src/modal/Modal.d.ts
CHANGED
|
@@ -1,49 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
/**
|
|
5
|
-
* Whether modal is open or not.
|
|
6
|
-
*/
|
|
7
|
-
isOpen?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Function to be called when the modal is clicked outside of it.
|
|
10
|
-
*/
|
|
11
|
-
onDismissClick?: () => void;
|
|
12
|
-
/**
|
|
13
|
-
* Child elements to be rendered inside the modal.
|
|
14
|
-
*/
|
|
15
|
-
children: ReactNode;
|
|
16
|
-
/**
|
|
17
|
-
* Test id to be applied to the modal.
|
|
18
|
-
*/
|
|
19
|
-
dataTestId?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Aria role to be applied to element
|
|
22
|
-
*/
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { BaseUseModalActionArgs, UseModalReturnValue } from "./useModal";
|
|
3
|
+
export type ModalProps<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []> = {
|
|
23
4
|
role?: string;
|
|
24
|
-
|
|
25
|
-
* Whether modal has backdrop shadow or not
|
|
26
|
-
*/
|
|
27
|
-
noBackdropShadow?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* A custom class name to be attached to modal container
|
|
30
|
-
*/
|
|
5
|
+
className?: string;
|
|
31
6
|
containerClassName?: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
ref?: Ref<HTMLDivElement>;
|
|
36
|
-
/**
|
|
37
|
-
* Whether modal should open with a fast animation or not.
|
|
38
|
-
*/
|
|
39
|
-
isFastOpen?: boolean;
|
|
40
|
-
}
|
|
7
|
+
dataTestId?: string;
|
|
8
|
+
} & PropsWithChildren<UseModalReturnValue<TOnCloseFnArgs, TOnOpenFnArgs>>;
|
|
41
9
|
/**
|
|
42
10
|
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
43
11
|
* - Modals interrupt a user's workflow by design.
|
|
44
12
|
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
13
|
+
*
|
|
14
|
+
* - Modals should be used with the `useModal` hook.
|
|
15
|
+
* - const modal = useModal();
|
|
16
|
+
* - <Modal {...modal} />
|
|
45
17
|
*/
|
|
46
18
|
export declare const Modal: {
|
|
47
|
-
({ isOpen,
|
|
19
|
+
<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []>({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }: ModalProps<TOnCloseFnArgs, TOnOpenFnArgs>): import("react/jsx-runtime").JSX.Element;
|
|
48
20
|
displayName: string;
|
|
49
21
|
};
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
export declare const cvaModalContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
2
2
|
export declare const cvaModalCard: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
3
|
-
export declare const cvaModalBackdrop: (props?: (
|
|
4
|
-
show?: boolean | null | undefined;
|
|
5
|
-
noShadow?: boolean | null | undefined;
|
|
6
|
-
isFastOpen?: boolean | null | undefined;
|
|
7
|
-
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
3
|
+
export declare const cvaModalBackdrop: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
1
2
|
export interface ModalBackdropProps {
|
|
2
3
|
onClick: () => void;
|
|
3
|
-
children:
|
|
4
|
-
isVisible?: boolean;
|
|
5
|
-
noShadow?: boolean;
|
|
6
|
-
isFastOpen?: boolean;
|
|
4
|
+
children: ReactNode;
|
|
7
5
|
}
|
|
8
6
|
/**
|
|
9
7
|
* The Backdrop for the modal.
|
|
@@ -11,4 +9,4 @@ export interface ModalBackdropProps {
|
|
|
11
9
|
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
12
10
|
* @returns {ReactElement} ModalBackdrop component
|
|
13
11
|
*/
|
|
14
|
-
export declare const ModalBackdrop: ({ children,
|
|
12
|
+
export declare const ModalBackdrop: ({ children, onClick }: ModalBackdropProps) => import("react/jsx-runtime").JSX.Element;
|
package/src/modal/useModal.d.ts
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { UseFloatingOptions, UseFloatingReturn } from "@floating-ui/react";
|
|
2
|
+
import { UseFloatingReturn as UseFloatingReturn_Dom } from "@floating-ui/react-dom";
|
|
3
|
+
import { UseInteractionsReturn } from "@floating-ui/react/dist/floating-ui.react";
|
|
4
|
+
import { MouseEvent, Ref } from "react";
|
|
5
|
+
type BaseUseModalActionArg = string | number | boolean | null | undefined | [] | object | MouseEvent;
|
|
6
|
+
export type BaseUseModalActionArgs = {} & Array<BaseUseModalActionArg>;
|
|
7
|
+
type OnCloseFn<TOnCloseFnArgs extends BaseUseModalActionArgs> = (...args: TOnCloseFnArgs) => void;
|
|
8
|
+
type OnOpenFn<TOnOpenFnArgs extends BaseUseModalActionArgs> = (...args: TOnOpenFnArgs) => void;
|
|
9
|
+
export type UseModalProps<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []> = {
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
onClose?: OnCloseFn<TOnCloseFnArgs>;
|
|
12
|
+
onOpen?: OnOpenFn<TOnOpenFnArgs>;
|
|
13
|
+
onOpenChange?: UseFloatingOptions["onOpenChange"];
|
|
14
|
+
rootElement?: HTMLElement;
|
|
6
15
|
closeOnEsc?: boolean;
|
|
7
|
-
|
|
16
|
+
closeOnOutsideClick?: boolean;
|
|
17
|
+
ref?: Ref<HTMLDivElement>;
|
|
18
|
+
};
|
|
19
|
+
type FloatingUiProps = {
|
|
20
|
+
refs: UseFloatingReturn_Dom["refs"];
|
|
21
|
+
floatingStyles: UseFloatingReturn_Dom["floatingStyles"];
|
|
22
|
+
rootElement?: HTMLElement;
|
|
23
|
+
context: UseFloatingReturn["context"];
|
|
24
|
+
getFloatingProps: UseInteractionsReturn["getFloatingProps"];
|
|
25
|
+
};
|
|
26
|
+
export type UseModalReturnValue<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []> = {
|
|
27
|
+
ref: Ref<HTMLDivElement>;
|
|
28
|
+
isOpen: boolean;
|
|
29
|
+
closeOnOutsideClick: boolean;
|
|
30
|
+
onBackdropClick: () => void;
|
|
31
|
+
open: OnOpenFn<TOnOpenFnArgs>;
|
|
32
|
+
toggle: (...args: TOnOpenFnArgs | TOnCloseFnArgs) => void;
|
|
33
|
+
close: OnCloseFn<TOnCloseFnArgs>;
|
|
34
|
+
floatingUi: FloatingUiProps;
|
|
35
|
+
};
|
|
8
36
|
/**
|
|
9
|
-
*
|
|
37
|
+
* A hook to handle the state and configuration of Modal components.
|
|
10
38
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
39
|
+
* - `useModal` should be used with the `Modal` component.
|
|
40
|
+
* - const modal = useModal();
|
|
41
|
+
* - <Modal {...modal} />
|
|
13
42
|
*/
|
|
14
|
-
export declare const useModal:
|
|
15
|
-
|
|
16
|
-
displayName?: string;
|
|
17
|
-
};
|
|
18
|
-
toggleModal: (e?: BaseSyntheticEvent) => void;
|
|
19
|
-
openModal: (e?: BaseSyntheticEvent) => void;
|
|
20
|
-
closeModal: (e?: BaseSyntheticEvent) => void;
|
|
21
|
-
isOpen: boolean;
|
|
22
|
-
};
|
|
43
|
+
export declare const useModal: <TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []>(props?: UseModalProps<TOnCloseFnArgs, TOnOpenFnArgs>) => UseModalReturnValue<TOnCloseFnArgs, TOnOpenFnArgs>;
|
|
44
|
+
export {};
|