tycho-components 0.15.6 → 0.15.8
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.
|
@@ -9,6 +9,8 @@ export type AppDropzoneBodyProps = {
|
|
|
9
9
|
keepName?: boolean;
|
|
10
10
|
/** When false, the confirm button is hidden (e.g. when used inside modal with its own confirm) */
|
|
11
11
|
showConfirmButton?: boolean;
|
|
12
|
+
/** When true, image preview is not rendered and filename message is shown instead */
|
|
13
|
+
disablePreview?: boolean;
|
|
12
14
|
};
|
|
13
15
|
export type AppDropzoneBodyRef = {
|
|
14
16
|
upload: () => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
3
3
|
import Dropzone from 'react-dropzone';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
@@ -8,7 +8,7 @@ import { toastLoading } from '../configs/store/actions';
|
|
|
8
8
|
import { useMessageUtils } from '../configs/useMessageUtils';
|
|
9
9
|
import UploadService from './UploadService';
|
|
10
10
|
import './style.scss';
|
|
11
|
-
function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, onDrop, keepName, showConfirmButton = true, }, ref) {
|
|
11
|
+
function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, onDrop, keepName, showConfirmButton = true, disablePreview = false, }, ref) {
|
|
12
12
|
const { t } = useTranslation('upload');
|
|
13
13
|
const { state, dispatch } = useContext(CommonContext);
|
|
14
14
|
const { dispatchError } = useMessageUtils();
|
|
@@ -24,13 +24,13 @@ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, onDrop, keep
|
|
|
24
24
|
setPreview(undefined);
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
if (isImageFile(file)) {
|
|
27
|
+
if (!disablePreview && isImageFile(file)) {
|
|
28
28
|
const url = URL.createObjectURL(file);
|
|
29
29
|
setPreview(url);
|
|
30
30
|
return () => URL.revokeObjectURL(url);
|
|
31
31
|
}
|
|
32
32
|
setPreview(undefined);
|
|
33
|
-
}, [file]);
|
|
33
|
+
}, [file, disablePreview]);
|
|
34
34
|
const upload = async () => {
|
|
35
35
|
const currentFile = fileRef.current;
|
|
36
36
|
if (!currentFile || state.toastLoading)
|
|
@@ -61,7 +61,7 @@ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, onDrop, keep
|
|
|
61
61
|
setFile(files[0]);
|
|
62
62
|
onDrop?.();
|
|
63
63
|
};
|
|
64
|
-
return (_jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && preview && _jsx("img", { className: "preview", src: preview, alt: "" }),
|
|
64
|
+
return (_jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && (_jsxs("div", { className: "uploaded-file", children: [preview && _jsx("img", { className: "preview", src: preview, alt: "" }), !preview && (_jsxs(_Fragment, { children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name })] })), showConfirmButton && (_jsx(Button, { onClick: upload, text: t('label.confirm'), size: "small", mode: "outlined" }))] }))] }));
|
|
65
65
|
}
|
|
66
66
|
const AppDropzoneBody = forwardRef(AppDropzoneBodyInner);
|
|
67
67
|
export default AppDropzoneBody;
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
height: 400px;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
.uploaded-
|
|
25
|
+
.uploaded-file {
|
|
26
26
|
display: flex;
|
|
27
27
|
flex-direction: column;
|
|
28
|
+
align-items: center;
|
|
28
29
|
width: 100%;
|
|
29
|
-
gap:
|
|
30
|
+
gap: 24px;
|
|
30
31
|
text-align: center;
|
|
31
32
|
border: 1px solid var(--border-subtle-3);
|
|
32
33
|
border-radius: var(--radius-100);
|
|
@@ -2,21 +2,21 @@ export const UploadTexts = {
|
|
|
2
2
|
en: {
|
|
3
3
|
'label.dropzone': 'Drag and drop or click to upload a file',
|
|
4
4
|
'label.uploaded.file': 'You are uploading the following file',
|
|
5
|
-
'label.confirm': '
|
|
5
|
+
'label.confirm': 'Confirm to upload the file',
|
|
6
6
|
'modal.title': 'Upload a file',
|
|
7
7
|
'error.uploading.image': 'An error occurred while uploading a file. Contact the administrator.',
|
|
8
8
|
},
|
|
9
9
|
'pt-BR': {
|
|
10
10
|
'label.dropzone': 'Arraste e solte ou clique para enviar um arquivo.',
|
|
11
11
|
'label.uploaded.file': 'Você está enviando o seguinte arquivo',
|
|
12
|
-
'label.confirm': '
|
|
12
|
+
'label.confirm': 'Confirme para enviar o arquivo',
|
|
13
13
|
'modal.title': 'Upload de arquivo',
|
|
14
14
|
'error.uploading.image': 'Ocorreu um erro ao enviar o arquivo. Entre em contato com o administrador.',
|
|
15
15
|
},
|
|
16
16
|
it: {
|
|
17
17
|
'label.dropzone': 'Trascina e rilascia o clicca per caricare un file',
|
|
18
18
|
'label.uploaded.file': 'Stai caricando il seguente file',
|
|
19
|
-
'label.confirm': '
|
|
19
|
+
'label.confirm': 'Conferma per caricare il file',
|
|
20
20
|
'modal.title': 'Carica un file',
|
|
21
21
|
'error.uploading.image': "Si è verificato un errore durante il caricamento del file. Contatta l'amministratore.",
|
|
22
22
|
},
|