@trackunit/react-modal 0.0.1
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 +25 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +185 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +157 -0
- package/package.json +18 -0
- package/src/index.d.ts +1 -0
- package/src/modal/Modal.d.ts +35 -0
- package/src/modal/Modal.stories.d.ts +15 -0
- package/src/modal/Modal.variants.d.ts +6 -0
- package/src/modal/ModalBackdrop.d.ts +14 -0
- package/src/modal/index.d.ts +3 -0
- package/src/modal/useModal.d.ts +21 -0
- package/src/translation.d.ts +34 -0
- package/translation.cjs.js +7 -0
- package/translation.cjs10.js +7 -0
- package/translation.cjs11.js +7 -0
- package/translation.cjs12.js +7 -0
- package/translation.cjs13.js +7 -0
- package/translation.cjs14.js +7 -0
- package/translation.cjs15.js +7 -0
- package/translation.cjs16.js +7 -0
- package/translation.cjs17.js +7 -0
- package/translation.cjs2.js +7 -0
- package/translation.cjs3.js +7 -0
- package/translation.cjs4.js +7 -0
- package/translation.cjs5.js +7 -0
- package/translation.cjs6.js +7 -0
- package/translation.cjs7.js +7 -0
- package/translation.cjs8.js +7 -0
- package/translation.cjs9.js +7 -0
- package/translation.esm.js +5 -0
- package/translation.esm10.js +5 -0
- package/translation.esm11.js +5 -0
- package/translation.esm12.js +5 -0
- package/translation.esm13.js +5 -0
- package/translation.esm14.js +5 -0
- package/translation.esm15.js +5 -0
- package/translation.esm16.js +5 -0
- package/translation.esm17.js +5 -0
- package/translation.esm2.js +5 -0
- package/translation.esm3.js +5 -0
- package/translation.esm4.js +5 -0
- package/translation.esm5.js +5 -0
- package/translation.esm6.js +5 -0
- package/translation.esm7.js +5 -0
- package/translation.esm8.js +5 -0
- package/translation.esm9.js +5 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
> **⚠️ Beta**
|
|
2
|
+
>
|
|
3
|
+
> This is a beta version and subject to change without notice.
|
|
4
|
+
|
|
5
|
+
# Trackunit react-modal
|
|
6
|
+
|
|
7
|
+
The `@trackunit/react-modal` package is the home of Trackunits public react components used for...
|
|
8
|
+
|
|
9
|
+
This library is exposed publicly for use in the the Trackunit [Iris App SDK](https://www.npmjs.com/package/@trackunit/iris-app).
|
|
10
|
+
|
|
11
|
+
To browse all avaliable components visit our [Public Storybook](https://apps.iris.trackunit.com/storybook/).
|
|
12
|
+
|
|
13
|
+
For more info and a full guide on Iris App SDK Development, please visit our [Developer Hub](https://developers.trackunit.com/).
|
|
14
|
+
|
|
15
|
+
## Development
|
|
16
|
+
|
|
17
|
+
At this point this library is only developed by Trackunit Employees.
|
|
18
|
+
For development related information see the [development readme](https://github.com/Trackunit/manager/blob/master/libs/react/components/DEVELOPMENT.md).
|
|
19
|
+
|
|
20
|
+
## Trackunit
|
|
21
|
+
|
|
22
|
+
This package was developed by Trackunit ApS.
|
|
23
|
+
Trackunit is the leading SaaS-based IoT solution for the construction industry, offering an ecosystem of hardware, fleet management software & telematics.
|
|
24
|
+
|
|
25
|
+

|
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
|
+
var reactComponents = require('@trackunit/react-components');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
10
|
+
var usePortal = require('react-useportal');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n["default"] = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
|
+
var usePortal__default = /*#__PURE__*/_interopDefaultLegacy(usePortal);
|
|
34
|
+
|
|
35
|
+
var defaultTranslations = {
|
|
36
|
+
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** The translation namespace for this library */
|
|
40
|
+
const namespace = "react.react-modal";
|
|
41
|
+
/**
|
|
42
|
+
* The TranslationResource for this Library.
|
|
43
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
44
|
+
*
|
|
45
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
46
|
+
*/
|
|
47
|
+
const translations = {
|
|
48
|
+
ns: namespace,
|
|
49
|
+
default: defaultTranslations,
|
|
50
|
+
languages: {
|
|
51
|
+
de: () => Promise.resolve().then(function () { return require('./translation.cjs.js'); }),
|
|
52
|
+
da: () => Promise.resolve().then(function () { return require('./translation.cjs2.js'); }),
|
|
53
|
+
cs: () => Promise.resolve().then(function () { return require('./translation.cjs3.js'); }),
|
|
54
|
+
nl: () => Promise.resolve().then(function () { return require('./translation.cjs4.js'); }),
|
|
55
|
+
fr: () => Promise.resolve().then(function () { return require('./translation.cjs5.js'); }),
|
|
56
|
+
fi: () => Promise.resolve().then(function () { return require('./translation.cjs6.js'); }),
|
|
57
|
+
hu: () => Promise.resolve().then(function () { return require('./translation.cjs7.js'); }),
|
|
58
|
+
it: () => Promise.resolve().then(function () { return require('./translation.cjs8.js'); }),
|
|
59
|
+
nb: () => Promise.resolve().then(function () { return require('./translation.cjs9.js'); }),
|
|
60
|
+
pl: () => Promise.resolve().then(function () { return require('./translation.cjs10.js'); }),
|
|
61
|
+
pt: () => Promise.resolve().then(function () { return require('./translation.cjs11.js'); }),
|
|
62
|
+
ru: () => Promise.resolve().then(function () { return require('./translation.cjs12.js'); }),
|
|
63
|
+
ro: () => Promise.resolve().then(function () { return require('./translation.cjs13.js'); }),
|
|
64
|
+
es: () => Promise.resolve().then(function () { return require('./translation.cjs14.js'); }),
|
|
65
|
+
sv: () => Promise.resolve().then(function () { return require('./translation.cjs15.js'); }),
|
|
66
|
+
ja: () => Promise.resolve().then(function () { return require('./translation.cjs16.js'); }),
|
|
67
|
+
th: () => Promise.resolve().then(function () { return require('./translation.cjs17.js'); }),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Registers the translations for this library
|
|
72
|
+
*/
|
|
73
|
+
const setupLibraryTranslations = () => {
|
|
74
|
+
i18nLibraryTranslation.registerTranslations(translations);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const cvaModalContainer = cssClassVarianceUtilities.cvaMerge(["h-full", "w-full", "flex", "items-center"]);
|
|
78
|
+
const cvaModalCard = cssClassVarianceUtilities.cvaMerge([
|
|
79
|
+
"m-auto",
|
|
80
|
+
"shadow-2xl",
|
|
81
|
+
"w-[calc(100%-1rem)]",
|
|
82
|
+
"max-h-[min(100%-1rem,30%+600px)]",
|
|
83
|
+
"max-w-[min(100%-1rem,30%+600px)]",
|
|
84
|
+
]);
|
|
85
|
+
const cvaModalBackdrop = cssClassVarianceUtilities.cvaMerge([
|
|
86
|
+
"flex",
|
|
87
|
+
"justify-center",
|
|
88
|
+
"items-center",
|
|
89
|
+
"fixed",
|
|
90
|
+
"top-0",
|
|
91
|
+
"left-0",
|
|
92
|
+
"w-full",
|
|
93
|
+
"h-full",
|
|
94
|
+
"z-20",
|
|
95
|
+
"invisible",
|
|
96
|
+
"opacity-0",
|
|
97
|
+
"transition-all",
|
|
98
|
+
], {
|
|
99
|
+
variants: {
|
|
100
|
+
show: {
|
|
101
|
+
true: "animate-modal-fade",
|
|
102
|
+
false: "",
|
|
103
|
+
},
|
|
104
|
+
noShadow: {
|
|
105
|
+
true: "",
|
|
106
|
+
false: "bg-black/50",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The Backdrop for the modal.
|
|
113
|
+
|
|
114
|
+
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
115
|
+
* @returns {JSX.Element} ModalBackdrop component
|
|
116
|
+
*/
|
|
117
|
+
const ModalBackdrop = ({ children, isVisible, onClick, noShadow }) => {
|
|
118
|
+
const ref = React__namespace.useRef(null);
|
|
119
|
+
return (jsxRuntime.jsx("div", { className: cvaModalBackdrop({ show: isVisible, noShadow }), onMouseDown: e => {
|
|
120
|
+
// only react on click on backdrop - accessing first child to get around styled element element
|
|
121
|
+
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
122
|
+
onClick();
|
|
123
|
+
}
|
|
124
|
+
}, ref: ref, children: children }));
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
129
|
+
* - Modals interrupt a user's workflow by design.
|
|
130
|
+
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
131
|
+
|
|
132
|
+
*/
|
|
133
|
+
const Modal = React__namespace.forwardRef(({ isOpen, children, dataTestId, className, role = "", noBackdropShadow = false, onDismissClick = () => {
|
|
134
|
+
return;
|
|
135
|
+
}, }, ref) => {
|
|
136
|
+
return (jsxRuntime.jsx(ModalBackdrop, { isVisible: isOpen, noShadow: noBackdropShadow, onClick: onDismissClick, children: isOpen ? (jsxRuntime.jsx("div", { className: cvaModalContainer(), ref: ref, role: role, children: jsxRuntime.jsx(reactComponents.Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) })) : null }));
|
|
137
|
+
});
|
|
138
|
+
Modal.displayName = "Modal";
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The useModal component should be used to inform the user of important information.
|
|
142
|
+
|
|
143
|
+
* @param {UseModalProps} props - The props for the useModal hook
|
|
144
|
+
* @returns {*} useModal return
|
|
145
|
+
*/
|
|
146
|
+
const useModal = ({ closeOnOutsideClick } = {}) => {
|
|
147
|
+
const modalRef = React.useRef(null);
|
|
148
|
+
const { isOpen, togglePortal, openPortal, closePortal, Portal } = usePortal__default["default"]({
|
|
149
|
+
closeOnOutsideClick,
|
|
150
|
+
onPortalClick: ({ target }) => {
|
|
151
|
+
var _a;
|
|
152
|
+
if (!closeOnOutsideClick) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
156
|
+
const clickingOutsideModal = !((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.contains(target));
|
|
157
|
+
if (clickingOutsideModal) {
|
|
158
|
+
closePortal();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const PortalWrapper = (props) => (jsxRuntime.jsx(Portal, { children: jsxRuntime.jsx(Modal, Object.assign({ isOpen: isOpen, ref: modalRef }, props)) }));
|
|
163
|
+
PortalWrapper.displayName = "Modal";
|
|
164
|
+
const WrappedModal = React.useCallback(PortalWrapper, [Portal, isOpen]);
|
|
165
|
+
return {
|
|
166
|
+
Modal: WrappedModal,
|
|
167
|
+
toggleModal: togglePortal,
|
|
168
|
+
openModal: openPortal,
|
|
169
|
+
closeModal: closePortal,
|
|
170
|
+
isOpen,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* ----------------------------
|
|
176
|
+
* | SETUP TRANSLATIONS START |
|
|
177
|
+
* ----------------------------
|
|
178
|
+
* This import and function call is needed to register translations for this library.
|
|
179
|
+
* Do not remove this if this library has translations.
|
|
180
|
+
*/
|
|
181
|
+
setupLibraryTranslations();
|
|
182
|
+
|
|
183
|
+
exports.Modal = Modal;
|
|
184
|
+
exports.ModalBackdrop = ModalBackdrop;
|
|
185
|
+
exports.useModal = useModal;
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
|
+
import { Card } from '@trackunit/react-components';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useRef, useCallback } from 'react';
|
|
6
|
+
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
7
|
+
import usePortal from 'react-useportal';
|
|
8
|
+
|
|
9
|
+
var defaultTranslations = {
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** The translation namespace for this library */
|
|
14
|
+
const namespace = "react.react-modal";
|
|
15
|
+
/**
|
|
16
|
+
* The TranslationResource for this Library.
|
|
17
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
18
|
+
*
|
|
19
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
20
|
+
*/
|
|
21
|
+
const translations = {
|
|
22
|
+
ns: namespace,
|
|
23
|
+
default: defaultTranslations,
|
|
24
|
+
languages: {
|
|
25
|
+
de: () => import('./translation.esm.js'),
|
|
26
|
+
da: () => import('./translation.esm2.js'),
|
|
27
|
+
cs: () => import('./translation.esm3.js'),
|
|
28
|
+
nl: () => import('./translation.esm4.js'),
|
|
29
|
+
fr: () => import('./translation.esm5.js'),
|
|
30
|
+
fi: () => import('./translation.esm6.js'),
|
|
31
|
+
hu: () => import('./translation.esm7.js'),
|
|
32
|
+
it: () => import('./translation.esm8.js'),
|
|
33
|
+
nb: () => import('./translation.esm9.js'),
|
|
34
|
+
pl: () => import('./translation.esm10.js'),
|
|
35
|
+
pt: () => import('./translation.esm11.js'),
|
|
36
|
+
ru: () => import('./translation.esm12.js'),
|
|
37
|
+
ro: () => import('./translation.esm13.js'),
|
|
38
|
+
es: () => import('./translation.esm14.js'),
|
|
39
|
+
sv: () => import('./translation.esm15.js'),
|
|
40
|
+
ja: () => import('./translation.esm16.js'),
|
|
41
|
+
th: () => import('./translation.esm17.js'),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Registers the translations for this library
|
|
46
|
+
*/
|
|
47
|
+
const setupLibraryTranslations = () => {
|
|
48
|
+
registerTranslations(translations);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const cvaModalContainer = cvaMerge(["h-full", "w-full", "flex", "items-center"]);
|
|
52
|
+
const cvaModalCard = cvaMerge([
|
|
53
|
+
"m-auto",
|
|
54
|
+
"shadow-2xl",
|
|
55
|
+
"w-[calc(100%-1rem)]",
|
|
56
|
+
"max-h-[min(100%-1rem,30%+600px)]",
|
|
57
|
+
"max-w-[min(100%-1rem,30%+600px)]",
|
|
58
|
+
]);
|
|
59
|
+
const cvaModalBackdrop = cvaMerge([
|
|
60
|
+
"flex",
|
|
61
|
+
"justify-center",
|
|
62
|
+
"items-center",
|
|
63
|
+
"fixed",
|
|
64
|
+
"top-0",
|
|
65
|
+
"left-0",
|
|
66
|
+
"w-full",
|
|
67
|
+
"h-full",
|
|
68
|
+
"z-20",
|
|
69
|
+
"invisible",
|
|
70
|
+
"opacity-0",
|
|
71
|
+
"transition-all",
|
|
72
|
+
], {
|
|
73
|
+
variants: {
|
|
74
|
+
show: {
|
|
75
|
+
true: "animate-modal-fade",
|
|
76
|
+
false: "",
|
|
77
|
+
},
|
|
78
|
+
noShadow: {
|
|
79
|
+
true: "",
|
|
80
|
+
false: "bg-black/50",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The Backdrop for the modal.
|
|
87
|
+
|
|
88
|
+
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
89
|
+
* @returns {JSX.Element} ModalBackdrop component
|
|
90
|
+
*/
|
|
91
|
+
const ModalBackdrop = ({ children, isVisible, onClick, noShadow }) => {
|
|
92
|
+
const ref = React.useRef(null);
|
|
93
|
+
return (jsx("div", { className: cvaModalBackdrop({ show: isVisible, noShadow }), onMouseDown: e => {
|
|
94
|
+
// only react on click on backdrop - accessing first child to get around styled element element
|
|
95
|
+
if (ref.current !== null && e.target === ref.current.children[0]) {
|
|
96
|
+
onClick();
|
|
97
|
+
}
|
|
98
|
+
}, ref: ref, children: children }));
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
103
|
+
* - Modals interrupt a user's workflow by design.
|
|
104
|
+
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
105
|
+
|
|
106
|
+
*/
|
|
107
|
+
const Modal = React.forwardRef(({ isOpen, children, dataTestId, className, role = "", noBackdropShadow = false, onDismissClick = () => {
|
|
108
|
+
return;
|
|
109
|
+
}, }, ref) => {
|
|
110
|
+
return (jsx(ModalBackdrop, { isVisible: isOpen, noShadow: noBackdropShadow, onClick: onDismissClick, children: isOpen ? (jsx("div", { className: cvaModalContainer(), ref: ref, role: role, children: jsx(Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) })) : null }));
|
|
111
|
+
});
|
|
112
|
+
Modal.displayName = "Modal";
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The useModal component should be used to inform the user of important information.
|
|
116
|
+
|
|
117
|
+
* @param {UseModalProps} props - The props for the useModal hook
|
|
118
|
+
* @returns {*} useModal return
|
|
119
|
+
*/
|
|
120
|
+
const useModal = ({ closeOnOutsideClick } = {}) => {
|
|
121
|
+
const modalRef = useRef(null);
|
|
122
|
+
const { isOpen, togglePortal, openPortal, closePortal, Portal } = usePortal({
|
|
123
|
+
closeOnOutsideClick,
|
|
124
|
+
onPortalClick: ({ target }) => {
|
|
125
|
+
var _a;
|
|
126
|
+
if (!closeOnOutsideClick) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
130
|
+
const clickingOutsideModal = !((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.contains(target));
|
|
131
|
+
if (clickingOutsideModal) {
|
|
132
|
+
closePortal();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const PortalWrapper = (props) => (jsx(Portal, { children: jsx(Modal, Object.assign({ isOpen: isOpen, ref: modalRef }, props)) }));
|
|
137
|
+
PortalWrapper.displayName = "Modal";
|
|
138
|
+
const WrappedModal = useCallback(PortalWrapper, [Portal, isOpen]);
|
|
139
|
+
return {
|
|
140
|
+
Modal: WrappedModal,
|
|
141
|
+
toggleModal: togglePortal,
|
|
142
|
+
openModal: openPortal,
|
|
143
|
+
closeModal: closePortal,
|
|
144
|
+
isOpen,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* ----------------------------
|
|
150
|
+
* | SETUP TRANSLATIONS START |
|
|
151
|
+
* ----------------------------
|
|
152
|
+
* This import and function call is needed to register translations for this library.
|
|
153
|
+
* Do not remove this if this library has translations.
|
|
154
|
+
*/
|
|
155
|
+
setupLibraryTranslations();
|
|
156
|
+
|
|
157
|
+
export { Modal, ModalBackdrop, useModal };
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trackunit/react-modal",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"repository": "https://github.com/Trackunit/manager",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20.x"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@trackunit/i18n-library-translation": "*",
|
|
11
|
+
"@trackunit/react-components": "*",
|
|
12
|
+
"react": "^18.2.0",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "*",
|
|
14
|
+
"react-useportal": "1.0.18"
|
|
15
|
+
},
|
|
16
|
+
"module": "./index.esm.js",
|
|
17
|
+
"main": "./index.cjs.js"
|
|
18
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./modal";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface ModalProps extends CommonProps {
|
|
4
|
+
/**
|
|
5
|
+
* Whether modal is open or not.
|
|
6
|
+
*/
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether modal should be closed when clicked outside of it.
|
|
10
|
+
*/
|
|
11
|
+
onDismissClick?: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Child elements to be rendered inside the modal.
|
|
14
|
+
*/
|
|
15
|
+
children: React.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
|
+
*/
|
|
23
|
+
role?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether modal has backdrop shadow or not
|
|
26
|
+
*/
|
|
27
|
+
noBackdropShadow?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* - Modals are used to present critical information or request user input needed to complete a user's workflow.
|
|
31
|
+
* - Modals interrupt a user's workflow by design.
|
|
32
|
+
* - The modal component provides a foundation for creating dialogs, lightboxes, etc.
|
|
33
|
+
|
|
34
|
+
*/
|
|
35
|
+
export declare const Modal: React.ForwardRefExoticComponent<ModalProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import { Modal, ModalProps } from "./Modal";
|
|
4
|
+
type Story = StoryObj<typeof Modal>;
|
|
5
|
+
declare const meta: Meta<typeof Modal>;
|
|
6
|
+
export default meta;
|
|
7
|
+
export declare const packageName: () => JSX.Element;
|
|
8
|
+
export declare const OverviewTemplate: (props: ModalProps) => JSX.Element;
|
|
9
|
+
export declare const Default: Story;
|
|
10
|
+
export declare const IncorrectUsageErrorModal: (closeOnOutsideClick: true) => JSX.Element;
|
|
11
|
+
export declare const CorrectUsagePrimaryAction: (closeOnOutsideClick: true) => JSX.Element;
|
|
12
|
+
export declare const IncorrectUsageLongText: (closeOnOutsideClick: true) => JSX.Element;
|
|
13
|
+
export declare const CorrectUsageImportantAction: (closeOnOutsideClick: true) => JSX.Element;
|
|
14
|
+
export declare const IncorrectAccessibility: (closeOnOutsideClick: false) => JSX.Element;
|
|
15
|
+
export declare const CorrectAccessibility: (closeOnOutsideClick: true) => JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const cvaModalContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
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
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ModalBackdropProps {
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
isVisible?: boolean;
|
|
6
|
+
noShadow?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The Backdrop for the modal.
|
|
10
|
+
|
|
11
|
+
* @param {ModalBackdropProps} props - The props for the ModalBackdrop component
|
|
12
|
+
* @returns {JSX.Element} ModalBackdrop component
|
|
13
|
+
*/
|
|
14
|
+
export declare const ModalBackdrop: ({ children, isVisible, onClick, noShadow }: ModalBackdropProps) => JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModalProps } from "./Modal";
|
|
3
|
+
export interface UseModalProps {
|
|
4
|
+
closeOnOutsideClick?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The useModal component should be used to inform the user of important information.
|
|
8
|
+
|
|
9
|
+
* @param {UseModalProps} props - The props for the useModal hook
|
|
10
|
+
* @returns {*} useModal return
|
|
11
|
+
*/
|
|
12
|
+
export declare const useModal: ({ closeOnOutsideClick }?: UseModalProps) => {
|
|
13
|
+
Modal: {
|
|
14
|
+
(props: ModalProps): JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
toggleModal: any;
|
|
18
|
+
openModal: any;
|
|
19
|
+
closeModal: any;
|
|
20
|
+
isOpen: any;
|
|
21
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { NamespaceTransProps, TransForLibs, TranslationResource } from "@trackunit/i18n-library-translation";
|
|
3
|
+
import defaultTranslations from "./locales/en/translation.json";
|
|
4
|
+
/** A type for all available translation keys in this library */
|
|
5
|
+
export type TranslationKeys = keyof typeof defaultTranslations;
|
|
6
|
+
/** The translation namespace for this library */
|
|
7
|
+
export declare const namespace = "react.react-modal";
|
|
8
|
+
/**
|
|
9
|
+
* The TranslationResource for this Library.
|
|
10
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
11
|
+
*
|
|
12
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
13
|
+
*/
|
|
14
|
+
export declare const translations: TranslationResource<TranslationKeys>;
|
|
15
|
+
/**
|
|
16
|
+
* Local useTranslation for this specific library
|
|
17
|
+
*/
|
|
18
|
+
export declare const useTranslation: () => [TransForLibs<never>, import("i18next").i18n, boolean] & {
|
|
19
|
+
t: TransForLibs<never>;
|
|
20
|
+
i18n: import("i18next").i18n;
|
|
21
|
+
ready: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Type of the t function for the local useTranslation for this specific library
|
|
25
|
+
*/
|
|
26
|
+
export type TranslationFunction = TransForLibs<TranslationKeys>;
|
|
27
|
+
/**
|
|
28
|
+
* Trans for this specific library.
|
|
29
|
+
*/
|
|
30
|
+
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* Registers the translations for this library
|
|
33
|
+
*/
|
|
34
|
+
export declare const setupLibraryTranslations: () => void;
|