tycho-components 0.16.3 → 0.16.4

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.
@@ -5,6 +5,7 @@ type Props = {
5
5
  onSuccess: (response: UploadedFile) => void;
6
6
  onError?: (err: any) => void;
7
7
  accept: Record<string, string[]>;
8
+ messages?: Partial<Record<'label.dropzone' | 'label.uploaded.file', string>>;
8
9
  onDrop?: () => void;
9
10
  keepName?: boolean;
10
11
  title?: string;
@@ -14,5 +15,5 @@ type Props = {
14
15
  };
15
16
  disableConfirm?: boolean;
16
17
  };
17
- export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, disableConfirm, }: Props): import("react/jsx-runtime").JSX.Element;
18
+ export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, messages, onDrop, keepName, title, alternativeButton, disableConfirm, }: Props): import("react/jsx-runtime").JSX.Element;
18
19
  export {};
@@ -3,11 +3,11 @@ import { useRef } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import AppModal from '../AppModal';
5
5
  import AppDropzoneBody from './AppDropzoneBody';
6
- export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, disableConfirm = false, }) {
6
+ export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, messages, onDrop, keepName, title, alternativeButton, disableConfirm = false, }) {
7
7
  const { t } = useTranslation('upload');
8
8
  const bodyRef = useRef(null);
9
9
  const handleConfirm = () => {
10
10
  bodyRef.current?.upload();
11
11
  };
12
- return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: handleConfirm, disableConfirm: disableConfirm, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBody, { ref: bodyRef, folder: folder, onSuccess: onSuccess, onError: onError, accept: accept, onDrop: onDrop, keepName: keepName, showConfirmButton: false }) }));
12
+ return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: handleConfirm, disableConfirm: disableConfirm, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBody, { ref: bodyRef, folder: folder, onSuccess: onSuccess, onError: onError, accept: accept, messages: messages, onDrop: onDrop, keepName: keepName, showConfirmButton: false }) }));
13
13
  }
@@ -5,6 +5,7 @@ export type AppDropzoneBodyProps = {
5
5
  onSuccess: (response: UploadedFile) => void;
6
6
  onError?: (err: any) => void;
7
7
  accept: Record<string, string[]>;
8
+ messages?: Partial<Record<'label.dropzone' | 'label.uploaded.file', string>>;
8
9
  onDrop?: () => void;
9
10
  keepName?: boolean;
10
11
  /** When false, the confirm button is hidden (e.g. when used inside modal with its own confirm) */
@@ -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, disablePreview = false, disableConfirm = false, }, ref) {
11
+ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, messages, onDrop, keepName, showConfirmButton = true, disablePreview = false, disableConfirm = false, }, ref) {
12
12
  const { t } = useTranslation('upload');
13
13
  const { state, dispatch } = useContext(CommonContext);
14
14
  const { dispatchError } = useMessageUtils();
@@ -64,7 +64,11 @@ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, onDrop, keep
64
64
  const handleCancel = () => {
65
65
  setFile(undefined);
66
66
  };
67
- 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 && (_jsxs("div", { className: "buttons", children: [_jsx(Button, { onClick: handleCancel, text: t('common:button.cancel'), size: "small", mode: "outlined", color: "danger" }), _jsx(Button, { onClick: upload, text: t('label.confirm'), size: "small", mode: "outlined", disabled: disableConfirm })] }))] }))] }));
67
+ const resolveMessage = (key) => {
68
+ const customMessage = messages?.[key]?.trim();
69
+ return customMessage || t(key);
70
+ };
71
+ 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: resolveMessage('label.dropzone') })] })) })), file && (_jsxs("div", { className: "uploaded-file", children: [preview && _jsx("img", { className: "preview", src: preview, alt: "" }), !preview && (_jsxs(_Fragment, { children: [_jsx("b", { children: resolveMessage('label.uploaded.file') }), _jsx("span", { children: file.name })] })), showConfirmButton && (_jsxs("div", { className: "buttons", children: [_jsx(Button, { onClick: handleCancel, text: t('common:button.cancel'), size: "small", mode: "outlined", color: "danger" }), _jsx(Button, { onClick: upload, text: t('label.confirm'), size: "small", mode: "outlined", disabled: disableConfirm })] }))] }))] }));
68
72
  }
69
73
  const AppDropzoneBody = forwardRef(AppDropzoneBodyInner);
70
74
  export default AppDropzoneBody;
@@ -31,10 +31,12 @@
31
31
  border: 1px solid var(--border-subtle-3);
32
32
  border-radius: var(--radius-100);
33
33
  padding: 16px;
34
- }
35
-
36
- .buttons {
37
- display: flex;
38
34
  gap: 16px;
35
+
36
+ .buttons {
37
+ display: flex;
38
+ gap: 16px;
39
+ margin-top: 16px;
40
+ }
39
41
  }
40
42
  }
@@ -1,22 +1,22 @@
1
1
  export const UploadTexts = {
2
2
  en: {
3
3
  'label.dropzone': 'Drag and drop or click to upload a file',
4
- 'label.uploaded.file': 'You are uploading the following file',
5
- 'label.confirm': 'Confirm to upload the file',
4
+ 'label.uploaded.file': 'You are uploading the following file:',
5
+ 'label.confirm': 'Confirm',
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
- 'label.uploaded.file': 'Você está enviando o seguinte arquivo',
12
- 'label.confirm': 'Confirme para enviar o arquivo',
11
+ 'label.uploaded.file': 'Você está enviando o seguinte arquivo:',
12
+ 'label.confirm': 'Confirme',
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
- 'label.uploaded.file': 'Stai caricando il seguente file',
19
- 'label.confirm': 'Conferma per caricare il file',
18
+ 'label.uploaded.file': 'Stai caricando il seguente file:',
19
+ 'label.confirm': 'Conferma',
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
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.16.3",
4
+ "version": "0.16.4",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {