siam-ui-utils 2.0.25 → 2.0.26

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siam-ui-utils",
3
- "version": "2.0.25",
3
+ "version": "2.0.26",
4
4
  "keywords": [
5
5
  "ampf-react",
6
6
  "ampf-utils",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@types/react-intl": "^3.0.0",
27
+ "events": "^3.3.0",
27
28
  "html5-file-selector": "^2.1.0",
28
29
  "prop-types": "^15.8.1",
29
30
  "react": "^18.3.1",
@@ -46,9 +47,14 @@
46
47
  "@testing-library/react": "^16.0.0",
47
48
  "@types/react-router-dom": "^5.3.3",
48
49
  "@typescript-eslint/parser": "^8.2.0",
49
- "@vitejs/plugin-react": "^4.3.1",
50
50
  "copyfiles": "^2.4.1",
51
- "eslint": "^8.57.0",
51
+ "@eslint/js": "^9.9.0",
52
+ "@types/react": "^18.3.3",
53
+ "@types/react-dom": "^18.3.0",
54
+ "@vitejs/plugin-react": "^4.3.1",
55
+ "eslint": "^9.9.0",
56
+ "eslint-plugin-react-hooks": "^5.1.0-rc.0",
57
+ "eslint-plugin-react-refresh": "^0.4.9",
52
58
  "eslint-config-airbnb": "^19.0.4",
53
59
  "eslint-config-prettier": "^8.8.0",
54
60
  "eslint-config-react-app": "^7.0.1",
package/src/App.css ADDED
@@ -0,0 +1,42 @@
1
+ #root {
2
+ max-width: 1280px;
3
+ margin: 0 auto;
4
+ padding: 2rem;
5
+ text-align: center;
6
+ }
7
+
8
+ .logo {
9
+ height: 6em;
10
+ padding: 1.5em;
11
+ will-change: filter;
12
+ transition: filter 300ms;
13
+ }
14
+ .logo:hover {
15
+ filter: drop-shadow(0 0 2em #646cffaa);
16
+ }
17
+ .logo.react:hover {
18
+ filter: drop-shadow(0 0 2em #61dafbaa);
19
+ }
20
+
21
+ @keyframes logo-spin {
22
+ from {
23
+ transform: rotate(0deg);
24
+ }
25
+ to {
26
+ transform: rotate(360deg);
27
+ }
28
+ }
29
+
30
+ @media (prefers-reduced-motion: no-preference) {
31
+ a:nth-of-type(2) .logo {
32
+ animation: logo-spin infinite 20s linear;
33
+ }
34
+ }
35
+
36
+ .card {
37
+ padding: 2em;
38
+ }
39
+
40
+ .read-the-docs {
41
+ color: #888;
42
+ }
package/src/App.jsx CHANGED
@@ -5,10 +5,17 @@ import {
5
5
  AccordionHeader,
6
6
  AccordionItem,
7
7
  } from 'reactstrap';
8
- import { TomarFoto, DropzoneUploader, DropzoneUploaderDniDigital } from './';
8
+ import {
9
+ TomarFoto,
10
+ DropzoneUploader,
11
+ DropzoneUploaderDniDigital,
12
+ NotificationContainer,
13
+ } from './';
14
+ import './index.css';
15
+ import './App.css';
9
16
  import './assets/css/vendor/bootstrap.min.css';
10
17
 
11
- function App() {
18
+ const App = () => {
12
19
  const [open, setOpen] = useState('0');
13
20
  const toggle = (id) => {
14
21
  if (open === id) {
@@ -20,6 +27,7 @@ function App() {
20
27
 
21
28
  return (
22
29
  <div>
30
+ <NotificationContainer />
23
31
  <Accordion open={open} toggle={toggle}>
24
32
  <AccordionItem>
25
33
  <AccordionHeader targetId="1">Tomar Foto</AccordionHeader>
@@ -56,7 +64,7 @@ function App() {
56
64
  <AccordionBody accordionId="3">
57
65
  <DropzoneUploaderDniDigital
58
66
  totalFiles={0}
59
- maxFiles={1}
67
+ maxFiles={2}
60
68
  onChangeFiles={() => {
61
69
  console.log('onChange');
62
70
  }}
@@ -66,6 +74,6 @@ function App() {
66
74
  </Accordion>
67
75
  </div>
68
76
  );
69
- }
77
+ };
70
78
 
71
79
  export default App;
@@ -1,153 +1,152 @@
1
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'
2
+ import { useState } from 'react';
3
+ import { Button } from 'reactstrap';
4
+ import { getDroppedOrSelectedFiles } from 'html5-file-selector';
5
+ import Dropzone from 'react-dropzone-uploader';
6
+ import 'react-dropzone-uploader/dist/styles.css';
7
+ import { NotificationManager } from '../../react-notifications';
8
+ import { pdfImage, IconButtonSvg } from '../../iconos';
9
+ import '../dropzone-uploader.css';
12
10
 
13
11
  export const DropzoneUploaderDniDigital = ({
14
- accept = 'image/*, application/pdf',
15
- classNames = '',
16
- onChangeFiles,
17
- totalFiles,
18
- label = 'Cargar Dni',
19
- maxSize = 2,
12
+ accept = 'image/*, application/pdf',
13
+ classNames = '',
14
+ onChangeFiles,
15
+ totalFiles,
16
+ label = 'Cargar Dni',
17
+ maxSize = 2,
20
18
  }) => {
21
- const [files, setFiles] = useState([])
19
+ const [files, setFiles] = useState([]);
22
20
 
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
- }
21
+ const handleChangeStatus = ({ file }, status) => {
22
+ if (status === 'done') {
23
+ const filesTemp = [...files];
24
+ filesTemp.push(file);
25
+ setFiles(filesTemp);
26
+ onChangeFiles(filesTemp);
27
+ } else if (status === 'removed') {
28
+ const filesTemp = [...files];
29
+ const index = filesTemp.indexOf(file);
30
+ if (index > -1) {
31
+ filesTemp.splice(index, 1);
32
+ }
33
+ setFiles(filesTemp);
34
+ onChangeFiles(filesTemp);
35
+ }
36
+ };
39
37
 
40
- const getFilesFromEvent = (e) => {
41
- return new Promise((resolve) => {
42
- getDroppedOrSelectedFiles(e).then((chosenFiles) => {
43
- resolve(chosenFiles.map((f) => f.fileObject))
44
- })
45
- })
46
- }
38
+ const getFilesFromEvent = (e) => {
39
+ return new Promise((resolve) => {
40
+ getDroppedOrSelectedFiles(e).then((chosenFiles) => {
41
+ resolve(chosenFiles.map((f) => f.fileObject));
42
+ });
43
+ });
44
+ };
47
45
 
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
- }
46
+ const CustomPreview = ({ fileWithMeta }) => {
47
+ const { meta, remove } = fileWithMeta;
48
+ console.log('meta.size :>> ', meta.size);
49
+ if (meta.size / (1024 * 1024) > maxSize) {
50
+ NotificationManager.error(
51
+ 'El archivo supera el tamaño máximo',
52
+ 'Advertencia',
53
+ );
54
+ remove();
55
+ }
56
+ return (
57
+ <div
58
+ className="dropzone-upload-previewContainer"
59
+ style={{ width: '100%', display: 'flex', alignItems: 'center' }}
60
+ >
61
+ {meta.type === 'application/pdf' ? (
62
+ <>
63
+ <IconButtonSvg
64
+ className="form-control flex"
65
+ svg={pdfImage}
66
+ svgOver={pdfImage}
67
+ height="1.6rem"
68
+ width="1.6rem"
69
+ title={meta.name}
70
+ />
71
+ <p style={{ paddingRight: '1rem' }}>
72
+ {meta.name.length > 17
73
+ ? meta.name.substring(0, 17) + '...'
74
+ : meta.name}
75
+ </p>
76
+ </>
77
+ ) : (
78
+ <>
79
+ <img
80
+ className="dropzone-upload-previewImage mt-1"
81
+ src={meta.previewUrl}
82
+ alt={meta.name}
83
+ style={{
84
+ width: '110px',
85
+ height: '110px',
86
+ objectFit: 'cover',
87
+ marginRight: '0.5rem',
88
+ }}
89
+ />
90
+ <div className="dropzone-upload-file-name-container">
91
+ <p className="dropzone-upload-file-name" title={meta.name}>
92
+ {meta.name}
93
+ </p>
94
+ </div>
95
+ </>
96
+ )}
97
+ <button
98
+ style={{ marginTop: '0rem' }}
99
+ onClick={remove}
100
+ className="dropzone-upload-delete-btn simple-icon-trash"
101
+ ></button>
102
+ </div>
103
+ );
104
+ };
106
105
 
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
- }
106
+ const Input = ({ accept, onFiles, getFilesFromEvent }) => {
107
+ const text = totalFiles > 0 ? `${2 - totalFiles} archivos más` : `${label}`;
108
+ return (
109
+ <>
110
+ <Button
111
+ outline
112
+ block
113
+ size="xs"
114
+ className="mt-5 ml-5"
115
+ onClick={() => document.getElementById('fileInput').click()}
116
+ >
117
+ {text}
118
+ <input
119
+ id="fileInput"
120
+ style={{ display: 'none' }}
121
+ type="file"
122
+ accept={accept}
123
+ multiple
124
+ onChange={(e) => {
125
+ getFilesFromEvent(e).then((chosenFiles) => {
126
+ onFiles(chosenFiles);
127
+ });
128
+ }}
129
+ />
130
+ </Button>
131
+ </>
132
+ );
133
+ };
135
134
 
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
- }
135
+ return (
136
+ <div className={classNames}>
137
+ <Dropzone
138
+ disableUpload={false}
139
+ maxFiles={totalFiles < 2 ? 2 : 0}
140
+ maxSize={maxSize} // en megas
141
+ InputComponent={Input}
142
+ PreviewComponent={CustomPreview}
143
+ classNames={{ dropzone: 'dropzone-upload-frame' }}
144
+ onChangeStatus={handleChangeStatus}
145
+ getFilesFromEvent={getFilesFromEvent}
146
+ accept={accept}
147
+ />
148
+ </div>
149
+ );
150
+ };
152
151
 
153
- export default DropzoneUploaderDniDigital
152
+ export default DropzoneUploaderDniDigital;
package/src/index.css ADDED
@@ -0,0 +1,74 @@
1
+ :root {
2
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 0.2;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 1.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ h2 {
39
+ font-size: 1.2em;
40
+ line-height: 1.1;
41
+ }
42
+
43
+
44
+ button {
45
+ border-radius: 8px;
46
+ border: 1px solid transparent;
47
+ padding: 0.6em 1.2em;
48
+ font-size: 1em;
49
+ font-weight: 500;
50
+ font-family: inherit;
51
+ background-color: #1a1a1a;
52
+ cursor: pointer;
53
+ transition: border-color 0.25s;
54
+ }
55
+ button:hover {
56
+ border-color: #646cff;
57
+ }
58
+ button:focus,
59
+ button:focus-visible {
60
+ outline: 4px auto -webkit-focus-ring-color;
61
+ }
62
+
63
+ @media (prefers-color-scheme: light) {
64
+ :root {
65
+ color: #213547;
66
+ background-color: #ffffff;
67
+ }
68
+ a:hover {
69
+ color: #747bff;
70
+ }
71
+ button {
72
+ background-color: #f9f9f9;
73
+ }
74
+ }
package/src/index.js CHANGED
@@ -4,3 +4,4 @@ export * from './bridges';
4
4
  export * from './CustomBootstrap';
5
5
  export * from './CustomSelectInput';
6
6
  export * from './tomar-foto';
7
+ export * from './react-notifications';
@@ -0,0 +1,89 @@
1
+ import { useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classnames from 'classnames';
4
+
5
+ const Notification = ({
6
+ title,
7
+ type,
8
+ message,
9
+ customClassName,
10
+ timeOut,
11
+ onClick,
12
+ onRequestHide,
13
+ }) => {
14
+ const requestHide = () => {
15
+ if (onRequestHide) {
16
+ onRequestHide();
17
+ }
18
+ };
19
+
20
+ useEffect(() => {
21
+ let timer = null;
22
+ if (timeOut !== 0) {
23
+ timer = setTimeout(requestHide, timeOut);
24
+ }
25
+ return () => {
26
+ if (timer) {
27
+ clearTimeout(timer);
28
+ }
29
+ };
30
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
+ }, []);
32
+
33
+ const handleClick = () => {
34
+ if (onClick) {
35
+ onClick();
36
+ }
37
+ requestHide();
38
+ };
39
+
40
+ const className = classnames([
41
+ 'notification',
42
+ `notification-${type}`,
43
+ customClassName,
44
+ ]);
45
+ const titleHtml = title ? <h4 className="title">{title}</h4> : null;
46
+ return (
47
+ <div className={className} onClick={() => handleClick()}>
48
+ <div className="notification-message" role="alert">
49
+ {titleHtml}
50
+ <div className="message">{message}</div>
51
+ </div>
52
+ </div>
53
+ );
54
+ };
55
+
56
+ Notification.propTypes = {
57
+ type: PropTypes.oneOf([
58
+ 'info',
59
+ 'success',
60
+ 'warning',
61
+ 'error',
62
+ 'primary',
63
+ 'secondary',
64
+ ]),
65
+ title: PropTypes.node,
66
+ message: PropTypes.node,
67
+ timeOut: PropTypes.number,
68
+ onClick: PropTypes.func,
69
+ onRequestHide: PropTypes.func,
70
+ customClassName: PropTypes.string,
71
+ };
72
+
73
+ Notification.defaultProps = {
74
+ type: 'info',
75
+ title: null,
76
+ message: null,
77
+ timeOut: 5000,
78
+
79
+ onClick: () => {
80
+ undefined;
81
+ },
82
+ onRequestHide: () => {
83
+ undefined;
84
+ },
85
+
86
+ customClassName: '',
87
+ };
88
+
89
+ export default Notification;
@@ -0,0 +1,53 @@
1
+ import { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import NotificationManager from './NotificationManager';
4
+ import Notifications from './Notifications';
5
+
6
+ class NotificationContainer extends Component {
7
+ constructor(props) {
8
+ super(props);
9
+ NotificationManager.addChangeListener(this.handleStoreChange);
10
+ this.state = {
11
+ notifications: [],
12
+ };
13
+ }
14
+
15
+ componentWillUnmount = () => {
16
+ NotificationManager.removeChangeListener(this.handleStoreChange);
17
+ };
18
+
19
+ handleStoreChange = (notifications) => {
20
+ this.setState({
21
+ notifications,
22
+ });
23
+ };
24
+
25
+ handleRequestHide = (notification) => {
26
+ NotificationManager.remove(notification);
27
+ };
28
+
29
+ render() {
30
+ const { notifications } = this.state;
31
+ const { enterTimeout, leaveTimeout } = this.props;
32
+ return (
33
+ <Notifications
34
+ enterTimeout={enterTimeout}
35
+ leaveTimeout={leaveTimeout}
36
+ notifications={notifications}
37
+ onRequestHide={this.handleRequestHide}
38
+ />
39
+ );
40
+ }
41
+ }
42
+
43
+ NotificationContainer.propTypes = {
44
+ enterTimeout: PropTypes.number,
45
+ leaveTimeout: PropTypes.number,
46
+ };
47
+
48
+ NotificationContainer.defaultProps = {
49
+ enterTimeout: 400,
50
+ leaveTimeout: 400,
51
+ };
52
+
53
+ export default NotificationContainer;
@@ -0,0 +1,135 @@
1
+ import { EventEmitter } from "events";
2
+
3
+ const createUUID = () => {
4
+ const pattern = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
5
+ return pattern.replace(/[xy]/g, (c) => {
6
+ const r = (Math.random() * 16) | 0;
7
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
8
+ return v.toString(16);
9
+ });
10
+ };
11
+
12
+ const Constants = {
13
+ CHANGE: "change",
14
+ PRIMARY: "primary",
15
+ SECONDARY: "secondary",
16
+ INFO: "info",
17
+ SUCCESS: "success",
18
+ WARNING: "warning",
19
+ ERROR: "error",
20
+ };
21
+
22
+ class NotificationManager extends EventEmitter {
23
+ constructor() {
24
+ super();
25
+ this.listNotify = [];
26
+ }
27
+
28
+ create(notify) {
29
+ const defaultNotify = {
30
+ id: createUUID(),
31
+ type: "info",
32
+ title: null,
33
+ message: null,
34
+ timeOut: 3000,
35
+ customClassName: "",
36
+ };
37
+ if (notify.priority) {
38
+ this.listNotify.unshift(Object.assign(defaultNotify, notify));
39
+ } else {
40
+ this.listNotify.push(Object.assign(defaultNotify, notify));
41
+ }
42
+ this.emitChange();
43
+ }
44
+
45
+ primary(message, title, timeOut, onClick, priority, customClassName) {
46
+ this.create({
47
+ type: Constants.PRIMARY,
48
+ message,
49
+ title,
50
+ timeOut,
51
+ onClick,
52
+ priority,
53
+ customClassName,
54
+ });
55
+ }
56
+
57
+ secondary(message, title, timeOut, onClick, priority, customClassName) {
58
+ this.create({
59
+ type: Constants.SECONDARY,
60
+ message,
61
+ title,
62
+ timeOut,
63
+ onClick,
64
+ priority,
65
+ customClassName,
66
+ });
67
+ }
68
+
69
+ info(message, title, timeOut, onClick, priority, customClassName) {
70
+ this.create({
71
+ type: Constants.INFO,
72
+ message,
73
+ title,
74
+ timeOut,
75
+ onClick,
76
+ priority,
77
+ customClassName,
78
+ });
79
+ }
80
+
81
+ success(message, title, timeOut, onClick, priority, customClassName) {
82
+ this.create({
83
+ type: Constants.SUCCESS,
84
+ message,
85
+ title,
86
+ timeOut,
87
+ onClick,
88
+ priority,
89
+ customClassName,
90
+ });
91
+ }
92
+
93
+ warning(message, title, timeOut, onClick, priority, customClassName) {
94
+ this.create({
95
+ type: Constants.WARNING,
96
+ message,
97
+ title,
98
+ timeOut,
99
+ onClick,
100
+ priority,
101
+ customClassName,
102
+ });
103
+ }
104
+
105
+ error(message, title, timeOut, onClick, priority, customClassName) {
106
+ this.create({
107
+ type: Constants.ERROR,
108
+ message,
109
+ title,
110
+ timeOut,
111
+ onClick,
112
+ priority,
113
+ customClassName,
114
+ });
115
+ }
116
+
117
+ remove(notification) {
118
+ this.listNotify = this.listNotify.filter((n) => notification.id !== n.id);
119
+ this.emitChange();
120
+ }
121
+
122
+ emitChange() {
123
+ this.emit(Constants.CHANGE, this.listNotify);
124
+ }
125
+
126
+ addChangeListener(callback) {
127
+ this.addListener(Constants.CHANGE, callback);
128
+ }
129
+
130
+ removeChangeListener(callback) {
131
+ this.removeListener(Constants.CHANGE, callback);
132
+ }
133
+ }
134
+
135
+ export default new NotificationManager();
@@ -0,0 +1,66 @@
1
+ import { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { TransitionGroup, CSSTransition } from 'react-transition-group';
4
+ import classnames from 'classnames';
5
+ import Notification from './Notification';
6
+
7
+ class Notifications extends Component {
8
+ handleRequestHide = (notification) => () => {
9
+ const { onRequestHide } = this.props;
10
+ if (onRequestHide) {
11
+ onRequestHide(notification);
12
+ }
13
+ };
14
+
15
+ render() {
16
+ const { notifications, enterTimeout, leaveTimeout } = this.props;
17
+ const className = classnames('notification-container', {
18
+ 'notification-container-empty': notifications.length === 0,
19
+ });
20
+ return (
21
+ <div className={className}>
22
+ <TransitionGroup>
23
+ {notifications.map((notification) => {
24
+ const key = notification.id || new Date().getTime();
25
+ return (
26
+ <CSSTransition
27
+ classNames="notification"
28
+ key={key}
29
+ timeout={{ exit: leaveTimeout, enter: enterTimeout }}
30
+ >
31
+ <Notification
32
+ key={key}
33
+ type={notification.type}
34
+ title={notification.title}
35
+ message={notification.message}
36
+ timeOut={notification.timeOut}
37
+ onClick={notification.onClick}
38
+ onRequestHide={this.handleRequestHide(notification)}
39
+ customClassName={notification.customClassName}
40
+ />
41
+ </CSSTransition>
42
+ );
43
+ })}
44
+ </TransitionGroup>
45
+ </div>
46
+ );
47
+ }
48
+ }
49
+ Notifications.propTypes = {
50
+ notifications: PropTypes.array,
51
+ onRequestHide: PropTypes.func,
52
+ enterTimeout: PropTypes.number,
53
+ leaveTimeout: PropTypes.number,
54
+ };
55
+
56
+ Notifications.defaultProps = {
57
+ notifications: [],
58
+
59
+ onRequestHide: () => {
60
+ undefined;
61
+ },
62
+
63
+ enterTimeout: 400,
64
+ leaveTimeout: 400,
65
+ };
66
+ export default Notifications;
@@ -0,0 +1,5 @@
1
+ import Notifications from './Notifications';
2
+ import NotificationContainer from './NotificationContainer';
3
+ import NotificationManager from './NotificationManager';
4
+
5
+ export { Notifications, NotificationContainer, NotificationManager };
package/vite.config.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import react from "@vitejs/plugin-react";
2
2
  import { defineConfig } from "vitest/config";
3
- import eslint from 'vite-plugin-eslint';
4
3
  import commonjs from 'vite-plugin-commonjs'
5
4
 
6
5
  export default defineConfig({
7
- plugins: [react(), eslint(), commonjs()],
8
- test: {
9
- globals: true,
6
+ plugins: [react(), commonjs()],
7
+ css: {
8
+ preprocessorOptions: {
9
+ scss: {
10
+ silenceDeprecations: ['legacy-js-api'],
11
+ },
12
+ },
10
13
  },
11
14
  });
package/.eslintrc.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint:recommended",
4
- "plugin:react/recommended",
5
- "plugin:react-hooks/recommended"
6
- ],
7
- "plugins": [
8
- "react",
9
- "react-hooks"
10
- ],
11
- "parserOptions": {
12
- "ecmaVersion": 2020,
13
- "sourceType": "module",
14
- "ecmaFeatures": {
15
- "jsx": true
16
- }
17
- },
18
- "env": {
19
- "browser": true,
20
- "es2020": true
21
- },
22
- "rules": {
23
- "react/react-in-jsx-scope": "off"
24
- }
25
- }