siam-ui-utils 2.1.0 → 2.1.2

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.
@@ -1,17 +1,17 @@
1
- import type { StorybookConfig } from '@storybook/react-vite';
2
-
3
- const config: StorybookConfig = {
4
- stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5
- addons: [
6
- '@storybook/addon-onboarding',
7
- '@storybook/addon-links',
8
- '@storybook/addon-essentials',
9
- '@chromatic-com/storybook',
10
- '@storybook/addon-interactions',
11
- ],
12
- framework: {
13
- name: '@storybook/react-vite',
14
- options: {},
15
- },
16
- };
17
- export default config;
1
+ import type { StorybookConfig } from '@storybook/react-vite';
2
+
3
+ const config: StorybookConfig = {
4
+ stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5
+ addons: [
6
+ '@storybook/addon-onboarding',
7
+ '@storybook/addon-links',
8
+ '@storybook/addon-essentials',
9
+ '@chromatic-com/storybook',
10
+ '@storybook/addon-interactions',
11
+ ],
12
+ framework: {
13
+ name: '@storybook/react-vite',
14
+ options: {},
15
+ },
16
+ };
17
+ export default config;
@@ -1,16 +1,16 @@
1
- import type { Preview } from '@storybook/react';
2
- import "./css/bootstrap.min.css";
3
- import "./css/bootstrap.rtl.only.min.css";
4
-
5
- const preview: Preview = {
6
- parameters: {
7
- controls: {
8
- matchers: {
9
- color: /(background|color)$/i,
10
- date: /Date$/i,
11
- },
12
- },
13
- },
14
- };
15
-
16
- export default preview;
1
+ import type { Preview } from '@storybook/react';
2
+ import "./css/bootstrap.min.css";
3
+ import "./css/bootstrap.rtl.only.min.css";
4
+
5
+ const preview: Preview = {
6
+ parameters: {
7
+ controls: {
8
+ matchers: {
9
+ color: /(background|color)$/i,
10
+ date: /Date$/i,
11
+ },
12
+ },
13
+ },
14
+ };
15
+
16
+ export default preview;
package/package.json CHANGED
@@ -1,87 +1,87 @@
1
- {
2
- "name": "siam-ui-utils",
3
- "version": "2.1.0",
4
- "keywords": [
5
- "ampf-react",
6
- "ampf-utils",
7
- "siam-ui-utils"
8
- ],
9
- "type": "module",
10
- "author": "Ampf Development Team",
11
- "license": "MIT",
12
- "description": "Conjunto de librerias de componentes utiles para AMPF",
13
- "main": "src/index.js",
14
- "browser": "src/index.js",
15
- "types": "index",
16
- "homepage": "https://github.com/ampfgit/siam-ui-utils#readme",
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/ampfgit/siam-ui-utils"
20
- },
21
- "moduleResolution": "nodenext",
22
- "scripts": {
23
- "start": "vite",
24
- "publish-npm": "npm publish",
25
- "storybook": "storybook dev -p 6006",
26
- "build-storybook": "storybook build"
27
- },
28
- "dependencies": {
29
- "@storybook/cli": "^8.3.2",
30
- "@types/react-intl": "^3.0.0",
31
- "eslint-plugin-react-hooks": "^4.6.2",
32
- "eslint-plugin-react-refresh": "^0.4.12",
33
- "html5-file-selector": "^2.1.0",
34
- "init": "^0.1.2",
35
- "prop-types": "^15.8.1",
36
- "react": "^18.3.1",
37
- "react-dropzone-uploader": "^2.11.0",
38
- "react-intl": "^6.4.2",
39
- "react-notifications": "^1.7.4",
40
- "react-router": "^6.26.2",
41
- "react-router-dom": "^6.26.2",
42
- "react-select": "^5.8.0",
43
- "reactstrap": "^9.2.2",
44
- "siam-utils": "^1.1.4",
45
- "source-map-loader": "^5.0.0",
46
- "styled-components": "^6.1.12",
47
- "typescript": "^5.5.4",
48
- "vite-plugin-commonjs": "^0.10.3"
49
- },
50
- "devDependencies": {
51
- "@chromatic-com/storybook": "^1.9.0",
52
- "@storybook/addon-essentials": "^8.3.2",
53
- "@storybook/addon-interactions": "^8.3.2",
54
- "@storybook/addon-links": "^8.3.2",
55
- "@storybook/addon-onboarding": "^8.3.2",
56
- "@storybook/blocks": "^8.3.2",
57
- "@storybook/react": "^8.3.2",
58
- "@storybook/react-vite": "^8.3.2",
59
- "@storybook/test": "^8.3.2",
60
- "@testing-library/dom": "^10.4.0",
61
- "@testing-library/jest-dom": "^6.4.8",
62
- "@testing-library/react": "^16.0.0",
63
- "@types/react-router-dom": "^5.3.3",
64
- "@typescript-eslint/eslint-plugin": "^5.0.0",
65
- "@typescript-eslint/parser": "^5.0.0",
66
- "@vitejs/plugin-react": "^4.3.1",
67
- "copyfiles": "^2.4.1",
68
- "eslint": "^8.57.1",
69
- "eslint-config-airbnb": "^19.0.4",
70
- "eslint-config-prettier": "^8.8.0",
71
- "eslint-config-react-app": "^7.0.1",
72
- "eslint-plugin-import": "^2.27.5",
73
- "eslint-plugin-jsx-a11y": "^6.7.1",
74
- "eslint-plugin-prettier": "^5.0.0-alpha.1",
75
- "eslint-plugin-react": "^7.33.0",
76
- "eslint-plugin-storybook": "^0.8.0",
77
- "storybook": "^8.3.2",
78
- "vite": "^5.3.4",
79
- "vite-plugin-eslint": "^1.8.1",
80
- "vitest": "^2.0.5"
81
- },
82
- "eslintConfig": {
83
- "extends": [
84
- "plugin:storybook/recommended"
85
- ]
86
- }
87
- }
1
+ {
2
+ "name": "siam-ui-utils",
3
+ "version": "2.1.2",
4
+ "keywords": [
5
+ "ampf-react",
6
+ "ampf-utils",
7
+ "siam-ui-utils"
8
+ ],
9
+ "type": "module",
10
+ "author": "Ampf Development Team",
11
+ "license": "MIT",
12
+ "description": "Conjunto de librerias de componentes utiles para AMPF",
13
+ "main": "src/index.js",
14
+ "browser": "src/index.js",
15
+ "types": "index",
16
+ "homepage": "https://github.com/ampfgit/siam-ui-utils#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/ampfgit/siam-ui-utils"
20
+ },
21
+ "moduleResolution": "nodenext",
22
+ "scripts": {
23
+ "start": "vite",
24
+ "publish-npm": "npm publish",
25
+ "storybook": "storybook dev -p 6006",
26
+ "build-storybook": "storybook build"
27
+ },
28
+ "dependencies": {
29
+ "@storybook/cli": "^8.3.2",
30
+ "@types/react-intl": "^3.0.0",
31
+ "eslint-plugin-react-hooks": "^4.6.2",
32
+ "eslint-plugin-react-refresh": "^0.4.12",
33
+ "html5-file-selector": "^2.1.0",
34
+ "init": "^0.1.2",
35
+ "prop-types": "^15.8.1",
36
+ "react": "^18.3.1",
37
+ "react-dropzone-uploader": "^2.11.0",
38
+ "react-intl": "^6.4.2",
39
+ "react-notifications": "^1.7.4",
40
+ "react-router": "^6.26.2",
41
+ "react-router-dom": "^6.26.2",
42
+ "react-select": "^5.8.0",
43
+ "reactstrap": "^9.2.2",
44
+ "siam-utils": "^1.1.4",
45
+ "source-map-loader": "^5.0.0",
46
+ "styled-components": "^6.1.12",
47
+ "typescript": "^5.5.4",
48
+ "vite-plugin-commonjs": "^0.10.3"
49
+ },
50
+ "devDependencies": {
51
+ "@chromatic-com/storybook": "^1.9.0",
52
+ "@storybook/addon-essentials": "^8.3.2",
53
+ "@storybook/addon-interactions": "^8.3.2",
54
+ "@storybook/addon-links": "^8.3.2",
55
+ "@storybook/addon-onboarding": "^8.3.2",
56
+ "@storybook/blocks": "^8.3.2",
57
+ "@storybook/react": "^8.3.2",
58
+ "@storybook/react-vite": "^8.3.2",
59
+ "@storybook/test": "^8.3.2",
60
+ "@testing-library/dom": "^10.4.0",
61
+ "@testing-library/jest-dom": "^6.4.8",
62
+ "@testing-library/react": "^16.0.0",
63
+ "@types/react-router-dom": "^5.3.3",
64
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
65
+ "@typescript-eslint/parser": "^5.0.0",
66
+ "@vitejs/plugin-react": "^4.3.1",
67
+ "copyfiles": "^2.4.1",
68
+ "eslint": "^8.57.1",
69
+ "eslint-config-airbnb": "^19.0.4",
70
+ "eslint-config-prettier": "^8.8.0",
71
+ "eslint-config-react-app": "^7.0.1",
72
+ "eslint-plugin-import": "^2.27.5",
73
+ "eslint-plugin-jsx-a11y": "^6.7.1",
74
+ "eslint-plugin-prettier": "^5.0.0-alpha.1",
75
+ "eslint-plugin-react": "^7.33.0",
76
+ "eslint-plugin-storybook": "^0.8.0",
77
+ "storybook": "^8.3.2",
78
+ "vite": "^5.3.4",
79
+ "vite-plugin-eslint": "^1.1.0",
80
+ "vitest": "^2.0.5"
81
+ },
82
+ "eslintConfig": {
83
+ "extends": [
84
+ "plugin:storybook/recommended"
85
+ ]
86
+ }
87
+ }
@@ -1,12 +1,10 @@
1
1
  import React from 'react';
2
2
  import { useNavigate } from 'react-router';
3
3
 
4
- const withRouter = (Component) => {
4
+ export const withRouter = (Component) => {
5
5
  const Wrapper = (props) => {
6
6
  const history = useNavigate();
7
7
  return <Component history={history} {...props} />;
8
8
  };
9
9
  return Wrapper;
10
10
  };
11
-
12
- export default withRouter;
@@ -2,31 +2,33 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
 
3
3
  import { DropzoneUploader } from '.';
4
4
 
5
- const args={
6
- onChangeFiles: () => {console.log('Dispatch an action onchange file')},
7
- totalFiles: 0,
8
- maxFiles: 3,
9
- accept : 'image/*, application/pdf',
10
- capture : null,
11
- nameFileLabel : 'Subir archivos',
12
- maxFileSize: 2
13
- }
5
+ const args = {
6
+ onChangeFiles: () => {
7
+ console.log('Accion despues de seleccionar un archivo');
8
+ },
9
+ totalFiles: 0,
10
+ maxFiles: 3,
11
+ accept: 'image/*, application/pdf',
12
+ capture: null,
13
+ nameFileLabel: 'Subir archivos',
14
+ maxFileSize: 2,
15
+ };
14
16
 
15
17
  const meta = {
16
18
  title: 'Components/DropzoneUploader',
17
19
  component: DropzoneUploader,
18
- args: {
19
- ...args
20
- },
20
+ args: {
21
+ ...args,
22
+ },
21
23
  } satisfies Meta<typeof DropzoneUploader>;
22
24
 
23
25
  export default meta;
26
+
24
27
  type Story = StoryObj<typeof meta>;
25
28
 
26
29
  export const DropzoneUploaderBasic: Story = {
27
30
  args: {
28
31
  ...args,
29
- maxFileSize: 7
30
- },
32
+ maxFileSize: 5,
33
+ },
31
34
  };
32
-
@@ -1,138 +1,150 @@
1
1
  /* eslint-disable react/prop-types */
2
- import React, { useEffect, useState } from 'react'
3
- import { getDroppedOrSelectedFiles } from 'html5-file-selector'
4
- import Dropzone from 'react-dropzone-uploader'
5
- import { NotificationManager } from 'react-notifications'
6
- import 'react-dropzone-uploader/dist/styles.css'
7
- import IconButtonSvg from '../iconos/icon-button-svg'
8
- import { pdfImage } from '../constants-svg'
9
- import "./dropzone-uploader.css"
2
+ import React, { useEffect, useState } from 'react';
3
+ import { getDroppedOrSelectedFiles } from 'html5-file-selector';
4
+ import Dropzone from 'react-dropzone-uploader';
5
+ import { NotificationManager } from 'react-notifications';
6
+ import 'react-dropzone-uploader/dist/styles.css';
7
+ import IconButtonSvg from '../iconos/icon-button-svg';
8
+ import { pdfImage } from '../constants-svg';
9
+ import './dropzone-uploader.css';
10
10
 
11
- const maxSize = 7 //en MB
11
+ console.log('dropzone1 :>> ');
12
+
13
+ const maxSize = 7; //en MB
12
14
  export const DropzoneUploader = ({
13
- onChangeFiles,
14
- totalFiles,
15
- maxFiles = 3,
16
- accept = 'image/*, application/pdf',
17
- capture = null,
18
- nameFileLabel = 'Subir archivos',
19
- maxFileSize=maxSize
15
+ onChangeFiles,
16
+ totalFiles,
17
+ maxFiles = 3,
18
+ accept = 'image/*, application/pdf',
19
+ capture = null,
20
+ nameFileLabel = 'Subir archivos',
21
+ maxFileSize = maxSize,
20
22
  }) => {
21
- const [files, setFiles] = useState([])
22
- const [totalFilesDU, setTotalFilesDU] = useState(totalFiles)
23
- const handleChangeStatus = ({ file }, status) => {
24
- if (status == 'done') {
25
- const filesTemp = files
26
- filesTemp.push(file)
27
- setFiles(filesTemp)
28
- onChangeFiles(files)
29
- setTotalFilesDU(files.length)
30
- } else if (status == 'removed') {
31
- const filesTemp = files
32
- const index = files.indexOf(file)
33
- if (index > -1) {
34
- filesTemp.splice(index, 1)
35
- }
36
- setFiles(filesTemp)
37
- onChangeFiles(files)
38
- setTotalFilesDU(files.length)
39
- }
40
- }
41
- const getFilesFromEvent = (e) => {
42
- return new Promise((resolve) => {
43
- getDroppedOrSelectedFiles(e).then((chosenFiles) => {
44
- resolve(chosenFiles.map((f) => f.fileObject))
45
- })
46
- })
47
- }
48
- const CustomPreview = ({ fileWithMeta }) => {
49
- const { meta, remove } = fileWithMeta
50
- if (meta.size / (1024 * 1024) > maxFileSize) {
51
- NotificationManager.error(
52
- 'El archivo supera el tamaño máximo',
53
- 'Advertencia'
54
- )
55
- remove()
56
- }
57
- return (
58
- <div className='dropzone-upload-previewContainer'>
59
- {meta.type === 'application/pdf' ? (
60
- <>
61
- <IconButtonSvg
62
- className='form-control flex'
63
- svg={pdfImage}
64
- svgOver={pdfImage}
65
- height='1.6rem'
66
- width='1.6rem'
67
- title={meta.name}
68
- />
69
- <p>
70
- {meta.name.length > 17
71
- ? meta.name.substring(0, 17) + '...'
72
- : meta.name}
73
- </p>
74
- </>
75
- ) : (
76
- <>
77
- <img
78
- className='dropzone-upload-previewImage'
79
- src={meta.previewUrl}
80
- alt={meta.name}
81
- />
82
- <p>
83
- {meta.name.length > 17
84
- ? meta.name.substring(0, 17) + '...'
85
- : meta.name}
86
- </p>
87
- </>
88
- )}
89
- <p>{(meta.size / 1024).toFixed(2)} .Kb</p>
90
- <button
91
- onClick={remove}
92
- className='dropzone-upload-delete-btn simple-icon-trash'
93
- ></button>
94
- </div>
95
- )
96
- }
23
+ console.log('dropzone2 :>> ');
24
+
25
+ const [files, setFiles] = useState([]);
26
+ 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
+
48
+ return new Promise((resolve) => {
49
+ getDroppedOrSelectedFiles(e).then((chosenFiles) => {
50
+ resolve(chosenFiles.map((f) => f.fileObject));
51
+ });
52
+ });
53
+ };
54
+ const CustomPreview = ({ fileWithMeta }) => {
55
+ console.log('dropzone4 :>> ');
56
+
57
+ const { meta, remove } = fileWithMeta;
58
+ if (meta.size / (1024 * 1024) > maxFileSize) {
59
+ NotificationManager.error(
60
+ 'El archivo supera el tamaño máximo',
61
+ 'Advertencia',
62
+ );
63
+ remove();
64
+ }
65
+ return (
66
+ <div className="dropzone-upload-previewContainer">
67
+ {meta.type === 'application/pdf' ? (
68
+ <>
69
+ <IconButtonSvg
70
+ className="form-control flex"
71
+ svg={pdfImage}
72
+ svgOver={pdfImage}
73
+ height="1.6rem"
74
+ width="1.6rem"
75
+ title={meta.name}
76
+ />
77
+ <p>
78
+ {meta.name.length > 17
79
+ ? meta.name.substring(0, 17) + '...'
80
+ : meta.name}
81
+ </p>
82
+ </>
83
+ ) : (
84
+ <>
85
+ <img
86
+ className="dropzone-upload-previewImage"
87
+ src={meta.previewUrl}
88
+ alt={meta.name}
89
+ />
90
+ <p>
91
+ {meta.name.length > 17
92
+ ? meta.name.substring(0, 17) + '...'
93
+ : meta.name}
94
+ </p>
95
+ </>
96
+ )}
97
+ <p>{(meta.size / 1024).toFixed(2)} .Kb</p>
98
+ <button
99
+ onClick={remove}
100
+ className="dropzone-upload-delete-btn simple-icon-trash"
101
+ ></button>
102
+ </div>
103
+ );
104
+ };
105
+
106
+ const Input = ({ accept, onFiles, getFilesFromEvent }) => {
107
+ console.log('dropzone4 :>> ');
108
+
109
+ const text =
110
+ totalFilesDU > 0
111
+ ? `${maxFiles - totalFilesDU} archivo/s más`
112
+ : nameFileLabel;
113
+ return (
114
+ <label className="dropzone-upload-button">
115
+ {text}
116
+ <input
117
+ style={{ display: 'none' }}
118
+ type="file"
119
+ accept={accept}
120
+ capture={capture}
121
+ multiple
122
+ onChange={(e) => {
123
+ getFilesFromEvent(e).then((chosenFiles) => {
124
+ onFiles(chosenFiles);
125
+ });
126
+ }}
127
+ />
128
+ </label>
129
+ );
130
+ };
131
+ useEffect(() => {
132
+ setTotalFilesDU(totalFiles);
133
+ }, [totalFiles]);
97
134
 
98
- const Input = ({ accept, onFiles, getFilesFromEvent }) => {
99
- const text =
100
- totalFilesDU > 0
101
- ? `${maxFiles - totalFilesDU} archivo/s más`
102
- : nameFileLabel
103
- return (
104
- <label className='dropzone-upload-button'>
105
- {text}
106
- <input
107
- style={{ display: 'none' }}
108
- type='file'
109
- accept={accept}
110
- capture={capture}
111
- multiple
112
- onChange={(e) => {
113
- getFilesFromEvent(e).then((chosenFiles) => {
114
- onFiles(chosenFiles)
115
- })
116
- }}
117
- />
118
- </label>
119
- )
120
- }
121
- useEffect(() => {
122
- setTotalFilesDU(totalFiles)
123
- }, [totalFiles])
135
+ console.log('dropzone5 :>> ');
124
136
 
125
- return (
126
- <Dropzone
127
- disableUpload={false}
128
- maxFiles={totalFilesDU < maxFiles ? maxFiles : 0}
129
- maxSize={maxFileSize} // en megas
130
- InputComponent={Input}
131
- PreviewComponent={CustomPreview}
132
- classNames={{ dropzone: 'dropzone-upload-frame' }}
133
- onChangeStatus={handleChangeStatus}
134
- getFilesFromEvent={getFilesFromEvent}
135
- accept={accept}
136
- />
137
- )
138
- }
137
+ return (
138
+ <Dropzone
139
+ disableUpload={false}
140
+ maxFiles={totalFilesDU < maxFiles ? maxFiles : 0}
141
+ maxSize={maxFileSize} // 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
+ );
150
+ };
package/src/index.js CHANGED
@@ -1,7 +1,6 @@
1
- export * from './dropzone-uploader'
2
- export * from './bridges'
3
- export * from './CustomBootstrap'
4
- export * from './CustomSelectInput'
5
- export * from "./iconos"
6
- export * from './IntlMessages'
7
- export * from './tomar-foto'
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';
package/vite.config.ts CHANGED
@@ -3,12 +3,8 @@ import { defineConfig } from "vitest/config";
3
3
  import eslint from 'vite-plugin-eslint';
4
4
 
5
5
  export default defineConfig({
6
- plugins: [react(), eslint()],
6
+ plugins: [react()],
7
7
  test: {
8
8
  globals: true,
9
- },
10
- server: {
11
- port: 3002,
12
- open: true,
13
- },
9
+ }
14
10
  });