siam-ui-utils 2.0.18 → 2.0.20
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/package.json
CHANGED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { Button } from 'reactstrap'
|
|
5
|
+
|
|
6
|
+
import { getDroppedOrSelectedFiles } from 'html5-file-selector'
|
|
7
|
+
import Dropzone from 'react-dropzone-uploader'
|
|
8
|
+
import 'react-dropzone-uploader/dist/styles.css'
|
|
9
|
+
import { NotificationManager } from 'react-notifications'
|
|
10
|
+
import { pdfImage, IconButtonSvg } from '../../iconos'
|
|
11
|
+
import '../dropzone-uploader.css'
|
|
12
|
+
|
|
13
|
+
export const DropzoneUploaderDniDigital = ({
|
|
14
|
+
accept = 'image/*, application/pdf',
|
|
15
|
+
classNames = '',
|
|
16
|
+
onChangeFiles,
|
|
17
|
+
totalFiles,
|
|
18
|
+
label = 'Cargar Dni',
|
|
19
|
+
maxSize = 2,
|
|
20
|
+
}) => {
|
|
21
|
+
const [files, setFiles] = useState([])
|
|
22
|
+
|
|
23
|
+
const handleChangeStatus = ({ file }, status) => {
|
|
24
|
+
if (status === 'done') {
|
|
25
|
+
const filesTemp = [...files]
|
|
26
|
+
filesTemp.push(file)
|
|
27
|
+
setFiles(filesTemp)
|
|
28
|
+
onChangeFiles(filesTemp)
|
|
29
|
+
} else if (status === 'removed') {
|
|
30
|
+
const filesTemp = [...files]
|
|
31
|
+
const index = filesTemp.indexOf(file)
|
|
32
|
+
if (index > -1) {
|
|
33
|
+
filesTemp.splice(index, 1)
|
|
34
|
+
}
|
|
35
|
+
setFiles(filesTemp)
|
|
36
|
+
onChangeFiles(filesTemp)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getFilesFromEvent = (e) => {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
getDroppedOrSelectedFiles(e).then((chosenFiles) => {
|
|
43
|
+
resolve(chosenFiles.map((f) => f.fileObject))
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const CustomPreview = ({ fileWithMeta }) => {
|
|
49
|
+
const { meta, remove } = fileWithMeta
|
|
50
|
+
if (meta.size / (1024 * 1024) > maxSize) {
|
|
51
|
+
NotificationManager.error(
|
|
52
|
+
'El archivo supera el tamaño máximo',
|
|
53
|
+
'Advertencia'
|
|
54
|
+
)
|
|
55
|
+
remove()
|
|
56
|
+
}
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className='dropzone-upload-previewContainer'
|
|
60
|
+
style={{ width: '100%', display: 'flex', alignItems: 'center' }}
|
|
61
|
+
>
|
|
62
|
+
{meta.type === 'application/pdf' ? (
|
|
63
|
+
<>
|
|
64
|
+
<IconButtonSvg
|
|
65
|
+
className='form-control flex'
|
|
66
|
+
svg={pdfImage}
|
|
67
|
+
svgOver={pdfImage}
|
|
68
|
+
height='1.6rem'
|
|
69
|
+
width='1.6rem'
|
|
70
|
+
title={meta.name}
|
|
71
|
+
/>
|
|
72
|
+
<p style={{ paddingRight: '1rem' }}>
|
|
73
|
+
{meta.name.length > 17
|
|
74
|
+
? meta.name.substring(0, 17) + '...'
|
|
75
|
+
: meta.name}
|
|
76
|
+
</p>
|
|
77
|
+
</>
|
|
78
|
+
) : (
|
|
79
|
+
<>
|
|
80
|
+
<img
|
|
81
|
+
className='dropzone-upload-previewImage mt-1'
|
|
82
|
+
src={meta.previewUrl}
|
|
83
|
+
alt={meta.name}
|
|
84
|
+
style={{
|
|
85
|
+
width: '110px',
|
|
86
|
+
height: '110px',
|
|
87
|
+
objectFit: 'cover',
|
|
88
|
+
marginRight: '0.5rem',
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
<div className='dropzone-upload-file-name-container'>
|
|
92
|
+
<p className='dropzone-upload-file-name' title={meta.name}>
|
|
93
|
+
{meta.name}
|
|
94
|
+
</p>
|
|
95
|
+
</div>
|
|
96
|
+
</>
|
|
97
|
+
)}
|
|
98
|
+
<button
|
|
99
|
+
style={{ marginTop: '0rem' }}
|
|
100
|
+
onClick={remove}
|
|
101
|
+
className='dropzone-upload-delete-btn simple-icon-trash'
|
|
102
|
+
></button>
|
|
103
|
+
</div>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const Input = ({ accept, onFiles, getFilesFromEvent }) => {
|
|
108
|
+
const text = totalFiles > 0 ? `${2 - totalFiles} archivos más` : { label }
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
<Button
|
|
112
|
+
outline
|
|
113
|
+
block
|
|
114
|
+
size='xs'
|
|
115
|
+
className='mt-5 ml-5'
|
|
116
|
+
onClick={() => document.getElementById('fileInput').click()}
|
|
117
|
+
>
|
|
118
|
+
{text}
|
|
119
|
+
<input
|
|
120
|
+
id='fileInput'
|
|
121
|
+
style={{ display: 'none' }}
|
|
122
|
+
type='file'
|
|
123
|
+
accept={accept}
|
|
124
|
+
multiple
|
|
125
|
+
onChange={(e) => {
|
|
126
|
+
getFilesFromEvent(e).then((chosenFiles) => {
|
|
127
|
+
onFiles(chosenFiles)
|
|
128
|
+
})
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
</Button>
|
|
132
|
+
</>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div className={classNames}>
|
|
138
|
+
<Dropzone
|
|
139
|
+
disableUpload={false}
|
|
140
|
+
maxFiles={totalFiles < 2 ? 2 : 0}
|
|
141
|
+
maxSize={maxSize} // en megas
|
|
142
|
+
InputComponent={Input}
|
|
143
|
+
PreviewComponent={CustomPreview}
|
|
144
|
+
classNames={{ dropzone: 'dropzone-upload-frame' }}
|
|
145
|
+
onChangeStatus={handleChangeStatus}
|
|
146
|
+
getFilesFromEvent={getFilesFromEvent}
|
|
147
|
+
accept={accept}
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default DropzoneUploaderDniDigital
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { styled } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line react/react-in-jsx-scope
|
|
4
|
+
const IconDiv = (props) => <div {...props} />;
|
|
5
|
+
|
|
6
|
+
export const Icon = styled(IconDiv)`
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
svg {
|
|
12
|
+
margin: 0.1rem;
|
|
13
|
+
margin-right: 0.1rem;
|
|
14
|
+
margin-top: 0.1rem;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
color: red;
|
|
17
|
+
width: ${(props) => props.width || '3rem'};
|
|
18
|
+
height: ${(props) => props.height || props.width || '3rem'};
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
}
|
|
21
|
+
label {
|
|
22
|
+
display: ${(props) => props.display || 'none'};
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|