@hh.ru/magritte-ui-upload 2.0.0 → 2.1.0
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/FileName.js +1 -1
- package/FileView.d.ts +13 -0
- package/FileView.js +26 -0
- package/FileView.js.map +1 -0
- package/FileViewWithPreview.d.ts +5 -0
- package/FileViewWithPreview.js +25 -0
- package/FileViewWithPreview.js.map +1 -0
- package/MultiUpload.d.ts +4 -0
- package/MultiUpload.js +45 -0
- package/MultiUpload.js.map +1 -0
- package/SingleUpload.d.ts +4 -0
- package/SingleUpload.js +79 -0
- package/SingleUpload.js.map +1 -0
- package/Upload.d.ts +1 -1
- package/Upload.js +25 -124
- package/Upload.js.map +1 -1
- package/index.css +1138 -41
- package/index.js +12 -3
- package/index.js.map +1 -1
- package/package.json +3 -2
- package/types.d.ts +8 -2
- package/upload-DAE6N3sX.js +5 -0
- package/upload-DAE6N3sX.js.map +1 -0
- package/useDropActions.d.ts +14 -0
- package/useDropActions.js +25 -0
- package/useDropActions.js.map +1 -0
- package/useDropButtons.d.ts +12 -0
- package/useDropButtons.js +25 -0
- package/useDropButtons.js.map +1 -0
- package/useFilePreview.d.ts +7 -0
- package/useFilePreview.js +17 -0
- package/useFilePreview.js.map +1 -0
- package/utils.d.ts +8 -2
- package/utils.js +25 -1
- package/utils.js.map +1 -1
package/FileName.js
CHANGED
|
@@ -2,7 +2,7 @@ import './index.css';
|
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
|
|
5
|
-
var styles = {"file-name-body":"magritte-file-name-body___PTTMc_2-
|
|
5
|
+
var styles = {"file-name-body":"magritte-file-name-body___PTTMc_2-1-0","fileNameBody":"magritte-file-name-body___PTTMc_2-1-0","file-name-body_medium":"magritte-file-name-body_medium___sfmmq_2-1-0","fileNameBodyMedium":"magritte-file-name-body_medium___sfmmq_2-1-0","file-name":"magritte-file-name___ZSL2g_2-1-0","fileName":"magritte-file-name___ZSL2g_2-1-0"};
|
|
6
6
|
|
|
7
7
|
const parse = (file) => {
|
|
8
8
|
const name = file.name;
|
package/FileView.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement, MouseEvent } from 'react';
|
|
2
|
+
import { UploadType, LoadedFile, RenderFileInfo } from '@hh.ru/magritte-ui-upload/types';
|
|
3
|
+
export interface FileViewProps {
|
|
4
|
+
uploadType: UploadType;
|
|
5
|
+
loadedFile: LoadedFile;
|
|
6
|
+
renderFileInfo: RenderFileInfo;
|
|
7
|
+
onFileDelete: (event: MouseEvent) => void;
|
|
8
|
+
preview: string;
|
|
9
|
+
'aria-label': string;
|
|
10
|
+
isLast?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const FileView: ({ uploadType, loadedFile, preview, renderFileInfo, onFileDelete, "aria-label": ariaLabel, isLast, }: FileViewProps) => ReactElement;
|
|
13
|
+
export { FileView };
|
package/FileView.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Action } from '@hh.ru/magritte-ui-action';
|
|
4
|
+
import { Avatar } from '@hh.ru/magritte-ui-avatar';
|
|
5
|
+
import { Divider } from '@hh.ru/magritte-ui-divider';
|
|
6
|
+
import { ExclamationTriangleOutlinedSize16, CheckCircleOutlinedSize16, CrossOutlinedSize24, TrashOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
+
import { Loader } from '@hh.ru/magritte-ui-loader';
|
|
8
|
+
import { VSpacing } from '@hh.ru/magritte-ui-spacing';
|
|
9
|
+
import { FileName } from './FileName.js';
|
|
10
|
+
import { getUploadIcon, bytes2mb } from './utils.js';
|
|
11
|
+
import 'classnames';
|
|
12
|
+
|
|
13
|
+
var styles = {"file-info-body":"magritte-file-info-body___HmfXd_2-1-0","fileInfoBody":"magritte-file-info-body___HmfXd_2-1-0","file-info-and-controls":"magritte-file-info-and-controls___61iyY_2-1-0","fileInfoAndControls":"magritte-file-info-and-controls___61iyY_2-1-0","file-info-container":"magritte-file-info-container___WFab8_2-1-0","fileInfoContainer":"magritte-file-info-container___WFab8_2-1-0","file-info":"magritte-file-info___HrqiB_2-1-0","fileInfo":"magritte-file-info___HrqiB_2-1-0","controls":"magritte-controls___WdH7A_2-1-0"};
|
|
14
|
+
|
|
15
|
+
const FileView = ({ uploadType, loadedFile, preview, renderFileInfo, onFileDelete, 'aria-label': ariaLabel, isLast = false, }) => {
|
|
16
|
+
const isLoading = Boolean(loadedFile?.loading);
|
|
17
|
+
const isInvalid = Boolean(loadedFile?.error);
|
|
18
|
+
const isImageType = uploadType === 'image';
|
|
19
|
+
return (jsxs(Fragment, { children: [jsx(Avatar, { mode: isImageType && !isLoading ? 'image' : 'icon', style: "secondary", image: preview, size: 48, icon: getUploadIcon(uploadType, loadedFile, true), "aria-label": ariaLabel }), jsxs("div", { className: styles.fileInfoBody, children: [jsxs("div", { className: styles.fileInfoAndControls, children: [jsxs("div", { className: styles.fileInfoContainer, children: [jsx(FileName, { file: loadedFile.data }), jsx(VSpacing, { default: 4 }), jsxs("div", { className: styles.fileInfo, children: [isInvalid && jsx(ExclamationTriangleOutlinedSize16, { initial: "negative" }), isLoading && jsx(Loader, { size: 16 }), !isInvalid && !isLoading && jsx(CheckCircleOutlinedSize16, { initial: "positive" }), renderFileInfo({
|
|
20
|
+
...loadedFile,
|
|
21
|
+
fileSizeMB: bytes2mb(loadedFile.data.size),
|
|
22
|
+
})] })] }), jsxs("div", { className: styles.controls, children: [isLoading && jsx(Action, { icon: CrossOutlinedSize24, mode: "secondary", onClick: onFileDelete }), !isLoading && jsx(Action, { icon: TrashOutlinedSize24, mode: "secondary", onClick: onFileDelete })] })] }), !isLast && (jsxs("div", { children: [jsx(VSpacing, { default: 16 }), jsx(Divider, {}), jsx(VSpacing, { default: 16 })] }))] })] }));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { FileView };
|
|
26
|
+
//# sourceMappingURL=FileView.js.map
|
package/FileView.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileView.js","sources":["../src/FileView.tsx"],"sourcesContent":["import { ReactElement, MouseEvent } from 'react';\n\nimport { Action } from '@hh.ru/magritte-ui-action';\nimport { Avatar } from '@hh.ru/magritte-ui-avatar';\nimport { Divider } from '@hh.ru/magritte-ui-divider';\nimport {\n CrossOutlinedSize24,\n CheckCircleOutlinedSize16,\n ExclamationTriangleOutlinedSize16,\n TrashOutlinedSize24,\n} from '@hh.ru/magritte-ui-icon/icon';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { FileName } from '@hh.ru/magritte-ui-upload/FileName';\nimport { UploadType, LoadedFile, RenderFileInfo } from '@hh.ru/magritte-ui-upload/types';\nimport { getUploadIcon, bytes2mb } from '@hh.ru/magritte-ui-upload/utils';\n\nimport styles from './file-view.less';\n\nexport interface FileViewProps {\n uploadType: UploadType;\n loadedFile: LoadedFile;\n renderFileInfo: RenderFileInfo;\n onFileDelete: (event: MouseEvent) => void;\n preview: string;\n 'aria-label': string;\n isLast?: boolean;\n}\n\nconst FileView = ({\n uploadType,\n loadedFile,\n preview,\n renderFileInfo,\n onFileDelete,\n 'aria-label': ariaLabel,\n isLast = false,\n}: FileViewProps): ReactElement => {\n const isLoading = Boolean(loadedFile?.loading);\n const isInvalid = Boolean(loadedFile?.error);\n const isImageType = uploadType === 'image';\n return (\n <>\n <Avatar\n mode={isImageType && !isLoading ? 'image' : 'icon'}\n style=\"secondary\"\n image={preview}\n size={48}\n icon={getUploadIcon(uploadType, loadedFile, true)}\n aria-label={ariaLabel}\n />\n <div className={styles.fileInfoBody}>\n <div className={styles.fileInfoAndControls}>\n <div className={styles.fileInfoContainer}>\n <FileName file={loadedFile.data} />\n <VSpacing default={4} />\n <div className={styles.fileInfo}>\n {isInvalid && <ExclamationTriangleOutlinedSize16 initial=\"negative\" />}\n {isLoading && <Loader size={16} />}\n {!isInvalid && !isLoading && <CheckCircleOutlinedSize16 initial=\"positive\" />}\n {renderFileInfo({\n ...loadedFile,\n fileSizeMB: bytes2mb(loadedFile.data.size),\n })}\n </div>\n </div>\n <div className={styles.controls}>\n {isLoading && <Action icon={CrossOutlinedSize24} mode=\"secondary\" onClick={onFileDelete} />}\n {!isLoading && <Action icon={TrashOutlinedSize24} mode=\"secondary\" onClick={onFileDelete} />}\n </div>\n </div>\n {!isLast && (\n <div>\n <VSpacing default={16} />\n <Divider />\n <VSpacing default={16} />\n </div>\n )}\n </div>\n </>\n );\n};\n\nexport { FileView };\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;AA6BM,MAAA,QAAQ,GAAG,CAAC,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,YAAY,EAAE,SAAS,EACvB,MAAM,GAAG,KAAK,GACF,KAAkB;IAC9B,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC7C,IAAA,MAAM,WAAW,GAAG,UAAU,KAAK,OAAO,CAAC;AAC3C,IAAA,QACIA,IAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CACIC,GAAC,CAAA,MAAM,EACH,EAAA,IAAI,EAAE,WAAW,IAAI,CAAC,SAAS,GAAG,OAAO,GAAG,MAAM,EAClD,KAAK,EAAC,WAAW,EACjB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,EAAE,EACR,IAAI,EAAE,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,EACrC,YAAA,EAAA,SAAS,EACvB,CAAA,EACFF,IAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,YAAY,EAC/B,QAAA,E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AA,EAAA,QAAA,EAAA,CACIE,GAAC,CAAA,QAAQ,IAAC,OAAO,EAAE,EAAE,EAAA,CAAI,EACzBA,GAAC,CAAA,OAAO,EAAG,EAAA,CAAA,EACXA,IAAC,QAAQ,EAAA,EAAC,OAAO,EAAE,EAAE,EAAI,CAAA,CAAA,EAAA,CACvB,CACT,CACC,EAAA,CAAA,CAAA,EAAA,CACP,EACL;AACN;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { FileViewProps } from '@hh.ru/magritte-ui-upload/FileView';
|
|
3
|
+
type FileViewWithPreviewProps = Omit<FileViewProps, 'preview' | 'uploadType'>;
|
|
4
|
+
declare const FileViewWithPreview: ({ loadedFile, ...otherProps }: FileViewWithPreviewProps) => ReactElement;
|
|
5
|
+
export { FileViewWithPreview };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { FileView } from './FileView.js';
|
|
4
|
+
import { useFilePreview } from './useFilePreview.js';
|
|
5
|
+
import { getFileType } from './utils.js';
|
|
6
|
+
import '@hh.ru/magritte-ui-action';
|
|
7
|
+
import '@hh.ru/magritte-ui-avatar';
|
|
8
|
+
import '@hh.ru/magritte-ui-divider';
|
|
9
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
10
|
+
import '@hh.ru/magritte-ui-loader';
|
|
11
|
+
import '@hh.ru/magritte-ui-spacing';
|
|
12
|
+
import './FileName.js';
|
|
13
|
+
import 'classnames';
|
|
14
|
+
import 'react';
|
|
15
|
+
|
|
16
|
+
var styles = {"item":"magritte-item___vVDG-_2-1-0"};
|
|
17
|
+
|
|
18
|
+
const FileViewWithPreview = ({ loadedFile, ...otherProps }) => {
|
|
19
|
+
const uploadType = getFileType(loadedFile.data.type);
|
|
20
|
+
const preview = useFilePreview({ loadedFile, isImageType: uploadType === 'image' });
|
|
21
|
+
return (jsx("div", { className: styles.item, children: jsx(FileView, { uploadType: uploadType, loadedFile: loadedFile, preview: preview, ...otherProps }) }));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { FileViewWithPreview };
|
|
25
|
+
//# sourceMappingURL=FileViewWithPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileViewWithPreview.js","sources":["../src/FileViewWithPreview.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { FileView, FileViewProps } from '@hh.ru/magritte-ui-upload/FileView';\nimport { useFilePreview } from '@hh.ru/magritte-ui-upload/useFilePreview';\nimport { getFileType } from '@hh.ru/magritte-ui-upload/utils';\n\nimport styles from './file-viev-with-preview.less';\n\ntype FileViewWithPreviewProps = Omit<FileViewProps, 'preview' | 'uploadType'>;\n\nconst FileViewWithPreview = ({ loadedFile, ...otherProps }: FileViewWithPreviewProps): ReactElement => {\n const uploadType = getFileType(loadedFile.data.type);\n const preview = useFilePreview({ loadedFile, isImageType: uploadType === 'image' });\n return (\n <div className={styles.item}>\n <FileView uploadType={uploadType} loadedFile={loadedFile} preview={preview} {...otherProps} />\n </div>\n );\n};\n\nexport { FileViewWithPreview };\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;AAUM,MAAA,mBAAmB,GAAG,CAAC,EAAE,UAAU,EAAE,GAAG,UAAU,EAA4B,KAAkB;IAClG,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrD,IAAA,MAAM,OAAO,GAAG,cAAc,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,KAAK,OAAO,EAAE,CAAC,CAAC;IACpF,QACIA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,IAAI,EACvB,QAAA,EAAAA,GAAA,CAAC,QAAQ,EAAA,EAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAA,GAAM,UAAU,EAAA,CAAI,EAC5F,CAAA,EACR;AACN;;;;"}
|
package/MultiUpload.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { UploadProps } from '@hh.ru/magritte-ui-upload/types';
|
|
3
|
+
declare const MultiUpload: ({ files, trls, size, multiple, accept, selectFileButton: _selectFileButton, deleteFileButton: _deleteFileButton, replaceImageButton: _replaceImageButton, renderFileInfo, onDropAccepted: onDropAcceptedExternal, onDropRejected: onDropRejectedExternal, onFileDelete: onFileDeleteExternal, "aria-label": ariaLabel, ...dropzoneProps }: UploadProps) => ReactElement;
|
|
4
|
+
export { MultiUpload };
|
package/MultiUpload.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useDropzone } from 'react-dropzone';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { VSpacing } from '@hh.ru/magritte-ui-spacing';
|
|
6
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
7
|
+
import { FileViewWithPreview } from './FileViewWithPreview.js';
|
|
8
|
+
import { useDropActions } from './useDropActions.js';
|
|
9
|
+
import { useDropButtons } from './useDropButtons.js';
|
|
10
|
+
import { getAvaliableFileTypes, getUploadIcon, DEFAULT_ACCEPT, RenderFileInfoDefault } from './utils.js';
|
|
11
|
+
import { s as styles } from './upload-DAE6N3sX.js';
|
|
12
|
+
import './FileView.js';
|
|
13
|
+
import '@hh.ru/magritte-ui-action';
|
|
14
|
+
import '@hh.ru/magritte-ui-avatar';
|
|
15
|
+
import '@hh.ru/magritte-ui-divider';
|
|
16
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
17
|
+
import '@hh.ru/magritte-ui-loader';
|
|
18
|
+
import './FileName.js';
|
|
19
|
+
import './useFilePreview.js';
|
|
20
|
+
import 'react';
|
|
21
|
+
|
|
22
|
+
const MultiUpload = ({ files, trls, size, multiple = true, accept = DEFAULT_ACCEPT, selectFileButton: _selectFileButton, deleteFileButton: _deleteFileButton, replaceImageButton: _replaceImageButton, renderFileInfo = RenderFileInfoDefault, onDropAccepted: onDropAcceptedExternal, onDropRejected: onDropRejectedExternal, onFileDelete: onFileDeleteExternal, 'aria-label': ariaLabel, ...dropzoneProps }) => {
|
|
23
|
+
const uploadType = getAvaliableFileTypes(accept);
|
|
24
|
+
const { onDropAccepted, onDropRejected, onFileDelete } = useDropActions({
|
|
25
|
+
onDropAccepted: onDropAcceptedExternal,
|
|
26
|
+
onDropRejected: onDropRejectedExternal,
|
|
27
|
+
onFileDelete: onFileDeleteExternal,
|
|
28
|
+
});
|
|
29
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
30
|
+
...dropzoneProps,
|
|
31
|
+
accept,
|
|
32
|
+
onDropAccepted,
|
|
33
|
+
onDropRejected,
|
|
34
|
+
multiple,
|
|
35
|
+
});
|
|
36
|
+
const { selectFileButton } = useDropButtons({ selectFileButton: _selectFileButton });
|
|
37
|
+
return (jsxs(Fragment, { children: [jsxs("div", { className: classnames(styles.root, styles[`root_${size}`], { [styles.dragActive]: isDragActive }), ...getRootProps(), children: [jsx("input", { ...getInputProps() }), jsx("div", { className: styles.background }), jsxs("div", { className: styles.body, children: [getUploadIcon(uploadType, undefined, false), jsx(VSpacing, { default: 16 }), jsx(Text, { typography: "label-2-regular", children: trls.title }), jsx(VSpacing, { default: 6 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: trls.subTitle }), selectFileButton && (jsxs(Fragment, { children: [jsx(VSpacing, { default: 16 }), selectFileButton] }))] })] }), files.length > 0 && (jsx("div", { className: styles.fileList, children: files.map((loadedFile, indexFile) => {
|
|
38
|
+
return (jsx(FileViewWithPreview, { loadedFile: loadedFile, renderFileInfo: renderFileInfo, onFileDelete: (event) => {
|
|
39
|
+
onFileDelete(event, loadedFile, indexFile);
|
|
40
|
+
}, "aria-label": ariaLabel || '', isLast: files.length - 1 === indexFile }, loadedFile.data.name));
|
|
41
|
+
}) }))] }));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { MultiUpload };
|
|
45
|
+
//# sourceMappingURL=MultiUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiUpload.js","sources":["../src/MultiUpload.tsx"],"sourcesContent":["import { ReactElement } from 'react';\nimport { useDropzone } from 'react-dropzone';\nimport classnames from 'classnames';\n\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Text } from '@hh.ru/magritte-ui-typography';\nimport { FileViewWithPreview } from '@hh.ru/magritte-ui-upload/FileViewWithPreview';\nimport { UploadProps } from '@hh.ru/magritte-ui-upload/types';\nimport { useDropActions } from '@hh.ru/magritte-ui-upload/useDropActions';\nimport { useDropButtons } from '@hh.ru/magritte-ui-upload/useDropButtons';\nimport {\n getUploadIcon,\n getAvaliableFileTypes,\n RenderFileInfoDefault,\n DEFAULT_ACCEPT,\n} from '@hh.ru/magritte-ui-upload/utils';\n\nimport styles from './upload.less';\n\nconst MultiUpload = ({\n files,\n trls,\n size,\n multiple = true,\n accept = DEFAULT_ACCEPT,\n selectFileButton: _selectFileButton,\n deleteFileButton: _deleteFileButton,\n replaceImageButton: _replaceImageButton,\n renderFileInfo = RenderFileInfoDefault,\n onDropAccepted: onDropAcceptedExternal,\n onDropRejected: onDropRejectedExternal,\n onFileDelete: onFileDeleteExternal,\n 'aria-label': ariaLabel,\n ...dropzoneProps\n}: UploadProps): ReactElement => {\n const uploadType = getAvaliableFileTypes(accept);\n const { onDropAccepted, onDropRejected, onFileDelete } = useDropActions({\n onDropAccepted: onDropAcceptedExternal,\n onDropRejected: onDropRejectedExternal,\n onFileDelete: onFileDeleteExternal,\n });\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n ...dropzoneProps,\n accept,\n onDropAccepted,\n onDropRejected,\n multiple,\n });\n const { selectFileButton } = useDropButtons({ selectFileButton: _selectFileButton });\n return (\n <>\n <div\n className={classnames(styles.root, styles[`root_${size}`], { [styles.dragActive]: isDragActive })}\n {...getRootProps()}\n >\n <input {...getInputProps()} />\n <div className={styles.background} />\n <div className={styles.body}>\n {getUploadIcon(uploadType, undefined, false)}\n <VSpacing default={16} />\n <Text typography=\"label-2-regular\">{trls.title}</Text>\n <VSpacing default={6} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {trls.subTitle}\n </Text>\n {selectFileButton && (\n <>\n <VSpacing default={16} />\n {selectFileButton}\n </>\n )}\n </div>\n </div>\n {files.length > 0 && (\n <div className={styles.fileList}>\n {files.map((loadedFile, indexFile) => {\n return (\n <FileViewWithPreview\n key={loadedFile.data.name}\n loadedFile={loadedFile}\n renderFileInfo={renderFileInfo}\n onFileDelete={(event) => {\n onFileDelete(event, loadedFile, indexFile);\n }}\n aria-label={ariaLabel || ''}\n isLast={files.length - 1 === indexFile}\n />\n );\n })}\n </div>\n )}\n </>\n );\n};\n\nexport { MultiUpload };\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBM,MAAA,WAAW,GAAG,CAAC,EACjB,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,GAAG,IAAI,EACf,MAAM,GAAG,cAAc,EACvB,gBAAgB,EAAE,iBAAiB,EACnC,gBAAgB,EAAE,iBAAiB,EACnC,kBAAkB,EAAE,mBAAmB,EACvC,cAAc,GAAG,qBAAqB,EACtC,cAAc,EAAE,sBAAsB,EACtC,cAAc,EAAE,sBAAsB,EACtC,YAAY,EAAE,oBAAoB,EAClC,YAAY,EAAE,SAAS,EACvB,GAAG,aAAa,EACN,KAAkB;AAC5B,IAAA,MAAM,UAAU,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,cAAc,CAAC;AACpE,QAAA,cAAc,EAAE,sBAAsB;AACtC,QAAA,cAAc,EAAE,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,EACN,gBAAgB,KACbF,IACI,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CAAAC,GAAA,CAAC,QAAQ,EAAA,EAAC,OAAO,EAAE,EAAE,EAAA,CAAI,EACxB,gBAAgB,CAAA,EAAA,CAClB,CACN,CAAA,EAAA,CACC,IACJ,EACL,KAAK,CAAC,MAAM,GAAG,CAAC,KACbA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,QAAQ,EAC1B,QAAA,EAAA,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,SAAS,KAAI;AACjC,oBAAA,QACIA,GAAC,CAAA,mBAAmB,EAEhB,EAAA,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,CAAC,KAAK,KAAI;AACpB,4BAAA,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;yBAC9C,EAAA,YAAA,EACW,SAAS,IAAI,EAAE,EAC3B,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,SAAS,IAPjC,UAAU,CAAC,IAAI,CAAC,IAAI,CAQ3B,EACJ;AACN,iBAAC,CAAC,EAAA,CACA,CACT,CAAA,EAAA,CACF,EACL;AACN;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { UploadProps } from '@hh.ru/magritte-ui-upload/types';
|
|
3
|
+
declare const SingleUpload: ({ files, trls, size, multiple, accept, selectFileButton: _selectFileButton, deleteFileButton: _deleteFileButton, replaceImageButton: _replaceImageButton, renderFileInfo, onDropAccepted: onDropAcceptedExternal, onDropRejected: onDropRejectedExternal, onFileDelete: onFileDeleteExternal, "aria-label": ariaLabel, ...dropzoneProps }: UploadProps) => ReactElement;
|
|
4
|
+
export { SingleUpload };
|
package/SingleUpload.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
4
|
+
import { useDropzone } from 'react-dropzone';
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
import { Avatar } from '@hh.ru/magritte-ui-avatar';
|
|
7
|
+
import { CrossOutlinedSize24, ExclamationTriangleOutlinedSize32 } from '@hh.ru/magritte-ui-icon/icon';
|
|
8
|
+
import { Loader } from '@hh.ru/magritte-ui-loader';
|
|
9
|
+
import { VSpacing } from '@hh.ru/magritte-ui-spacing';
|
|
10
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
11
|
+
import { FileName } from './FileName.js';
|
|
12
|
+
import { FileView } from './FileView.js';
|
|
13
|
+
import { useDropActions } from './useDropActions.js';
|
|
14
|
+
import { useDropButtons } from './useDropButtons.js';
|
|
15
|
+
import { useFilePreview } from './useFilePreview.js';
|
|
16
|
+
import { getAvaliableFileTypes, getUploadIcon, bytes2mb, DEFAULT_ACCEPT, RenderFileInfoDefault } from './utils.js';
|
|
17
|
+
import { s as styles } from './upload-DAE6N3sX.js';
|
|
18
|
+
import '@hh.ru/magritte-ui-action';
|
|
19
|
+
import '@hh.ru/magritte-ui-divider';
|
|
20
|
+
|
|
21
|
+
const SingleUpload = ({ files, trls, size = 'medium', multiple = false, accept = DEFAULT_ACCEPT, selectFileButton: _selectFileButton, deleteFileButton: _deleteFileButton, replaceImageButton: _replaceImageButton, renderFileInfo = RenderFileInfoDefault, onDropAccepted: onDropAcceptedExternal, onDropRejected: onDropRejectedExternal, onFileDelete: onFileDeleteExternal, 'aria-label': ariaLabel, ...dropzoneProps }) => {
|
|
22
|
+
const bodyUploadRef = useRef(null);
|
|
23
|
+
const uploadType = getAvaliableFileTypes(accept);
|
|
24
|
+
const loadedFile = files.length > 0 ? files[0] : undefined;
|
|
25
|
+
const isLoad = Boolean(loadedFile);
|
|
26
|
+
const isLoading = Boolean(loadedFile?.loading);
|
|
27
|
+
const isInvalid = Boolean(loadedFile?.error);
|
|
28
|
+
const isSizeSmall = size === 'small';
|
|
29
|
+
const isImageType = uploadType === 'image';
|
|
30
|
+
const preview = useFilePreview({ loadedFile, isImageType });
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!bodyUploadRef.current) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
if (isSizeSmall) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
// фиксируем ширину, так как после выбора контент поменяется
|
|
39
|
+
const currentElement = bodyUploadRef.current;
|
|
40
|
+
currentElement.style.minHeight = `${bodyUploadRef.current.offsetHeight}px`;
|
|
41
|
+
return () => {
|
|
42
|
+
currentElement.style.minHeight = 'auto';
|
|
43
|
+
};
|
|
44
|
+
}, [isSizeSmall]);
|
|
45
|
+
const { onDropAccepted, onDropRejected, onFileDelete } = useDropActions({
|
|
46
|
+
onDropAccepted: onDropAcceptedExternal,
|
|
47
|
+
onDropRejected: onDropRejectedExternal,
|
|
48
|
+
onFileDelete: onFileDeleteExternal,
|
|
49
|
+
});
|
|
50
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
51
|
+
...dropzoneProps,
|
|
52
|
+
accept,
|
|
53
|
+
onDropAccepted,
|
|
54
|
+
onDropRejected,
|
|
55
|
+
multiple,
|
|
56
|
+
});
|
|
57
|
+
const { selectFileButton, deleteFileButton, replaceImageButton } = useDropButtons({
|
|
58
|
+
selectFileButton: _selectFileButton,
|
|
59
|
+
deleteFileButton: _deleteFileButton,
|
|
60
|
+
replaceImageButton: _replaceImageButton,
|
|
61
|
+
onFileDelete: (event) => {
|
|
62
|
+
onFileDelete(event, loadedFile, 0);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const backgroundStyles = !isSizeSmall
|
|
66
|
+
? { backgroundImage: preview !== 'none' ? `url('${preview}')` : preview }
|
|
67
|
+
: {};
|
|
68
|
+
return (jsxs("div", { className: classnames(styles.root, styles[`root_${size}`], { [styles.dragActive]: isDragActive }, { [styles.loading]: isLoading }, { [styles.load]: isLoad }, { [styles.invalid]: isInvalid }), ...getRootProps(), children: [jsx("input", { ...getInputProps() }), jsx("div", { className: styles.background, style: backgroundStyles }), jsxs("div", { className: styles.body, ref: bodyUploadRef, children: [isSizeSmall && (jsxs(Fragment, { children: [loadedFile && (jsx(FileView, { uploadType: uploadType, loadedFile: loadedFile, renderFileInfo: renderFileInfo, onFileDelete: (event) => {
|
|
69
|
+
onFileDelete(event, loadedFile, 0);
|
|
70
|
+
}, preview: preview, "aria-label": ariaLabel || '', isLast: true })), !loadedFile && (jsxs(Fragment, { children: [jsx(Avatar, { mode: "icon", style: "secondary", size: 48, icon: getUploadIcon(uploadType, loadedFile, true), "aria-label": ariaLabel || '' }), jsxs("div", { children: [jsx(Text, { typography: "label-2-regular", children: trls.title }), jsx(VSpacing, { default: 4 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: trls.subTitle })] }), selectFileButton && jsx("div", { className: styles.smallControls, children: selectFileButton })] }))] })), !isSizeSmall && (jsxs(Fragment, { children: [isLoading && (jsxs("div", { className: styles.loader, children: [jsx(Loader, { size: 64 }), jsx("div", { className: styles.cancel, children: jsx(CrossOutlinedSize24, { initial: "accent", onClick: (event) => {
|
|
71
|
+
onFileDelete(event, loadedFile, 0);
|
|
72
|
+
} }) })] })), isInvalid ? (jsx(ExclamationTriangleOutlinedSize32, { initial: "negative" })) : (getUploadIcon(uploadType, loadedFile, false)), jsx(VSpacing, { default: 16 }), loadedFile && (jsxs(Fragment, { children: [jsx(FileName, { file: loadedFile.data, isSizeMedium: true }), jsx(VSpacing, { default: 6 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: renderFileInfo({
|
|
73
|
+
...loadedFile,
|
|
74
|
+
fileSizeMB: bytes2mb(loadedFile.data.size),
|
|
75
|
+
}) }), !loadedFile.loading && !isImageType && deleteFileButton && (jsxs(Fragment, { children: [jsx(VSpacing, { default: 16 }), deleteFileButton] })), !loadedFile.loading && isImageType && (replaceImageButton || deleteFileButton) && (jsxs("div", { className: styles.imageControls, children: [replaceImageButton, deleteFileButton] }))] })), !loadedFile && (jsxs(Fragment, { children: [jsx(Text, { typography: "label-2-regular", children: trls.title }), jsx(VSpacing, { default: 6 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: trls.subTitle }), selectFileButton && (jsxs(Fragment, { children: [jsx(VSpacing, { default: 16 }), selectFileButton] }))] }))] }))] })] }));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { SingleUpload };
|
|
79
|
+
//# sourceMappingURL=SingleUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SingleUpload.js","sources":["../src/SingleUpload.tsx"],"sourcesContent":["import { ReactElement, useRef, useEffect, MouseEvent } from 'react';\nimport { useDropzone } from 'react-dropzone';\nimport classnames from 'classnames';\n\nimport { Avatar } from '@hh.ru/magritte-ui-avatar';\nimport { CrossOutlinedSize24, ExclamationTriangleOutlinedSize32 } from '@hh.ru/magritte-ui-icon/icon';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Text } from '@hh.ru/magritte-ui-typography';\nimport { FileName } from '@hh.ru/magritte-ui-upload/FileName';\nimport { FileView } from '@hh.ru/magritte-ui-upload/FileView';\nimport { UploadProps } from '@hh.ru/magritte-ui-upload/types';\nimport { useDropActions } from '@hh.ru/magritte-ui-upload/useDropActions';\nimport { useDropButtons } from '@hh.ru/magritte-ui-upload/useDropButtons';\nimport { useFilePreview } from '@hh.ru/magritte-ui-upload/useFilePreview';\nimport {\n getUploadIcon,\n bytes2mb,\n getAvaliableFileTypes,\n RenderFileInfoDefault,\n DEFAULT_ACCEPT,\n} from '@hh.ru/magritte-ui-upload/utils';\n\nimport styles from './upload.less';\n\nconst SingleUpload = ({\n files,\n trls,\n size = 'medium',\n multiple = false,\n accept = DEFAULT_ACCEPT,\n selectFileButton: _selectFileButton,\n deleteFileButton: _deleteFileButton,\n replaceImageButton: _replaceImageButton,\n renderFileInfo = RenderFileInfoDefault,\n onDropAccepted: onDropAcceptedExternal,\n onDropRejected: onDropRejectedExternal,\n onFileDelete: onFileDeleteExternal,\n 'aria-label': ariaLabel,\n ...dropzoneProps\n}: UploadProps): ReactElement => {\n const bodyUploadRef = useRef<HTMLDivElement>(null);\n const uploadType = getAvaliableFileTypes(accept);\n const loadedFile = files.length > 0 ? files[0] : undefined;\n const isLoad = Boolean(loadedFile);\n const isLoading = Boolean(loadedFile?.loading);\n const isInvalid = Boolean(loadedFile?.error);\n const isSizeSmall = size === 'small';\n const isImageType = uploadType === 'image';\n const preview = useFilePreview({ loadedFile, isImageType });\n\n useEffect(() => {\n if (!bodyUploadRef.current) {\n return void 0;\n }\n if (isSizeSmall) {\n return void 0;\n }\n // фиксируем ширину, так как после выбора контент поменяется\n const currentElement = bodyUploadRef.current;\n currentElement.style.minHeight = `${bodyUploadRef.current.offsetHeight}px`;\n return () => {\n currentElement.style.minHeight = 'auto';\n };\n }, [isSizeSmall]);\n\n const { onDropAccepted, onDropRejected, onFileDelete } = useDropActions({\n onDropAccepted: onDropAcceptedExternal,\n onDropRejected: onDropRejectedExternal,\n onFileDelete: onFileDeleteExternal,\n });\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n ...dropzoneProps,\n accept,\n onDropAccepted,\n onDropRejected,\n multiple,\n });\n\n const { selectFileButton, deleteFileButton, replaceImageButton } = useDropButtons({\n selectFileButton: _selectFileButton,\n deleteFileButton: _deleteFileButton,\n replaceImageButton: _replaceImageButton,\n onFileDelete: (event: MouseEvent) => {\n onFileDelete(event, loadedFile, 0);\n },\n });\n\n const backgroundStyles = !isSizeSmall\n ? { backgroundImage: preview !== 'none' ? `url('${preview}')` : preview }\n : {};\n return (\n <div\n className={classnames(\n styles.root,\n styles[`root_${size}`],\n { [styles.dragActive]: isDragActive },\n { [styles.loading]: isLoading },\n { [styles.load]: isLoad },\n { [styles.invalid]: isInvalid }\n )}\n {...getRootProps()}\n >\n <input {...getInputProps()} />\n <div className={styles.background} style={backgroundStyles} />\n <div className={styles.body} ref={bodyUploadRef}>\n {isSizeSmall && (\n <>\n {loadedFile && (\n <FileView\n uploadType={uploadType}\n loadedFile={loadedFile}\n renderFileInfo={renderFileInfo}\n onFileDelete={(event) => {\n onFileDelete(event, loadedFile, 0);\n }}\n preview={preview}\n aria-label={ariaLabel || ''}\n isLast\n />\n )}\n {!loadedFile && (\n <>\n <Avatar\n mode=\"icon\"\n style=\"secondary\"\n size={48}\n icon={getUploadIcon(uploadType, loadedFile, true)}\n aria-label={ariaLabel || ''}\n />\n <div>\n <Text typography=\"label-2-regular\">{trls.title}</Text>\n <VSpacing default={4} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {trls.subTitle}\n </Text>\n </div>\n {selectFileButton && <div className={styles.smallControls}>{selectFileButton}</div>}\n </>\n )}\n </>\n )}\n {!isSizeSmall && (\n <>\n {isLoading && (\n <div className={styles.loader}>\n <Loader size={64} />\n <div className={styles.cancel}>\n <CrossOutlinedSize24\n initial=\"accent\"\n onClick={(event) => {\n onFileDelete(event, loadedFile, 0);\n }}\n />\n </div>\n </div>\n )}\n {isInvalid ? (\n <ExclamationTriangleOutlinedSize32 initial=\"negative\" />\n ) : (\n getUploadIcon(uploadType, loadedFile, false)\n )}\n <VSpacing default={16} />\n {loadedFile && (\n <>\n <FileName file={loadedFile.data} isSizeMedium />\n <VSpacing default={6} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {renderFileInfo({\n ...loadedFile,\n fileSizeMB: bytes2mb(loadedFile.data.size),\n })}\n </Text>\n {!loadedFile.loading && !isImageType && deleteFileButton && (\n <>\n <VSpacing default={16} />\n {deleteFileButton}\n </>\n )}\n {!loadedFile.loading && isImageType && (replaceImageButton || deleteFileButton) && (\n <div className={styles.imageControls}>\n {replaceImageButton}\n {deleteFileButton}\n </div>\n )}\n </>\n )}\n {!loadedFile && (\n <>\n <Text typography=\"label-2-regular\">{trls.title}</Text>\n <VSpacing default={6} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {trls.subTitle}\n </Text>\n {selectFileButton && (\n <>\n <VSpacing default={16} />\n {selectFileButton}\n </>\n )}\n </>\n )}\n </>\n )}\n </div>\n </div>\n );\n};\n\nexport { SingleUpload };\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBM,MAAA,YAAY,GAAG,CAAC,EAClB,KAAK,EACL,IAAI,EACJ,IAAI,GAAG,QAAQ,EACf,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,cAAc,EACvB,gBAAgB,EAAE,iBAAiB,EACnC,gBAAgB,EAAE,iBAAiB,EACnC,kBAAkB,EAAE,mBAAmB,EACvC,cAAc,GAAG,qBAAqB,EACtC,cAAc,EAAE,sBAAsB,EACtC,cAAc,EAAE,sBAAsB,EACtC,YAAY,EAAE,oBAAoB,EAClC,YAAY,EAAE,SAAS,EACvB,GAAG,aAAa,EACN,KAAkB;AAC5B,IAAA,MAAM,aAAa,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AACnD,IAAA,MAAM,UAAU,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACjD,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAC3D,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC7C,IAAA,MAAM,WAAW,GAAG,IAAI,KAAK,OAAO,CAAC;AACrC,IAAA,MAAM,WAAW,GAAG,UAAU,KAAK,OAAO,CAAC;IAC3C,MAAM,OAAO,GAAG,cAAc,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5D,S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AAC,OAAO,EAAE,CAAC,EAAA,CAAI,EACxBA,GAAA,CAAC,IAAI,EAAA,EAAC,UAAU,EAAC,iBAAiB,EAAC,KAAK,EAAC,WAAW,EAC/C,QAAA,EAAA,IAAI,CAAC,QAAQ,EACX,CAAA,EACN,gBAAgB,KACbD,IAAA,CAAAE,QAAA,EAAA,EAAA,QAAA,EAAA,CACID,GAAC,CAAA,QAAQ,EAAC,EAAA,OAAO,EAAE,EAAE,EAAI,CAAA,EACxB,gBAAgB,CAAA,EAAA,CAClB,CACN,CAAA,EAAA,CACF,CACN,CAAA,EAAA,CACF,CACN,CAAA,EAAA,CACC,CACJ,EAAA,CAAA,EACR;AACN;;;;"}
|
package/Upload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { UploadProps } from '@hh.ru/magritte-ui-upload/types';
|
|
3
|
-
declare const Upload: ({
|
|
3
|
+
declare const Upload: ({ multiple, ...uploadProps }: UploadProps) => ReactElement;
|
|
4
4
|
export { Upload };
|
package/Upload.js
CHANGED
|
@@ -1,130 +1,31 @@
|
|
|
1
1
|
import './index.css';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { MultiUpload } from './MultiUpload.js';
|
|
4
|
+
import { SingleUpload } from './SingleUpload.js';
|
|
5
|
+
import 'react-dropzone';
|
|
6
|
+
import 'classnames';
|
|
7
|
+
import '@hh.ru/magritte-ui-spacing';
|
|
8
|
+
import '@hh.ru/magritte-ui-typography';
|
|
9
|
+
import './FileViewWithPreview.js';
|
|
10
|
+
import './FileView.js';
|
|
11
|
+
import '@hh.ru/magritte-ui-action';
|
|
12
|
+
import '@hh.ru/magritte-ui-avatar';
|
|
13
|
+
import '@hh.ru/magritte-ui-divider';
|
|
14
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
15
|
+
import '@hh.ru/magritte-ui-loader';
|
|
16
|
+
import './FileName.js';
|
|
17
|
+
import './utils.js';
|
|
18
|
+
import './useFilePreview.js';
|
|
19
|
+
import 'react';
|
|
20
|
+
import './useDropActions.js';
|
|
21
|
+
import './useDropButtons.js';
|
|
22
|
+
import './upload-DAE6N3sX.js';
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const bytes2mb = (value) => {
|
|
19
|
-
return (value / order).toFixed(2);
|
|
20
|
-
};
|
|
21
|
-
// парсим accept в нормальный формат
|
|
22
|
-
const getAvaliableFileTypes = (accept) => {
|
|
23
|
-
const avaliableTypes = Object.keys(accept);
|
|
24
|
-
if (avaliableTypes.length === 0) {
|
|
25
|
-
throw new Error(`Magritte component Upload: accept can't be empty`);
|
|
26
|
-
}
|
|
27
|
-
if (avaliableTypes.length > 1) {
|
|
28
|
-
return 'mixed';
|
|
24
|
+
const Upload = ({ multiple, ...uploadProps }) => {
|
|
25
|
+
if (multiple) {
|
|
26
|
+
return jsx(MultiUpload, { multiple: true, size: "medium", ...uploadProps });
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
return avaliableType.split('/')[0];
|
|
32
|
-
};
|
|
33
|
-
const RenderFileInfoDefault = (loadedFile) => {
|
|
34
|
-
return loadedFile.fileSizeMB;
|
|
35
|
-
};
|
|
36
|
-
const DEFAULT_ACCEPT = {
|
|
37
|
-
'image/*': ['.png', '.jpeg', '.jpg'],
|
|
38
|
-
};
|
|
39
|
-
const Upload = ({ files, trls, size = 'medium', multiple = false, accept = DEFAULT_ACCEPT, selectFileButton: _selectFileButton, deleteFileButton: _deleteFileButton, replaceImageButton: _replaceImageButton, renderFileInfo = RenderFileInfoDefault, onDropAccepted: onDropAcceptedExternal, onDropRejected: onDropRejectedExternal, onFileDelete: onFileDeleteExternal, 'aria-label': ariaLabel, ...dropzoneProps }) => {
|
|
40
|
-
const bodyUploadRef = useRef(null);
|
|
41
|
-
const uploadType = getAvaliableFileTypes(accept);
|
|
42
|
-
const loadedFile = files.length > 0 ? files[0] : undefined;
|
|
43
|
-
const isLoad = Boolean(loadedFile);
|
|
44
|
-
const isLoading = Boolean(loadedFile?.loading);
|
|
45
|
-
const isInvalid = Boolean(loadedFile?.error);
|
|
46
|
-
const isSizeSmall = size === 'small';
|
|
47
|
-
const isImageType = uploadType === 'image';
|
|
48
|
-
const backgroundUploadPreview = useMemo(() => {
|
|
49
|
-
if (!loadedFile || !isImageType) {
|
|
50
|
-
return 'none';
|
|
51
|
-
}
|
|
52
|
-
if (loadedFile.loading) {
|
|
53
|
-
return 'none';
|
|
54
|
-
}
|
|
55
|
-
if (isSizeSmall) {
|
|
56
|
-
return URL.createObjectURL(loadedFile.data);
|
|
57
|
-
}
|
|
58
|
-
return `url('${URL.createObjectURL(loadedFile.data)}')`;
|
|
59
|
-
}, [loadedFile, isImageType, isSizeSmall]);
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (!bodyUploadRef.current) {
|
|
62
|
-
return void 0;
|
|
63
|
-
}
|
|
64
|
-
if (isSizeSmall) {
|
|
65
|
-
return void 0;
|
|
66
|
-
}
|
|
67
|
-
// фиксируем ширину, так как после выбора контент поменяется
|
|
68
|
-
const currentElement = bodyUploadRef.current;
|
|
69
|
-
currentElement.style.minHeight = `${bodyUploadRef.current.offsetHeight}px`;
|
|
70
|
-
return () => {
|
|
71
|
-
currentElement.style.minHeight = 'auto';
|
|
72
|
-
};
|
|
73
|
-
}, [isSizeSmall]);
|
|
74
|
-
const onDropAccepted = useCallback((acceptedFiles, event) => {
|
|
75
|
-
const acceptedLoadFiles = acceptedFiles.map((file) => ({ data: file, loading: true, loadPercentage: 0 }));
|
|
76
|
-
onDropAcceptedExternal(acceptedLoadFiles, event);
|
|
77
|
-
}, [onDropAcceptedExternal]);
|
|
78
|
-
const onDropRejected = useCallback((fileRejections, event) => {
|
|
79
|
-
const rejectionLoadFiles = fileRejections.map((fileRejection) => ({
|
|
80
|
-
data: fileRejection.file,
|
|
81
|
-
loading: false,
|
|
82
|
-
error: fileRejection.errors?.[0].code || '',
|
|
83
|
-
}));
|
|
84
|
-
onDropRejectedExternal?.(rejectionLoadFiles, event);
|
|
85
|
-
}, [onDropRejectedExternal]);
|
|
86
|
-
const onFileDelete = useCallback((event) => {
|
|
87
|
-
loadedFile && onFileDeleteExternal(loadedFile, 0);
|
|
88
|
-
event.stopPropagation();
|
|
89
|
-
}, [loadedFile, onFileDeleteExternal]);
|
|
90
|
-
const selectFileButton = _selectFileButton &&
|
|
91
|
-
cloneElement(_selectFileButton, {
|
|
92
|
-
key: 'selectFileButton',
|
|
93
|
-
'data-qa': 'magritte-select-file-button',
|
|
94
|
-
});
|
|
95
|
-
const deleteFileButton = _deleteFileButton &&
|
|
96
|
-
cloneElement(_deleteFileButton, {
|
|
97
|
-
key: 'deleteFileButton',
|
|
98
|
-
'data-qa': 'magritte-delete-file-button',
|
|
99
|
-
onClick: (event) => {
|
|
100
|
-
onFileDelete(event);
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
const replaceImageButton = _replaceImageButton &&
|
|
104
|
-
cloneElement(_replaceImageButton, {
|
|
105
|
-
key: 'replaceImageButton',
|
|
106
|
-
'data-qa': 'magritte-select-replace-image-button',
|
|
107
|
-
});
|
|
108
|
-
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
109
|
-
...dropzoneProps,
|
|
110
|
-
accept,
|
|
111
|
-
onDropAccepted,
|
|
112
|
-
onDropRejected,
|
|
113
|
-
multiple,
|
|
114
|
-
});
|
|
115
|
-
return (jsxs("div", { className: classnames(styles.root, styles[`root_${size}`], { [styles.dragActive]: isDragActive }, { [styles.loading]: isLoading }, { [styles.load]: isLoad }, { [styles.invalid]: isInvalid }), ...getRootProps(), children: [jsx("div", { className: styles.background, style: { backgroundImage: !isSizeSmall ? backgroundUploadPreview : 'none' } }), jsxs("div", { className: styles.body, ref: bodyUploadRef, children: [jsx("input", { ...getInputProps() }), isSizeSmall && (jsxs(Fragment, { children: [loadedFile && (jsxs(Fragment, { children: [jsx(Avatar, { mode: isImageType && !isLoading ? 'image' : 'icon', style: "secondary", image: backgroundUploadPreview, size: 48, icon: getUploadIcon(uploadType, loadedFile, true), "aria-label": ariaLabel || '' }), jsxs("div", { className: styles.smallFileInfoContainer, children: [jsx(FileName, { file: loadedFile.data }), jsx(VSpacing, { default: 4 }), jsxs("div", { className: styles.smallFileInfo, children: [isInvalid && jsx(ExclamationTriangleOutlinedSize16, { initial: "negative" }), isLoading && jsx(Loader, { size: 16 }), !isInvalid && !isLoading && jsx(CheckCircleOutlinedSize16, { initial: "positive" }), renderFileInfo({
|
|
116
|
-
...loadedFile,
|
|
117
|
-
fileSizeMB: bytes2mb(loadedFile.data.size),
|
|
118
|
-
})] })] }), jsxs("div", { className: styles.smallControls, children: [isLoading && (jsx(Action, { icon: CrossOutlinedSize24, mode: "secondary", onClick: (event) => {
|
|
119
|
-
onFileDelete(event);
|
|
120
|
-
} })), !isLoading && (jsx(Action, { icon: TrashOutlinedSize24, mode: "secondary", onClick: (event) => {
|
|
121
|
-
onFileDelete(event);
|
|
122
|
-
} }))] })] })), !loadedFile && (jsxs(Fragment, { children: [jsx(Avatar, { mode: "icon", style: "secondary", size: 48, icon: getUploadIcon(uploadType, loadedFile, true), "aria-label": ariaLabel }), jsxs("div", { children: [jsx(Text, { typography: "label-2-regular", children: trls.title }), jsx(VSpacing, { default: 4 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: trls.subTitle })] }), selectFileButton && jsx("div", { className: styles.smallControls, children: selectFileButton })] }))] })), !isSizeSmall && (jsxs(Fragment, { children: [isLoading && (jsxs("div", { className: styles.loader, children: [jsx(Loader, { size: 64 }), jsx("div", { className: styles.cancel, children: jsx(CrossOutlinedSize24, { initial: "accent", onClick: (event) => {
|
|
123
|
-
onFileDelete(event);
|
|
124
|
-
} }) })] })), isInvalid ? (jsx(ExclamationTriangleOutlinedSize32, { initial: "negative" })) : (getUploadIcon(uploadType, loadedFile, false)), jsx(VSpacing, { default: 16 }), loadedFile && (jsxs(Fragment, { children: [jsx(FileName, { file: loadedFile.data, isSizeMedium: true }), jsx(VSpacing, { default: 6 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: renderFileInfo({
|
|
125
|
-
...loadedFile,
|
|
126
|
-
fileSizeMB: bytes2mb(loadedFile.data.size),
|
|
127
|
-
}) }), !loadedFile.loading && !isImageType && deleteFileButton && (jsxs(Fragment, { children: [jsx(VSpacing, { default: 16 }), deleteFileButton] })), !loadedFile.loading && isImageType && (replaceImageButton || deleteFileButton) && (jsxs("div", { className: styles.imageControls, children: [replaceImageButton, deleteFileButton] }))] })), !loadedFile && (jsxs(Fragment, { children: [jsx(Text, { typography: "label-2-regular", children: trls.title }), jsx(VSpacing, { default: 6 }), jsx(Text, { typography: "label-4-regular", style: "secondary", children: trls.subTitle }), selectFileButton && (jsxs(Fragment, { children: [jsx(VSpacing, { default: 16 }), selectFileButton] }))] }))] }))] })] }));
|
|
28
|
+
return jsx(SingleUpload, { multiple: false, ...uploadProps });
|
|
128
29
|
};
|
|
129
30
|
|
|
130
31
|
export { Upload };
|
package/Upload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Upload.js","sources":["../src/Upload.tsx"],"sourcesContent":["import {\n ReactElement,\n useRef,\n ReactNode,\n useEffect,\n useCallback,\n cloneElement,\n MouseEvent,\n ComponentProps,\n useMemo,\n} from 'react';\nimport { useDropzone, Accept, DropEvent, FileRejection } from 'react-dropzone';\nimport classnames from 'classnames';\n\nimport { Action } from '@hh.ru/magritte-ui-action';\nimport { Avatar } from '@hh.ru/magritte-ui-avatar';\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport {\n CrossOutlinedSize24,\n CheckCircleOutlinedSize16,\n ExclamationTriangleOutlinedSize32,\n ExclamationTriangleOutlinedSize16,\n TrashOutlinedSize24,\n} from '@hh.ru/magritte-ui-icon/icon';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Text } from '@hh.ru/magritte-ui-typography';\nimport { FileName } from '@hh.ru/magritte-ui-upload/FileName';\nimport { UploadProps, UploadType, LoadedFileWithFileSize } from '@hh.ru/magritte-ui-upload/types';\nimport { getUploadIcon } from '@hh.ru/magritte-ui-upload/utils';\n\nimport styles from './upload.less';\n\nconst order = 1024 * 1024;\nconst bytes2mb = (value: number): string => {\n return (value / order).toFixed(2);\n};\n\n// парсим accept в нормальный формат\nconst getAvaliableFileTypes = (accept: Accept): UploadType => {\n const avaliableTypes = Object.keys(accept);\n if (avaliableTypes.length === 0) {\n throw new Error(`Magritte component Upload: accept can't be empty`);\n }\n if (avaliableTypes.length > 1) {\n return 'mixed';\n }\n const avaliableType = avaliableTypes[0];\n return avaliableType.split('/')[0] as UploadType;\n};\n\nconst RenderFileInfoDefault = (loadedFile: LoadedFileWithFileSize): ReactNode => {\n return loadedFile.fileSizeMB;\n};\n\nconst DEFAULT_ACCEPT: Accept = {\n 'image/*': ['.png', '.jpeg', '.jpg'],\n};\n\nconst Upload = ({\n files,\n trls,\n size = 'medium',\n multiple = false,\n accept = DEFAULT_ACCEPT,\n selectFileButton: _selectFileButton,\n deleteFileButton: _deleteFileButton,\n replaceImageButton: _replaceImageButton,\n renderFileInfo = RenderFileInfoDefault,\n onDropAccepted: onDropAcceptedExternal,\n onDropRejected: onDropRejectedExternal,\n onFileDelete: onFileDeleteExternal,\n 'aria-label': ariaLabel,\n ...dropzoneProps\n}: UploadProps): ReactElement => {\n const bodyUploadRef = useRef<HTMLDivElement>(null);\n const uploadType = getAvaliableFileTypes(accept);\n const loadedFile = files.length > 0 ? files[0] : undefined;\n const isLoad = Boolean(loadedFile);\n const isLoading = Boolean(loadedFile?.loading);\n const isInvalid = Boolean(loadedFile?.error);\n const isSizeSmall = size === 'small';\n const isImageType = uploadType === 'image';\n\n const backgroundUploadPreview: string = useMemo(() => {\n if (!loadedFile || !isImageType) {\n return 'none';\n }\n if (loadedFile.loading) {\n return 'none';\n }\n if (isSizeSmall) {\n return URL.createObjectURL(loadedFile.data);\n }\n return `url('${URL.createObjectURL(loadedFile.data)}')`;\n }, [loadedFile, isImageType, isSizeSmall]);\n\n useEffect(() => {\n if (!bodyUploadRef.current) {\n return void 0;\n }\n if (isSizeSmall) {\n return void 0;\n }\n // фиксируем ширину, так как после выбора контент поменяется\n const currentElement = bodyUploadRef.current;\n currentElement.style.minHeight = `${bodyUploadRef.current.offsetHeight}px`;\n return () => {\n currentElement.style.minHeight = 'auto';\n };\n }, [isSizeSmall]);\n\n const onDropAccepted = useCallback(\n (acceptedFiles: File[], event: DropEvent) => {\n const acceptedLoadFiles = acceptedFiles.map((file) => ({ data: file, loading: true, loadPercentage: 0 }));\n onDropAcceptedExternal(acceptedLoadFiles, event);\n },\n [onDropAcceptedExternal]\n );\n const onDropRejected = useCallback(\n (fileRejections: FileRejection[], event: DropEvent) => {\n const rejectionLoadFiles = fileRejections.map((fileRejection) => ({\n data: fileRejection.file,\n loading: false,\n error: fileRejection.errors?.[0].code || '',\n }));\n onDropRejectedExternal?.(rejectionLoadFiles, event);\n },\n [onDropRejectedExternal]\n );\n const onFileDelete = useCallback(\n (event: MouseEvent) => {\n loadedFile && onFileDeleteExternal(loadedFile, 0);\n event.stopPropagation();\n },\n [loadedFile, onFileDeleteExternal]\n );\n\n const selectFileButton =\n _selectFileButton &&\n cloneElement(_selectFileButton, {\n key: 'selectFileButton',\n 'data-qa': 'magritte-select-file-button',\n } as Partial<ComponentProps<typeof Button>>);\n\n const deleteFileButton =\n _deleteFileButton &&\n cloneElement(_deleteFileButton, {\n key: 'deleteFileButton',\n 'data-qa': 'magritte-delete-file-button',\n onClick: (event: MouseEvent) => {\n onFileDelete(event);\n },\n } as Partial<ComponentProps<typeof Button>>);\n\n const replaceImageButton =\n _replaceImageButton &&\n cloneElement(_replaceImageButton, {\n key: 'replaceImageButton',\n 'data-qa': 'magritte-select-replace-image-button',\n } as Partial<ComponentProps<typeof Button>>);\n\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n ...dropzoneProps,\n accept,\n onDropAccepted,\n onDropRejected,\n multiple,\n });\n return (\n <div\n className={classnames(\n styles.root,\n styles[`root_${size}`],\n { [styles.dragActive]: isDragActive },\n { [styles.loading]: isLoading },\n { [styles.load]: isLoad },\n { [styles.invalid]: isInvalid }\n )}\n {...getRootProps()}\n >\n <div\n className={styles.background}\n style={{ backgroundImage: !isSizeSmall ? backgroundUploadPreview : 'none' }}\n />\n <div className={styles.body} ref={bodyUploadRef}>\n <input {...getInputProps()} />\n {isSizeSmall && (\n <>\n {loadedFile && (\n <>\n <Avatar\n mode={isImageType && !isLoading ? 'image' : 'icon'}\n style=\"secondary\"\n image={backgroundUploadPreview}\n size={48}\n icon={getUploadIcon(uploadType, loadedFile, true)}\n aria-label={ariaLabel || ''}\n />\n <div className={styles.smallFileInfoContainer}>\n <FileName file={loadedFile.data} />\n <VSpacing default={4} />\n <div className={styles.smallFileInfo}>\n {isInvalid && <ExclamationTriangleOutlinedSize16 initial=\"negative\" />}\n {isLoading && <Loader size={16} />}\n {!isInvalid && !isLoading && <CheckCircleOutlinedSize16 initial=\"positive\" />}\n {renderFileInfo({\n ...loadedFile,\n fileSizeMB: bytes2mb(loadedFile.data.size),\n })}\n </div>\n </div>\n <div className={styles.smallControls}>\n {isLoading && (\n <Action\n icon={CrossOutlinedSize24}\n mode=\"secondary\"\n onClick={(event) => {\n onFileDelete(event);\n }}\n />\n )}\n {!isLoading && (\n <Action\n icon={TrashOutlinedSize24}\n mode=\"secondary\"\n onClick={(event) => {\n onFileDelete(event);\n }}\n />\n )}\n </div>\n </>\n )}\n {!loadedFile && (\n <>\n <Avatar\n mode=\"icon\"\n style=\"secondary\"\n size={48}\n icon={getUploadIcon(uploadType, loadedFile, true)}\n aria-label={ariaLabel as string}\n />\n <div>\n <Text typography=\"label-2-regular\">{trls.title}</Text>\n <VSpacing default={4} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {trls.subTitle}\n </Text>\n </div>\n {selectFileButton && <div className={styles.smallControls}>{selectFileButton}</div>}\n </>\n )}\n </>\n )}\n {!isSizeSmall && (\n <>\n {isLoading && (\n <div className={styles.loader}>\n <Loader size={64} />\n <div className={styles.cancel}>\n <CrossOutlinedSize24\n initial=\"accent\"\n onClick={(event) => {\n onFileDelete(event);\n }}\n />\n </div>\n </div>\n )}\n {isInvalid ? (\n <ExclamationTriangleOutlinedSize32 initial=\"negative\" />\n ) : (\n getUploadIcon(uploadType, loadedFile, false)\n )}\n <VSpacing default={16} />\n {loadedFile && (\n <>\n <FileName file={loadedFile.data} isSizeMedium />\n <VSpacing default={6} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {renderFileInfo({\n ...loadedFile,\n fileSizeMB: bytes2mb(loadedFile.data.size),\n })}\n </Text>\n {!loadedFile.loading && !isImageType && deleteFileButton && (\n <>\n <VSpacing default={16} />\n {deleteFileButton}\n </>\n )}\n {!loadedFile.loading && isImageType && (replaceImageButton || deleteFileButton) && (\n <div className={styles.imageControls}>\n {replaceImageButton}\n {deleteFileButton}\n </div>\n )}\n </>\n )}\n {!loadedFile && (\n <>\n <Text typography=\"label-2-regular\">{trls.title}</Text>\n <VSpacing default={6} />\n <Text typography=\"label-4-regular\" style=\"secondary\">\n {trls.subTitle}\n </Text>\n {selectFileButton && (\n <>\n <VSpacing default={16} />\n {selectFileButton}\n </>\n )}\n </>\n )}\n </>\n )}\n </div>\n </div>\n );\n};\n\nexport { Upload };\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;AAiCA,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1B,MAAM,QAAQ,GAAG,CAAC,KAAa,KAAY;IACvC,OAAO,CAAC,KAAK,GAAG,KAAK,EAAE,OAAO,C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AAI,CAAC,WAAW,IAAI,gBAAgB,KACpDD,4BACIC,GAAC,CAAA,QAAQ,EAAC,EAAA,OAAO,EAAE,EAAE,EAAI,CAAA,EACxB,gBAAgB,CAAA,EAAA,CAClB,CACN,EACA,CAAC,UAAU,CAAC,OAAO,IAAI,WAAW,KAAK,kBAAkB,IAAI,gBAAgB,CAAC,KAC3ED,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,aAAa,EAAA,QAAA,EAAA,CAC/B,kBAAkB,EAClB,gBAAgB,CAAA,EAAA,CACf,CACT,CAAA,EAAA,CACF,CACN,EACA,CAAC,UAAU,KACRA,4BACIC,GAAC,CAAA,IAAI,EAAC,EAAA,UAAU,EAAC,iBAAiB,EAAE,QAAA,EAAA,IAAI,CAAC,KAAK,EAAQ,CAAA,EACtDA,GAAC,CAAA,QAAQ,IAAC,OAAO,EAAE,CAAC,EAAA,CAAI,EACxBA,GAAA,CAAC,IAAI,EAAA,EAAC,UAAU,EAAC,iBAAiB,EAAC,KAAK,EAAC,WAAW,EAC/C,QAAA,EAAA,IAAI,CAAC,QAAQ,EACX,CAAA,EACN,gBAAgB,KACbD,IAAA,CAAAE,QAAA,EAAA,EAAA,QAAA,EAAA,CACID,GAAC,CAAA,QAAQ,EAAC,EAAA,OAAO,EAAE,EAAE,EAAI,CAAA,EACxB,gBAAgB,CAAA,EAAA,CAClB,CACN,CAAA,EAAA,CACF,CACN,CAAA,EAAA,CACF,CACN,CAAA,EAAA,CACC,CACJ,EAAA,CAAA,EACR;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"Upload.js","sources":["../src/Upload.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { MultiUpload } from '@hh.ru/magritte-ui-upload/MultiUpload';\nimport { SingleUpload } from '@hh.ru/magritte-ui-upload/SingleUpload';\nimport { UploadProps } from '@hh.ru/magritte-ui-upload/types';\n\nconst Upload = ({ multiple, ...uploadProps }: UploadProps): ReactElement => {\n if (multiple) {\n return <MultiUpload multiple={true} size=\"medium\" {...uploadProps} />;\n }\n return <SingleUpload multiple={false} {...uploadProps} />;\n};\n\nexport { Upload };\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAMM,MAAA,MAAM,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAe,KAAkB;IACvE,IAAI,QAAQ,EAAE;AACV,QAAA,OAAOA,GAAC,CAAA,WAAW,EAAC,EAAA,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAC,QAAQ,EAAK,GAAA,WAAW,GAAI,CAAC;KACzE;IACD,OAAOA,GAAA,CAAC,YAAY,EAAC,EAAA,QAAQ,EAAE,KAAK,EAAA,GAAM,WAAW,EAAA,CAAI,CAAC;AAC9D;;;;"}
|