code7-leia 0.1.47 → 0.1.49
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/code7-leia.cjs.development.js +126 -17
- package/dist/code7-leia.cjs.development.js.map +1 -1
- package/dist/code7-leia.cjs.production.min.js +1 -1
- package/dist/code7-leia.cjs.production.min.js.map +1 -1
- package/dist/code7-leia.esm.js +126 -17
- package/dist/code7-leia.esm.js.map +1 -1
- package/dist/components/FileArea/components/AreaUpload/index.d.ts +23 -0
- package/dist/components/FileArea/components/AreaUpload/styles.d.ts +9 -0
- package/package.json +1 -1
- package/src/components/FileArea/components/AreaUpload/index.tsx +131 -0
- package/src/components/FileArea/components/AreaUpload/styles.tsx +67 -0
- package/src/components/FileArea/index.tsx +10 -4
- package/src/components/FileArea/styles.tsx +9 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FileProperties {
|
|
3
|
+
id: number;
|
|
4
|
+
lastModified: number;
|
|
5
|
+
lastModifiedDate: Date;
|
|
6
|
+
name: string;
|
|
7
|
+
size: number;
|
|
8
|
+
type: string;
|
|
9
|
+
}
|
|
10
|
+
interface AreaUploadProps {
|
|
11
|
+
formatFile?: string;
|
|
12
|
+
multipleFile?: boolean;
|
|
13
|
+
initialFiles?: File[];
|
|
14
|
+
removeItem?: (file: FileProperties) => void;
|
|
15
|
+
setFile?: (file: {
|
|
16
|
+
content: ArrayBuffer | string;
|
|
17
|
+
properties: File;
|
|
18
|
+
}) => void;
|
|
19
|
+
onChange?: (files: File[]) => void;
|
|
20
|
+
hasListFiles?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare const AreaUpload: React.FC<AreaUploadProps>;
|
|
23
|
+
export default AreaUpload;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface ContainerProps {
|
|
3
|
+
isDragAccept?: boolean;
|
|
4
|
+
isDragReject?: boolean;
|
|
5
|
+
isDragActive?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const Container: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, ContainerProps>>;
|
|
8
|
+
export declare const ListFiles: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
|
|
9
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { getLanguage } from '../../../../utils/getLanguage'
|
|
3
|
+
import { useDropzone, FileRejection } from 'react-dropzone';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
import { Container} from './styles';
|
|
7
|
+
|
|
8
|
+
interface FileProperties {
|
|
9
|
+
id: number;
|
|
10
|
+
lastModified: number;
|
|
11
|
+
lastModifiedDate: Date;
|
|
12
|
+
name: string;
|
|
13
|
+
size: number;
|
|
14
|
+
type: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface AreaUploadProps {
|
|
18
|
+
formatFile?: string;
|
|
19
|
+
multipleFile?: boolean;
|
|
20
|
+
initialFiles?: File[];
|
|
21
|
+
removeItem?: (file: FileProperties) => void;
|
|
22
|
+
setFile?: (file: { content: ArrayBuffer | string; properties: File }) => void;
|
|
23
|
+
onChange?: (files: File[]) => void;
|
|
24
|
+
hasListFiles?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const AreaUpload: React.FC<AreaUploadProps> = ({
|
|
28
|
+
formatFile = 'application/pdf',
|
|
29
|
+
multipleFile = false,
|
|
30
|
+
initialFiles = [],
|
|
31
|
+
setFile = () => {},
|
|
32
|
+
onChange = () => {},
|
|
33
|
+
}) => {
|
|
34
|
+
const [myFiles, setMyFiles] = useState<File[]>([]);
|
|
35
|
+
const t = getLanguage('pt-br')
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setMyFiles([...initialFiles, ...myFiles]);
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const onDrop = useCallback(
|
|
42
|
+
(acceptedFiles: File[], fileRejections: FileRejection[]) => {
|
|
43
|
+
if (fileRejections && fileRejections.length > 0) {
|
|
44
|
+
console.error('Arquivos rejeitados:', fileRejections);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onChange(acceptedFiles);
|
|
48
|
+
|
|
49
|
+
const files = [...myFiles, ...acceptedFiles];
|
|
50
|
+
const filesWithId = files.map((item, index) => ({
|
|
51
|
+
id: index + 1,
|
|
52
|
+
lastModified: item.lastModified,
|
|
53
|
+
name: item.name,
|
|
54
|
+
size: item.size,
|
|
55
|
+
type: item.type,
|
|
56
|
+
}));
|
|
57
|
+
setMyFiles(filesWithId as unknown as File[]);
|
|
58
|
+
|
|
59
|
+
acceptedFiles.forEach((file) => {
|
|
60
|
+
const reader = new FileReader();
|
|
61
|
+
|
|
62
|
+
reader.onload = () => {
|
|
63
|
+
const binaryStr = reader.result;
|
|
64
|
+
setFile({ content: binaryStr as ArrayBuffer, properties: file });
|
|
65
|
+
};
|
|
66
|
+
reader.readAsArrayBuffer(file);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
[myFiles]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
getRootProps,
|
|
74
|
+
getInputProps,
|
|
75
|
+
open,
|
|
76
|
+
isDragActive,
|
|
77
|
+
isDragAccept,
|
|
78
|
+
isDragReject,
|
|
79
|
+
} = useDropzone({
|
|
80
|
+
accept: formatFile as any,
|
|
81
|
+
noClick: true,
|
|
82
|
+
noKeyboard: true,
|
|
83
|
+
multiple: multipleFile,
|
|
84
|
+
onDrop,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<>
|
|
89
|
+
{multipleFile || myFiles?.length === 0 ? (
|
|
90
|
+
<Container
|
|
91
|
+
{...getRootProps({ isDragActive, isDragAccept, isDragReject })}
|
|
92
|
+
>
|
|
93
|
+
<input {...getInputProps()} />
|
|
94
|
+
|
|
95
|
+
<span>
|
|
96
|
+
<p>
|
|
97
|
+
{t.fileArea.modal.descriptionUpload}
|
|
98
|
+
</p>
|
|
99
|
+
</span>
|
|
100
|
+
<button type="button" onClick={open}>
|
|
101
|
+
{t.fileArea.modal.chooseFile}
|
|
102
|
+
</button>
|
|
103
|
+
</Container>
|
|
104
|
+
) : (
|
|
105
|
+
''
|
|
106
|
+
)}
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
AreaUpload.propTypes = {
|
|
112
|
+
formatFile: PropTypes.string,
|
|
113
|
+
multipleFile: PropTypes.bool,
|
|
114
|
+
initialFiles: PropTypes.arrayOf(PropTypes.object as any),
|
|
115
|
+
removeItem: PropTypes.func,
|
|
116
|
+
setFile: PropTypes.func,
|
|
117
|
+
onChange: PropTypes.func,
|
|
118
|
+
hasListFiles: PropTypes.bool,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
AreaUpload.defaultProps = {
|
|
122
|
+
formatFile: 'application/json',
|
|
123
|
+
multipleFile: false,
|
|
124
|
+
initialFiles: [],
|
|
125
|
+
removeItem: () => {},
|
|
126
|
+
setFile: () => {},
|
|
127
|
+
onChange: () => {},
|
|
128
|
+
hasListFiles: true,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default AreaUpload;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
interface ContainerProps {
|
|
4
|
+
isDragAccept?: boolean;
|
|
5
|
+
isDragReject?: boolean;
|
|
6
|
+
isDragActive?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getColor = (props: ContainerProps) => {
|
|
10
|
+
if (props.isDragAccept) {
|
|
11
|
+
return '#6690ff';
|
|
12
|
+
}
|
|
13
|
+
if (props.isDragReject) {
|
|
14
|
+
return '#e18976';
|
|
15
|
+
}
|
|
16
|
+
if (props.isDragActive) {
|
|
17
|
+
return '#6690ff';
|
|
18
|
+
}
|
|
19
|
+
return '#979aa5';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const Container = styled.div<ContainerProps>`
|
|
23
|
+
background-color: #f3f5f9;
|
|
24
|
+
flex: 1;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
padding: 20px;
|
|
29
|
+
border-width: 2px;
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
border-color: var(${(props) => getColor(props)});
|
|
32
|
+
border-style: dashed;
|
|
33
|
+
color: #5a5d68;
|
|
34
|
+
outline: none;
|
|
35
|
+
transition: border 0.24s ease-in-out;
|
|
36
|
+
|
|
37
|
+
& > span {
|
|
38
|
+
margin: 8px 10px 0 0;
|
|
39
|
+
display: flex;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
export const ListFiles = styled.div`
|
|
44
|
+
&.horizontal-itens {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: row;
|
|
47
|
+
flex-wrap: wrap;
|
|
48
|
+
|
|
49
|
+
& button {
|
|
50
|
+
margin: 4px;
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.tag-file {
|
|
55
|
+
display: flex;
|
|
56
|
+
gap: 8px;
|
|
57
|
+
padding: 10px 24px !important;
|
|
58
|
+
color: #102693 !important;
|
|
59
|
+
font-size: 14px;
|
|
60
|
+
letter-spacing: 0px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.tag-icon {
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
@@ -18,10 +18,12 @@ import ModalFooter from './components/Modal/ModalFooter'
|
|
|
18
18
|
import ModalContent from './components/Modal/ModalContent'
|
|
19
19
|
import EmptyState from '../EmptyState';
|
|
20
20
|
import Select from '../Select'
|
|
21
|
+
import AreaUpload from './components/AreaUpload';
|
|
21
22
|
|
|
22
23
|
export const FileArea = () => {
|
|
23
24
|
const [files, setFiles] = useState<FileData[]>([]);
|
|
24
25
|
const [initialFiles, setInitialFiles] = useState<FileData[]>([]);
|
|
26
|
+
const [uploadFile, setUploadFile] = useState<{ content: ArrayBuffer | string; properties: File }>();
|
|
25
27
|
const { pathname } = useLocation();
|
|
26
28
|
const [modal, setModal] = useState(false)
|
|
27
29
|
const id = pathname.split('/')[4]
|
|
@@ -99,6 +101,7 @@ export const FileArea = () => {
|
|
|
99
101
|
|
|
100
102
|
const handleSelect = (value: string | number) => {
|
|
101
103
|
console.log(value);
|
|
104
|
+
console.log(uploadFile);
|
|
102
105
|
};
|
|
103
106
|
|
|
104
107
|
const renderFiles = () => {
|
|
@@ -163,12 +166,15 @@ export const FileArea = () => {
|
|
|
163
166
|
title={t.fileArea.modal.uploadFile}
|
|
164
167
|
>
|
|
165
168
|
<ModalContent>
|
|
166
|
-
<div>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
<div className='choose-file'>
|
|
170
|
+
<AreaUpload
|
|
171
|
+
setFile={setUploadFile}
|
|
172
|
+
/>
|
|
173
|
+
</div>
|
|
174
|
+
<div className='presset'>
|
|
169
175
|
<p>Presset</p>
|
|
170
176
|
<Select placeholder={t.testArea.selectPresset} options={optionsPresset} onSelect={handleSelect} />
|
|
171
|
-
</div>
|
|
177
|
+
</div>
|
|
172
178
|
</ModalContent>
|
|
173
179
|
<ModalFooter>
|
|
174
180
|
<button className='button cancel' onClick={handleOpenModal}>
|
|
@@ -32,9 +32,9 @@ export const Container = styled.div`
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
.button {
|
|
35
|
-
padding: 8px
|
|
36
|
-
border-radius: 4px
|
|
37
|
-
gap: 10px
|
|
35
|
+
padding: 8px 16px 8px 16px;
|
|
36
|
+
border-radius: 4px;
|
|
37
|
+
gap: 10px;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
.cancel {
|
|
@@ -46,6 +46,12 @@ export const Container = styled.div`
|
|
|
46
46
|
background: #102693;
|
|
47
47
|
color: white;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
.presset {
|
|
51
|
+
padding-top: 10px;
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
}
|
|
49
55
|
`;
|
|
50
56
|
|
|
51
57
|
export const Header = styled.div`
|