tycho-components 0.4.14 → 0.4.16

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.
@@ -1,5 +1,5 @@
1
- import "./style.scss";
2
- import { UploadedFile } from "./UploadedFile";
1
+ import './style.scss';
2
+ import { UploadedFile } from './UploadedFile';
3
3
  type Props = {
4
4
  folder: string;
5
5
  onClose: () => void;
@@ -1,23 +1,25 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext, useState } from "react";
3
- import Dropzone from "react-dropzone";
4
- import { useTranslation } from "react-i18next";
5
- import AppModal from "../AppModal";
6
- import CommonContext from "../configs/CommonContext";
7
- import { toastLoading } from "../configs/store/actions";
8
- import { useMessageUtils } from "../configs/useMessageUtils";
9
- import "./style.scss";
10
- import UploadService from "./UploadService";
2
+ import { useContext, useState } from 'react';
3
+ import Dropzone from 'react-dropzone';
4
+ import { useTranslation } from 'react-i18next';
5
+ import AppModal from '../AppModal';
6
+ import CommonContext from '../configs/CommonContext';
7
+ import { toastLoading } from '../configs/store/actions';
8
+ import { useMessageUtils } from '../configs/useMessageUtils';
9
+ import './style.scss';
10
+ import UploadService from './UploadService';
11
11
  export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }) {
12
- const { t } = useTranslation("upload");
12
+ const { t } = useTranslation('upload');
13
13
  const { state, dispatch } = useContext(CommonContext);
14
14
  const { dispatchError } = useMessageUtils();
15
15
  const [file, setFile] = useState();
16
16
  const [preview, setPreview] = useState();
17
17
  const isImageFile = (file) => {
18
- return file.type.startsWith("image/");
18
+ return file.type?.startsWith('image/') ?? false;
19
19
  };
20
20
  const handleDrop = async (files) => {
21
+ if (files.length === 0)
22
+ return;
21
23
  const file = files[0];
22
24
  setFile(file);
23
25
  if (isImageFile(file))
@@ -29,22 +31,22 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
29
31
  return;
30
32
  dispatch(toastLoading(true));
31
33
  const data = new FormData();
32
- data.append("file", file);
33
- data.append("folder", folder);
34
- keepName && data.append("keepOriginalName", "true");
34
+ data.append('file', file);
35
+ data.append('folder', folder);
36
+ keepName && data.append('keepOriginalName', 'true');
35
37
  UploadService.execute(data)
36
38
  .then((r) => {
37
39
  onSuccess(r.data);
38
40
  })
39
41
  .catch((err) => {
40
- dispatchError({ err: "error.uploading.image", t, key: "upload" });
42
+ dispatchError({ err: 'error.uploading.image', t, key: 'upload' });
41
43
  onError && onError(err);
42
44
  })
43
45
  .finally(() => {
44
46
  dispatch(toastLoading(false));
45
47
  });
46
48
  };
47
- return (_jsx(AppModal, { title: title || t("modal.title"), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children: _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, onLoad: () => {
49
+ return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children: _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, onLoad: () => {
48
50
  URL.revokeObjectURL(preview);
49
- } })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t("label.uploaded.file") }), _jsx("span", { children: file.name }), _jsx("b", { children: t("label.confirm") })] }))] }) }));
51
+ } })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name }), _jsx("b", { children: t('label.confirm') })] }))] }) }));
50
52
  }
@@ -7,7 +7,7 @@ import "./style.scss";
7
7
  export default function AppModal({ children, title, subtitle, className, close, confirm, disableConfirm, hideFooter, disableClose, disableCancel, confirmLabel, closeLabel, cancel, onEntered, alternativeButton, hideBackdrop, alternativeOptions, }) {
8
8
  const { t } = useTranslation("common");
9
9
  const getClassNames = cx("modal-container", className);
10
- return (_jsx(Modal, { open: true, disableEnforceFocus: true, disableAutoFocus: true, disableRestoreFocus: true, hideBackdrop: hideBackdrop, children: _jsx(Fade, { in: true, onEntered: () => onEntered && onEntered(), children: _jsxs(Box, { className: getClassNames, sx: style, children: [_jsxs("div", { className: "header", children: [_jsxs("div", { className: "titles", children: [_jsx("span", { className: "title", children: title }), subtitle && _jsx("span", { className: "subtitle", children: subtitle })] }), !disableClose && (_jsx(Icon, { name: "close", onClick: close, className: "pointer" }))] }), _jsx("div", { className: "body", children: children }), !hideFooter ? (_jsxs("div", { className: "footer", children: [alternativeButton && alternativeOptions, alternativeButton && (_jsx(Button, { className: "alternative", color: "white", onClick: alternativeButton.action, text: alternativeButton.title })), !disableCancel && (_jsx(Button, { onClick: cancel || close, text: closeLabel || t("button.cancel"), color: "danger" })), confirm && (_jsx(Button, { onClick: confirm, disabled: disableConfirm, text: confirmLabel || t("button.confirm") }))] })) : null] }) }) }));
10
+ return (_jsx(Modal, { open: true, disableEnforceFocus: true, disableAutoFocus: true, disableRestoreFocus: true, hideBackdrop: hideBackdrop, children: _jsx(Fade, { in: true, onEntered: () => onEntered && onEntered(), children: _jsxs(Box, { className: getClassNames, sx: style, children: [_jsxs("div", { className: "header", children: [_jsxs("div", { className: "titles", children: [_jsx("span", { className: "title", children: title }), subtitle && _jsx("span", { className: "subtitle", children: subtitle })] }), !disableClose && (_jsx(Icon, { name: "close", onClick: close, className: "pointer" }))] }), _jsx("div", { className: "body", children: children }), !hideFooter ? (_jsxs("div", { className: "footer", children: [alternativeOptions && alternativeOptions, alternativeButton && (_jsx(Button, { className: "alternative", color: "white", onClick: alternativeButton.action, text: alternativeButton.title })), !disableCancel && (_jsx(Button, { onClick: cancel || close, text: closeLabel || t("button.cancel"), color: "danger" })), confirm && (_jsx(Button, { onClick: confirm, disabled: disableConfirm, text: confirmLabel || t("button.confirm") }))] })) : null] }) }) }));
11
11
  }
12
12
  const style = {
13
13
  position: "absolute",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.4.14",
4
+ "version": "0.4.16",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {