This repository was archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathFileUploadV2.tsx
More file actions
72 lines (69 loc) · 2.69 KB
/
Copy pathFileUploadV2.tsx
File metadata and controls
72 lines (69 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import styled from 'styled-components';
import { MainInterface, Main } from '@Utils/BaseStyles';
import { Button } from '@Inputs/Button/Button';
import { PanelCard } from '../PanelCard/PanelCard';
import { DropArea, IDropAreaProps } from '../DropArea/DropArea';
import { useInformativePanels } from './useInformativePanels';
import { useGetWidth } from './useGetWidth';
export interface IFileUploadV2Props
extends MainInterface,
React.HTMLAttributes<HTMLDivElement> {
/** if true, failure message will appear even after success operation; its purpose is to test the appearance of the failure message during development */
isTestIsFailure?: boolean;
/**
* function to process the file read and transformed to a base64 string; default: does nothing
* @param {string} base64String the file read and transformed to a base64 string
*/
onFile?: (base64String: string) => void;
/** time in ms of the presence of the bottom panel informing the result of the operation (sucess or failure); default value: 1500 */
messageDuration?: number;
dropAreaProps?: IDropAreaProps;
}
/**
* multiple file upload, in parallel, version 2
*/
export const FileUploadV2: React.FC<IFileUploadV2Props> = ({
isTestIsFailure = false,
onFile = (base64String: string) => null,
messageDuration = 1500,
dropAreaProps = {},
...props
}): React.ReactElement => {
const [panels, onDrop, onCancelUploading] = useInformativePanels(
isTestIsFailure,
onFile,
messageDuration,
);
const [dropAreaWidth, dropAreaRef] = useGetWidth();
return (
<FileUploadV2Container {...props}>
<DropArea
onDropHandler={onDrop}
{...dropAreaProps}
ref={dropAreaRef}
/>
{panels.map((panel) => (
<PanelCard
key={panel.name}
cancelButtonOnLoading={
<Button onClick={onCancelUploading(panel.name)}>
Cancel
</Button>
}
name={panel.name}
operationState={panel.operationState}
margin="10px 0"
style={{ width: dropAreaWidth, boxSizing: 'border-box' }}
/>
))}
</FileUploadV2Container>
);
};
const FileUploadV2Container = styled.div<MainInterface>`
background-color: ${({ theme }) => theme.colors.background};
border-radius: ${({ theme }) => theme.dimensions.radius};
width: fit-content;
${({ theme, ...props }): string =>
Main({ padding: theme.dimensions.padding.container, ...props })}
`;