@trackunit/react-compound-components 1.0.24 → 1.0.26
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
5
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
6
|
-
var
|
|
6
|
+
var react = require('react');
|
|
7
7
|
var reactComponents = require('@trackunit/react-components');
|
|
8
8
|
var reactModal = require('@trackunit/react-modal');
|
|
9
9
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
@@ -12,25 +12,6 @@ var tailwindMerge = require('tailwind-merge');
|
|
|
12
12
|
var dateAndTimeUtils = require('@trackunit/date-and-time-utils');
|
|
13
13
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
14
14
|
|
|
15
|
-
function _interopNamespaceDefault(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__*/_interopNamespaceDefault(React);
|
|
33
|
-
|
|
34
15
|
var defaultTranslations = {
|
|
35
16
|
"confirmationDialog.default.message": "Are you certain that you wish to proceed with this course of action?",
|
|
36
17
|
"confirmationDialog.default.primarybutton": "Confirm",
|
|
@@ -91,20 +72,20 @@ const ConfirmationDialogModal = ({ isOpen, title, handleDismiss, message, handle
|
|
|
91
72
|
*
|
|
92
73
|
*/
|
|
93
74
|
const ConfirmationDialogContextProvider = ({ children }) => {
|
|
94
|
-
const [isOpen, setIsOpen] =
|
|
75
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
95
76
|
const [t] = useTranslation();
|
|
96
|
-
const [resolveAction, setResolveAction] =
|
|
97
|
-
const [confirmationDialogProps, setConfirmationDialogProps] =
|
|
77
|
+
const [resolveAction, setResolveAction] = react.useState(null);
|
|
78
|
+
const [confirmationDialogProps, setConfirmationDialogProps] = react.useState({
|
|
98
79
|
title: t("confirmationDialog.default.title"),
|
|
99
80
|
primaryActionType: "primary",
|
|
100
81
|
primaryActionLabel: t("confirmationDialog.default.primarybutton"),
|
|
101
82
|
secondaryActionLabel: t("confirmationDialog.default.secondarybutton"),
|
|
102
83
|
message: t("confirmationDialog.default.message"),
|
|
103
84
|
});
|
|
104
|
-
const closeModal =
|
|
85
|
+
const closeModal = react.useCallback(() => {
|
|
105
86
|
setIsOpen(false);
|
|
106
87
|
}, []);
|
|
107
|
-
const confirmationDialogModalProps =
|
|
88
|
+
const confirmationDialogModalProps = react.useMemo(() => ({
|
|
108
89
|
...confirmationDialogProps,
|
|
109
90
|
isOpen,
|
|
110
91
|
handleDismiss: () => {
|
|
@@ -120,14 +101,14 @@ const ConfirmationDialogContextProvider = ({ children }) => {
|
|
|
120
101
|
closeModal();
|
|
121
102
|
},
|
|
122
103
|
}), [confirmationDialogProps, isOpen, resolveAction, closeModal]);
|
|
123
|
-
const confirm =
|
|
104
|
+
const confirm = react.useCallback(async (props) => {
|
|
124
105
|
setConfirmationDialogProps(prev => ({ ...prev, ...props }));
|
|
125
106
|
setIsOpen(true);
|
|
126
107
|
return new Promise(resolve => {
|
|
127
108
|
setResolveAction(() => resolve);
|
|
128
109
|
});
|
|
129
110
|
}, []);
|
|
130
|
-
const value =
|
|
111
|
+
const value = react.useMemo(() => ({ confirm }), [confirm]);
|
|
131
112
|
return (jsxRuntime.jsxs(reactCoreHooks.ConfirmationDialogProvider, { value: value, children: [children, resolveAction ? jsxRuntime.jsx(ConfirmationDialogModal, { ...confirmationDialogModalProps }) : null] }));
|
|
132
113
|
};
|
|
133
114
|
|
|
@@ -189,13 +170,13 @@ const titleStyle = "absolute top-3 left-1/2 transform -translate-x-1/2 text-whit
|
|
|
189
170
|
*/
|
|
190
171
|
const ImageCollection = (props) => {
|
|
191
172
|
const { imagesData, actions, emptyPlaceholderActionLabel, additionalItemClassName, uploading } = props;
|
|
192
|
-
const [openImageId, setOpenImageId] =
|
|
193
|
-
const [isDeleting, setIsDeleting] =
|
|
173
|
+
const [openImageId, setOpenImageId] = react.useState(imagesData[0]?.id);
|
|
174
|
+
const [isDeleting, setIsDeleting] = react.useState(false);
|
|
194
175
|
const { isLg } = reactComponents.useViewportBreakpoints();
|
|
195
|
-
const fileInputRef =
|
|
196
|
-
const imageGalleryRef =
|
|
197
|
-
const uploadButton =
|
|
198
|
-
const items =
|
|
176
|
+
const fileInputRef = react.useRef(null);
|
|
177
|
+
const imageGalleryRef = react.useRef(null);
|
|
178
|
+
const uploadButton = react.useMemo(() => actions?.upload ? (jsxRuntime.jsx("div", { className: "flex justify-end", children: jsxRuntime.jsx(reactComponents.Button, { loading: uploading, onClick: () => fileInputRef.current?.click(), children: actions.upload.label }) })) : null, [actions?.upload, uploading]);
|
|
179
|
+
const items = react.useMemo(() => imagesData.map(image => ({
|
|
199
180
|
id: image.id,
|
|
200
181
|
original: createOriginalUrl(image.id),
|
|
201
182
|
thumbnail: createThumbnailUrl(image.id),
|
|
@@ -203,12 +184,12 @@ const ImageCollection = (props) => {
|
|
|
203
184
|
name: image.name,
|
|
204
185
|
timestamp: dateAndTimeUtils.formatDateUtil(new Date(image.timestamp), { dateFormat: "medium", timeFormat: "medium" }),
|
|
205
186
|
})), [imagesData]);
|
|
206
|
-
|
|
187
|
+
react.useEffect(() => {
|
|
207
188
|
if ((!openImageId || !imagesData.map(x => x.id).includes(openImageId)) && imagesData.length > 0) {
|
|
208
189
|
setOpenImageId(imagesData[0]?.id);
|
|
209
190
|
}
|
|
210
191
|
}, [imagesData, openImageId]);
|
|
211
|
-
const onRemove =
|
|
192
|
+
const onRemove = react.useCallback(async () => {
|
|
212
193
|
if (!(actions?.remove?.onRemove && openImageId)) {
|
|
213
194
|
return;
|
|
214
195
|
}
|
package/index.esm.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { ConfirmationDialogProvider } from '@trackunit/react-core-hooks';
|
|
4
|
-
import
|
|
5
|
-
import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
4
|
+
import { useState, useCallback, useMemo, useRef, useEffect } from 'react';
|
|
6
5
|
import { Card, CardHeader, CardBody, CardFooter, Button, useViewportBreakpoints, Icon, Spinner } from '@trackunit/react-components';
|
|
7
6
|
import { Modal } from '@trackunit/react-modal';
|
|
8
7
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
@@ -81,10 +80,10 @@ const ConfirmationDialogContextProvider = ({ children }) => {
|
|
|
81
80
|
secondaryActionLabel: t("confirmationDialog.default.secondarybutton"),
|
|
82
81
|
message: t("confirmationDialog.default.message"),
|
|
83
82
|
});
|
|
84
|
-
const closeModal =
|
|
83
|
+
const closeModal = useCallback(() => {
|
|
85
84
|
setIsOpen(false);
|
|
86
85
|
}, []);
|
|
87
|
-
const confirmationDialogModalProps =
|
|
86
|
+
const confirmationDialogModalProps = useMemo(() => ({
|
|
88
87
|
...confirmationDialogProps,
|
|
89
88
|
isOpen,
|
|
90
89
|
handleDismiss: () => {
|
|
@@ -100,14 +99,14 @@ const ConfirmationDialogContextProvider = ({ children }) => {
|
|
|
100
99
|
closeModal();
|
|
101
100
|
},
|
|
102
101
|
}), [confirmationDialogProps, isOpen, resolveAction, closeModal]);
|
|
103
|
-
const confirm =
|
|
102
|
+
const confirm = useCallback(async (props) => {
|
|
104
103
|
setConfirmationDialogProps(prev => ({ ...prev, ...props }));
|
|
105
104
|
setIsOpen(true);
|
|
106
105
|
return new Promise(resolve => {
|
|
107
106
|
setResolveAction(() => resolve);
|
|
108
107
|
});
|
|
109
108
|
}, []);
|
|
110
|
-
const value =
|
|
109
|
+
const value = useMemo(() => ({ confirm }), [confirm]);
|
|
111
110
|
return (jsxs(ConfirmationDialogProvider, { value: value, children: [children, resolveAction ? jsx(ConfirmationDialogModal, { ...confirmationDialogModalProps }) : null] }));
|
|
112
111
|
};
|
|
113
112
|
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-compound-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"react": "18.3.1",
|
|
8
8
|
"tailwind-merge": "^2.0.0",
|
|
9
9
|
"react-image-gallery": "1.3.0",
|
|
10
|
-
"@trackunit/react-core-contexts-api": "
|
|
11
|
-
"@trackunit/react-core-hooks": "
|
|
12
|
-
"@trackunit/react-components": "
|
|
13
|
-
"@trackunit/react-modal": "
|
|
14
|
-
"@trackunit/css-class-variance-utilities": "
|
|
15
|
-
"@trackunit/date-and-time-utils": "
|
|
16
|
-
"@trackunit/react-form-components": "
|
|
17
|
-
"@trackunit/i18n-library-translation": "
|
|
10
|
+
"@trackunit/react-core-contexts-api": "1.0.9",
|
|
11
|
+
"@trackunit/react-core-hooks": "1.0.9",
|
|
12
|
+
"@trackunit/react-components": "1.1.7",
|
|
13
|
+
"@trackunit/react-modal": "1.0.25",
|
|
14
|
+
"@trackunit/css-class-variance-utilities": "1.0.4",
|
|
15
|
+
"@trackunit/date-and-time-utils": "1.0.4",
|
|
16
|
+
"@trackunit/react-form-components": "1.0.25",
|
|
17
|
+
"@trackunit/i18n-library-translation": "1.0.13"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=20.x",
|