tycho-components 0.19.16 → 0.19.17
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/dist/AppDropzoneLocal/AppDropzoneBodyLocal.d.ts +15 -0
- package/dist/AppDropzoneLocal/AppDropzoneBodyLocal.js +55 -0
- package/dist/AppDropzoneLocal/AppDropzoneLocal.d.ts +15 -0
- package/dist/AppDropzoneLocal/AppDropzoneLocal.js +13 -0
- package/dist/AppDropzoneLocal/UploadedFileLocal.d.ts +5 -0
- package/dist/AppDropzoneLocal/UploadedFileLocal.js +1 -0
- package/dist/AppDropzoneLocal/index.d.ts +5 -0
- package/dist/AppDropzoneLocal/index.js +4 -0
- package/dist/AppDropzoneLocal/style.scss +75 -0
- package/dist/configs/Localization.d.ts +3 -0
- package/dist/configs/localization/UploadTexts.d.ts +3 -0
- package/dist/configs/localization/UploadTexts.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './style.scss';
|
|
2
|
+
import type { UploadedFileLocal } from './UploadedFileLocal';
|
|
3
|
+
export type AppDropzoneBodyLocalProps = {
|
|
4
|
+
onSuccess: (files: UploadedFileLocal[]) => void;
|
|
5
|
+
onError?: (err: unknown) => void;
|
|
6
|
+
accept: Record<string, string[]>;
|
|
7
|
+
onDrop?: () => void;
|
|
8
|
+
/** When false, the confirm button is hidden (e.g. when used inside modal with its own confirm) */
|
|
9
|
+
showConfirmButton?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type AppDropzoneBodyLocalRef = {
|
|
12
|
+
upload: () => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
declare const AppDropzoneBodyLocal: import("react").ForwardRefExoticComponent<AppDropzoneBodyLocalProps & import("react").RefAttributes<AppDropzoneBodyLocalRef>>;
|
|
15
|
+
export default AppDropzoneBodyLocal;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
3
|
+
import Dropzone from 'react-dropzone';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { Button } from 'tycho-storybook';
|
|
6
|
+
import './style.scss';
|
|
7
|
+
function AppDropzoneBodyLocalInner({ onSuccess, onError, accept, onDrop, showConfirmButton = true, }, ref) {
|
|
8
|
+
const { t } = useTranslation('upload');
|
|
9
|
+
const [files, setFiles] = useState([]);
|
|
10
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
11
|
+
const filesRef = useRef([]);
|
|
12
|
+
filesRef.current = files;
|
|
13
|
+
const upload = async () => {
|
|
14
|
+
const currentFiles = filesRef.current;
|
|
15
|
+
if (currentFiles.length === 0 || isUploading)
|
|
16
|
+
return;
|
|
17
|
+
setIsUploading(true);
|
|
18
|
+
try {
|
|
19
|
+
const results = await Promise.all(currentFiles.map(async (file) => ({
|
|
20
|
+
name: file.name,
|
|
21
|
+
content: await file.text(),
|
|
22
|
+
})));
|
|
23
|
+
onSuccess(results);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
onError?.(err);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setIsUploading(false);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
useImperativeHandle(ref, () => ({
|
|
33
|
+
upload,
|
|
34
|
+
}));
|
|
35
|
+
const handleDrop = (acceptedFiles) => {
|
|
36
|
+
if (acceptedFiles.length === 0)
|
|
37
|
+
return;
|
|
38
|
+
setFiles((prev) => [...prev, ...acceptedFiles]);
|
|
39
|
+
onDrop?.();
|
|
40
|
+
};
|
|
41
|
+
const clearFiles = () => setFiles([]);
|
|
42
|
+
const removeAt = (index) => {
|
|
43
|
+
setFiles((prev) => prev.filter((_, i) => i !== index));
|
|
44
|
+
};
|
|
45
|
+
return (_jsxs("div", { className: "dropzone-container-local", children: [files.length === 0 && (_jsx(Dropzone, { onDrop: handleDrop, accept: accept, multiple: true, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone-local", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), files.length > 0 && (_jsxs("div", { className: "uploaded-message-local", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("ul", { className: "uploaded-file-list-local", children: files.map((file, index) => (_jsxs("li", { children: [_jsx("span", { children: file.name }), _jsx("button", { type: "button", className: "uploaded-file-remove-local", onClick: (e) => {
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
removeAt(index);
|
|
48
|
+
}, "aria-label": t('common:button.remove', {
|
|
49
|
+
defaultValue: 'Remove',
|
|
50
|
+
}), children: "\u00D7" })] }, `${file.name}-${file.size}-${index}`))) }), _jsx("button", { type: "button", className: "uploaded-clear-all-local", onClick: clearFiles, children: t('label.clear.all', { defaultValue: 'Clear all' }) }), _jsx("b", { children: t('label.confirm') })] })), files.length > 0 && showConfirmButton && (_jsx(Button, { onClick: () => {
|
|
51
|
+
void upload();
|
|
52
|
+
}, text: t('common:button.confirm') }))] }));
|
|
53
|
+
}
|
|
54
|
+
const AppDropzoneBodyLocal = forwardRef(AppDropzoneBodyLocalInner);
|
|
55
|
+
export default AppDropzoneBodyLocal;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UploadedFileLocal } from './UploadedFileLocal';
|
|
2
|
+
type AppDropzoneLocalProps = {
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
onSuccess: (files: UploadedFileLocal[]) => void;
|
|
5
|
+
onError?: (err: unknown) => void;
|
|
6
|
+
accept: Record<string, string[]>;
|
|
7
|
+
onDrop?: () => void;
|
|
8
|
+
title?: string;
|
|
9
|
+
alternativeButton?: {
|
|
10
|
+
title: string;
|
|
11
|
+
action: () => void;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export default function AppDropzoneLocal({ onClose, onSuccess, onError, accept, onDrop, title, alternativeButton, }: AppDropzoneLocalProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import AppModal from '../AppModal';
|
|
5
|
+
import AppDropzoneBodyLocal from './AppDropzoneBodyLocal';
|
|
6
|
+
export default function AppDropzoneLocal({ onClose, onSuccess, onError, accept, onDrop, title, alternativeButton, }) {
|
|
7
|
+
const { t } = useTranslation('upload');
|
|
8
|
+
const bodyRef = useRef(null);
|
|
9
|
+
const handleConfirm = () => {
|
|
10
|
+
void bodyRef.current?.upload();
|
|
11
|
+
};
|
|
12
|
+
return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload-local", close: onClose, confirm: handleConfirm, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBodyLocal, { ref: bodyRef, onSuccess: onSuccess, onError: onError, accept: accept, onDrop: onDrop, showConfirmButton: false }) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import AppDropzoneLocal from './AppDropzoneLocal';
|
|
2
|
+
import AppDropzoneBodyLocal, { type AppDropzoneBodyLocalProps, type AppDropzoneBodyLocalRef } from './AppDropzoneBodyLocal';
|
|
3
|
+
import type { UploadedFileLocal } from './UploadedFileLocal';
|
|
4
|
+
export default AppDropzoneLocal;
|
|
5
|
+
export { AppDropzoneBodyLocal, type AppDropzoneBodyLocalProps, type AppDropzoneBodyLocalRef, type UploadedFileLocal, };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
.dropzone-container-local {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
|
|
6
|
+
.dropzone-local {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
text-align: center;
|
|
11
|
+
width: 100%;
|
|
12
|
+
padding: var(--spacing-700);
|
|
13
|
+
border-radius: var(--radius-100);
|
|
14
|
+
border: 2px dashed var(--border-subtle-3);
|
|
15
|
+
background-color: var(--layer-layer-2);
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.preview-local {
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
width: 400px;
|
|
22
|
+
height: 400px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.uploaded-message-local {
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
width: 100%;
|
|
29
|
+
gap: 16px;
|
|
30
|
+
text-align: center;
|
|
31
|
+
border: 1px solid var(--border-subtle-3);
|
|
32
|
+
border-radius: var(--radius-100);
|
|
33
|
+
padding: 16px;
|
|
34
|
+
margin-top: var(--spacing-400);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.uploaded-file-list-local {
|
|
38
|
+
list-style: none;
|
|
39
|
+
margin: 0;
|
|
40
|
+
padding: 0;
|
|
41
|
+
text-align: left;
|
|
42
|
+
border: var(--border-default);
|
|
43
|
+
padding: 8px;
|
|
44
|
+
border-radius: var(--radius-100);
|
|
45
|
+
|
|
46
|
+
li {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: space-between;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
padding: 4px 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.uploaded-file-remove-local {
|
|
56
|
+
flex-shrink: 0;
|
|
57
|
+
border: none;
|
|
58
|
+
background: transparent;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
font-size: 1.25rem;
|
|
61
|
+
line-height: 1;
|
|
62
|
+
padding: 0 4px;
|
|
63
|
+
color: var(--text-secondary, inherit);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.uploaded-clear-all-local {
|
|
67
|
+
align-self: center;
|
|
68
|
+
border: none;
|
|
69
|
+
background: transparent;
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
text-decoration: underline;
|
|
72
|
+
font: inherit;
|
|
73
|
+
color: var(--text-link, inherit);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -230,6 +230,7 @@ export declare const commonResources: {
|
|
|
230
230
|
upload: {
|
|
231
231
|
'label.dropzone': string;
|
|
232
232
|
'label.uploaded.file': string;
|
|
233
|
+
'label.confirm': string;
|
|
233
234
|
'modal.title': string;
|
|
234
235
|
'error.uploading.image': string;
|
|
235
236
|
};
|
|
@@ -549,6 +550,7 @@ export declare const commonResources: {
|
|
|
549
550
|
upload: {
|
|
550
551
|
'label.dropzone': string;
|
|
551
552
|
'label.uploaded.file': string;
|
|
553
|
+
'label.confirm': string;
|
|
552
554
|
'modal.title': string;
|
|
553
555
|
'error.uploading.image': string;
|
|
554
556
|
};
|
|
@@ -870,6 +872,7 @@ export declare const commonResources: {
|
|
|
870
872
|
upload: {
|
|
871
873
|
'label.dropzone': string;
|
|
872
874
|
'label.uploaded.file': string;
|
|
875
|
+
'label.confirm': string;
|
|
873
876
|
'modal.title': string;
|
|
874
877
|
'error.uploading.image': string;
|
|
875
878
|
};
|
|
@@ -2,18 +2,21 @@ export declare const UploadTexts: {
|
|
|
2
2
|
en: {
|
|
3
3
|
'label.dropzone': string;
|
|
4
4
|
'label.uploaded.file': string;
|
|
5
|
+
'label.confirm': string;
|
|
5
6
|
'modal.title': string;
|
|
6
7
|
'error.uploading.image': string;
|
|
7
8
|
};
|
|
8
9
|
'pt-BR': {
|
|
9
10
|
'label.dropzone': string;
|
|
10
11
|
'label.uploaded.file': string;
|
|
12
|
+
'label.confirm': string;
|
|
11
13
|
'modal.title': string;
|
|
12
14
|
'error.uploading.image': string;
|
|
13
15
|
};
|
|
14
16
|
it: {
|
|
15
17
|
'label.dropzone': string;
|
|
16
18
|
'label.uploaded.file': string;
|
|
19
|
+
'label.confirm': string;
|
|
17
20
|
'modal.title': string;
|
|
18
21
|
'error.uploading.image': string;
|
|
19
22
|
};
|
|
@@ -2,18 +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': 'Press confirm to continue',
|
|
5
6
|
'modal.title': 'Upload a file',
|
|
6
7
|
'error.uploading.image': 'An error occurred while uploading a file. Contact the administrator.',
|
|
7
8
|
},
|
|
8
9
|
'pt-BR': {
|
|
9
10
|
'label.dropzone': 'Arraste e solte ou clique para enviar um arquivo.',
|
|
10
11
|
'label.uploaded.file': 'Você está enviando o seguinte arquivo:',
|
|
12
|
+
'label.confirm': 'Pressione confirmar para continuar',
|
|
11
13
|
'modal.title': 'Upload de arquivo',
|
|
12
14
|
'error.uploading.image': 'Ocorreu um erro ao enviar o arquivo. Entre em contato com o administrador.',
|
|
13
15
|
},
|
|
14
16
|
it: {
|
|
15
17
|
'label.dropzone': 'Trascina e rilascia o clicca per caricare un file',
|
|
16
18
|
'label.uploaded.file': 'Stai caricando il seguente file:',
|
|
19
|
+
'label.confirm': 'Premi conferma per continuare',
|
|
17
20
|
'modal.title': 'Carica un file',
|
|
18
21
|
'error.uploading.image': "Si è verificato un errore durante il caricamento del file. Contatta l'amministratore.",
|
|
19
22
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { default as AppClipboard } from './AppClipboard';
|
|
|
4
4
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
5
5
|
export { default as AppDropzone, AppDropzoneBody, type AppDropzoneBodyProps, type AppDropzoneBodyRef, } from './AppDropzone';
|
|
6
6
|
export type { UploadedFile } from './AppDropzone/UploadedFile';
|
|
7
|
+
export { default as AppDropzoneLocal, AppDropzoneBodyLocal, type AppDropzoneBodyLocalProps, type AppDropzoneBodyLocalRef, type UploadedFileLocal, } from './AppDropzoneLocal';
|
|
7
8
|
export { default as AppEditable } from './AppEditable';
|
|
8
9
|
export type { AppEditableField } from './AppEditable/AppEditableField';
|
|
9
10
|
export { validateFormField } from './AppEditable/FormField';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as AppCard } from './AppCard/AppCard';
|
|
|
3
3
|
export { default as AppClipboard } from './AppClipboard';
|
|
4
4
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
5
5
|
export { default as AppDropzone, AppDropzoneBody, } from './AppDropzone';
|
|
6
|
+
export { default as AppDropzoneLocal, AppDropzoneBodyLocal, } from './AppDropzoneLocal';
|
|
6
7
|
export { default as AppEditable } from './AppEditable';
|
|
7
8
|
export { validateFormField } from './AppEditable/FormField';
|
|
8
9
|
export { default as AppForm } from './AppForm/AppForm';
|