siam-ui-utils 2.1.8 → 2.1.10
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/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/dropzone-uploader/index.jsx +50 -58
- package/src/index.js +6 -6
- package/src/{dropzone-uploader → stories}/DropzoneUploader.stories.tsx +1 -1
- package/src/{tomar-foto → stories}/TomarFoto.stories.tsx +10 -10
- package/src/tomar-foto/index.jsx +61 -62
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react/prop-types */
|
|
2
1
|
import React, { useEffect, useState } from 'react';
|
|
3
2
|
import { getDroppedOrSelectedFiles } from 'html5-file-selector';
|
|
4
3
|
import Dropzone from 'react-dropzone-uploader';
|
|
@@ -8,9 +7,16 @@ import IconButtonSvg from '../iconos/icon-button-svg';
|
|
|
8
7
|
import { pdfImage } from '../constants-svg';
|
|
9
8
|
import './dropzone-uploader.css';
|
|
10
9
|
|
|
11
|
-
console.log('dropzone1 :>> ');
|
|
12
|
-
|
|
13
10
|
const maxSize = 7; //en MB
|
|
11
|
+
|
|
12
|
+
const getFilesFromEvent = (e) => {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
getDroppedOrSelectedFiles(e).then((chosenFiles) => {
|
|
15
|
+
resolve(chosenFiles.map((f) => f.fileObject));
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
14
20
|
export const DropzoneUploader = ({
|
|
15
21
|
onChangeFiles,
|
|
16
22
|
totalFiles,
|
|
@@ -20,40 +26,34 @@ export const DropzoneUploader = ({
|
|
|
20
26
|
nameFileLabel = 'Subir archivos',
|
|
21
27
|
maxFileSize = maxSize,
|
|
22
28
|
}) => {
|
|
23
|
-
console.log('dropzone2 :>> ');
|
|
24
|
-
|
|
25
29
|
const [files, setFiles] = useState([]);
|
|
26
30
|
const [totalFilesDU, setTotalFilesDU] = useState(totalFiles);
|
|
27
|
-
const handleChangeStatus = ({ file }, status) => {
|
|
28
|
-
if (status == 'done') {
|
|
29
|
-
const filesTemp = files;
|
|
30
|
-
filesTemp.push(file);
|
|
31
|
-
setFiles(filesTemp);
|
|
32
|
-
onChangeFiles(files);
|
|
33
|
-
setTotalFilesDU(files.length);
|
|
34
|
-
} else if (status == 'removed') {
|
|
35
|
-
const filesTemp = files;
|
|
36
|
-
const index = files.indexOf(file);
|
|
37
|
-
if (index > -1) {
|
|
38
|
-
filesTemp.splice(index, 1);
|
|
39
|
-
}
|
|
40
|
-
setFiles(filesTemp);
|
|
41
|
-
onChangeFiles(files);
|
|
42
|
-
setTotalFilesDU(files.length);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const getFilesFromEvent = (e) => {
|
|
46
|
-
console.log('dropzone3 :>> ');
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
const Input = ({ accept, onFiles, getFilesFromEvent }) => {
|
|
33
|
+
const text =
|
|
34
|
+
totalFilesDU > 0
|
|
35
|
+
? `${maxFiles - totalFilesDU} archivo/s más`
|
|
36
|
+
: nameFileLabel;
|
|
37
|
+
return (
|
|
38
|
+
<label className="dropzone-upload-button">
|
|
39
|
+
{text}
|
|
40
|
+
<input
|
|
41
|
+
style={{ display: 'none' }}
|
|
42
|
+
type="file"
|
|
43
|
+
accept={accept}
|
|
44
|
+
capture={capture}
|
|
45
|
+
multiple
|
|
46
|
+
onChange={(e) => {
|
|
47
|
+
getFilesFromEvent(e).then((chosenFiles) => {
|
|
48
|
+
onFiles(chosenFiles);
|
|
49
|
+
});
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
</label>
|
|
53
|
+
);
|
|
53
54
|
};
|
|
54
|
-
const CustomPreview = ({ fileWithMeta }) => {
|
|
55
|
-
console.log('dropzone4 :>> ');
|
|
56
55
|
|
|
56
|
+
const CustomPreview = ({ fileWithMeta }) => {
|
|
57
57
|
const { meta, remove } = fileWithMeta;
|
|
58
58
|
if (meta.size / (1024 * 1024) > maxFileSize) {
|
|
59
59
|
NotificationManager.error(
|
|
@@ -103,37 +103,29 @@ export const DropzoneUploader = ({
|
|
|
103
103
|
);
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
getFilesFromEvent(e).then((chosenFiles) => {
|
|
124
|
-
onFiles(chosenFiles);
|
|
125
|
-
});
|
|
126
|
-
}}
|
|
127
|
-
/>
|
|
128
|
-
</label>
|
|
129
|
-
);
|
|
106
|
+
const handleChangeStatus = ({ file }, status) => {
|
|
107
|
+
if (status == 'done') {
|
|
108
|
+
const filesTemp = files;
|
|
109
|
+
filesTemp.push(file);
|
|
110
|
+
setFiles(filesTemp);
|
|
111
|
+
onChangeFiles(files);
|
|
112
|
+
setTotalFilesDU(files.length);
|
|
113
|
+
} else if (status == 'removed') {
|
|
114
|
+
const filesTemp = files;
|
|
115
|
+
const index = files.indexOf(file);
|
|
116
|
+
if (index > -1) {
|
|
117
|
+
filesTemp.splice(index, 1);
|
|
118
|
+
}
|
|
119
|
+
setFiles(filesTemp);
|
|
120
|
+
onChangeFiles(files);
|
|
121
|
+
setTotalFilesDU(files.length);
|
|
122
|
+
}
|
|
130
123
|
};
|
|
124
|
+
|
|
131
125
|
useEffect(() => {
|
|
132
126
|
setTotalFilesDU(totalFiles);
|
|
133
127
|
}, [totalFiles]);
|
|
134
128
|
|
|
135
|
-
console.log('dropzone5 :>> ');
|
|
136
|
-
|
|
137
129
|
return (
|
|
138
130
|
<>
|
|
139
131
|
<Dropzone
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
1
|
+
export * from './dropzone-uploader';
|
|
2
|
+
export * from './bridges';
|
|
3
|
+
export * from './CustomBootstrap';
|
|
4
|
+
export * from './CustomSelectInput';
|
|
5
|
+
export * from './IntlMessages';
|
|
6
|
+
export * from './tomar-foto';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
|
|
3
|
-
import { TomarFoto } from '
|
|
3
|
+
import { TomarFoto } from '../tomar-foto';
|
|
4
4
|
|
|
5
5
|
const meta = {
|
|
6
6
|
title: 'Components/TomarFoto',
|
|
7
7
|
component: TomarFoto,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
args: {
|
|
9
|
+
onFilesSelectedSelfie: () => {},
|
|
10
|
+
isMobile: false,
|
|
11
|
+
},
|
|
12
12
|
} satisfies Meta<typeof TomarFoto>;
|
|
13
13
|
|
|
14
14
|
export default meta;
|
|
@@ -16,14 +16,14 @@ type Story = StoryObj<typeof meta>;
|
|
|
16
16
|
|
|
17
17
|
export const TomarFotoWebApplication: Story = {
|
|
18
18
|
args: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
isMobile: false,
|
|
20
|
+
},
|
|
21
21
|
};
|
|
22
22
|
export const TomarFotoMobileApplication: Story = {
|
|
23
23
|
args: {
|
|
24
24
|
isMobile: true,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
onFilesSelectedSelfie: () => {
|
|
26
|
+
console.log('Dispatch an action');
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
};
|
package/src/tomar-foto/index.jsx
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
|
-
import React, { useState } from 'react'
|
|
3
|
-
import { Row } from 'reactstrap'
|
|
4
|
-
import { DropzoneUploader } from '../
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import imgHacerFoto from '../assets/img/take-photo.png';
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
import { Row } from 'reactstrap'
|
|
4
|
+
import { DropzoneUploader, Colxx } from '../'
|
|
5
|
+
import { TAKE_PHOTO } from '../constants'
|
|
6
|
+
import imgHacerFoto from '../assets/img/take-photo.png'
|
|
8
7
|
|
|
9
8
|
export const TomarFoto = ({ onFilesSelectedSelfie, isMobile = false }) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const [filesTotalSelectedSelfie, setTotalFilesSelectedSelfie] = useState(0)
|
|
10
|
+
const {
|
|
11
|
+
LOAD_SELFIE_WITH_IDENTITY_CARD_MESSAGE,
|
|
12
|
+
MESSAGE_SELFIE_ONLY_CAN_TAKE_FROM_CELLPHONE,
|
|
13
|
+
TAKE_PHOTO_MESSAGE,
|
|
14
|
+
} = TAKE_PHOTO
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const handleFilesSelectedSelfie = (files) => {
|
|
17
|
+
setTotalFilesSelectedSelfie(files.length)
|
|
18
|
+
onFilesSelectedSelfie(files)
|
|
19
|
+
}
|
|
21
20
|
|
|
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
|
-
}
|
|
21
|
+
return (
|
|
22
|
+
<>
|
|
23
|
+
<Row className='pt-2 ml-4'>
|
|
24
|
+
<Colxx xxs='11' md='5'>
|
|
25
|
+
{LOAD_SELFIE_WITH_IDENTITY_CARD_MESSAGE}
|
|
26
|
+
</Colxx>
|
|
27
|
+
</Row>
|
|
28
|
+
<Row className='pt-2 ml-2'>
|
|
29
|
+
<Colxx xxs='12' md='9'>
|
|
30
|
+
{isMobile ? (
|
|
31
|
+
<>
|
|
32
|
+
<Colxx xxs='12' className='text-center'>
|
|
33
|
+
{filesTotalSelectedSelfie === 0 && (
|
|
34
|
+
<img
|
|
35
|
+
style={{ width: '97%' }}
|
|
36
|
+
alt='hacerFotoDNI'
|
|
37
|
+
src={imgHacerFoto}
|
|
38
|
+
/>
|
|
39
|
+
)}
|
|
40
|
+
<DropzoneUploader
|
|
41
|
+
className='pt-2 ml-2'
|
|
42
|
+
maxFiles={1}
|
|
43
|
+
onChangeFiles={handleFilesSelectedSelfie}
|
|
44
|
+
totalFiles={filesTotalSelectedSelfie}
|
|
45
|
+
accept='image/jpg,image/jpeg'
|
|
46
|
+
capture='environment'
|
|
47
|
+
nameFileLabel={TAKE_PHOTO_MESSAGE}
|
|
48
|
+
/>
|
|
49
|
+
</Colxx>
|
|
50
|
+
</>
|
|
51
|
+
) : (
|
|
52
|
+
<h2
|
|
53
|
+
className={'view-icon iconsminds-smartphone-4 ml-2 mr-2'}
|
|
54
|
+
style={{
|
|
55
|
+
color: 'red',
|
|
56
|
+
margin: '10px 10px 0px 10px',
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{MESSAGE_SELFIE_ONLY_CAN_TAKE_FROM_CELLPHONE}
|
|
60
|
+
</h2>
|
|
61
|
+
)}
|
|
62
|
+
</Colxx>
|
|
63
|
+
</Row>
|
|
64
|
+
</>
|
|
65
|
+
)
|
|
66
|
+
}
|