siam-ui-utils 2.0.26 → 2.0.27

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,89 +0,0 @@
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;
@@ -1,53 +0,0 @@
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;
@@ -1,135 +0,0 @@
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();
@@ -1,66 +0,0 @@
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;
@@ -1,5 +0,0 @@
1
- import Notifications from './Notifications';
2
- import NotificationContainer from './NotificationContainer';
3
- import NotificationManager from './NotificationManager';
4
-
5
- export { Notifications, NotificationContainer, NotificationManager };