diginet-core-ui 1.3.75 → 1.3.76-beta.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.
- package/components/alert/index.js +102 -110
- package/components/alert/notify.js +103 -162
- package/components/avatar/index.js +23 -22
- package/components/button/icon.js +137 -175
- package/components/button/index.js +147 -174
- package/components/button/more.js +192 -112
- package/components/form-control/attachment/index.js +24 -22
- package/components/form-control/checkbox/index.js +45 -41
- package/components/form-control/date-picker/index.js +1 -4
- package/components/form-control/date-range-picker/index.js +355 -334
- package/components/form-control/dropdown/index.js +67 -47
- package/components/form-control/helper-text/index.js +29 -15
- package/components/form-control/input-base/index.js +228 -345
- package/components/form-control/label/index.js +8 -9
- package/components/form-control/number-input/index2.js +164 -159
- package/components/form-control/text-input/index.js +32 -219
- package/components/popover/index.js +41 -29
- package/components/progress/circular.js +207 -151
- package/components/tab/tab-container.js +23 -22
- package/components/tab/tab-header.js +37 -35
- package/components/tab/tab-panel.js +13 -11
- package/components/tab/tab.js +18 -16
- package/components/tooltip/index.js +61 -58
- package/components/typography/index.js +10 -10
- package/package.json +61 -31
- package/readme.md +11 -0
- package/styles/general.js +16 -11
- package/styles/typography.js +63 -72
- package/theme/index.js +1 -1
- package/theme/set-theme.js +2 -1
- package/utils/useInput.js +4 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import {
|
|
4
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { jsx, css } from '@emotion/core';
|
|
7
7
|
import LinearProgress from '../progress/linear';
|
|
8
|
-
import { color as colors } from '../../styles/colors';
|
|
9
8
|
import ButtonIcon from '../button/icon';
|
|
10
9
|
import Icon from '../../icons';
|
|
11
10
|
import { hexToRGBA } from '../../styles/color-helper';
|
|
11
|
+
import { animations } from '../../styles/animation';
|
|
12
|
+
import { classNames, useDelayUnmount } from '../../utils';
|
|
12
13
|
import { alignCenter, border, borderBox, borderRadius4px, breakWord, displayBlock, flexRow, justifyStart, positionRelative, userSelectNone } from '../../styles/general';
|
|
13
|
-
import
|
|
14
|
+
import { useTheme, useColor as colors } from '../../theme';
|
|
14
15
|
const {
|
|
15
16
|
colors: {
|
|
16
17
|
system: {
|
|
17
|
-
|
|
18
|
-
white
|
|
18
|
+
white: systemWhite
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
typography: {
|
|
@@ -28,31 +28,40 @@ const {
|
|
|
28
28
|
},
|
|
29
29
|
spacing,
|
|
30
30
|
zIndex: zIndexCORE
|
|
31
|
-
} =
|
|
31
|
+
} = useTheme();
|
|
32
32
|
const iconMap = new Map([['info', 'Info'], ['success', 'ApprovalFilled'], ['warning', 'Warning'], ['danger', 'CancelFilled']]);
|
|
33
33
|
const maxWidthMap = new Map([['tiny', 320], ['small', 400], ['medium', 480]]);
|
|
34
34
|
const primaryTypoMap = new Map([['tiny', heading5], ['small', heading4], ['medium', heading3]]);
|
|
35
35
|
const iconSizeMap = new Map([['tiny', 16], ['small', 20], ['medium', 24]]);
|
|
36
36
|
const linearProgressSizeMap = new Map([['tiny', 2], ['small', 3], ['medium', 4]]);
|
|
37
|
+
const transitionTime = 300;
|
|
37
38
|
const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
38
|
-
|
|
39
|
-
text,
|
|
40
|
-
secondary,
|
|
41
|
-
size,
|
|
42
|
-
className,
|
|
43
|
-
progressing,
|
|
39
|
+
action = {},
|
|
44
40
|
autoDisappear,
|
|
45
|
-
|
|
41
|
+
children,
|
|
42
|
+
className,
|
|
46
43
|
clearAble,
|
|
44
|
+
color,
|
|
45
|
+
duration,
|
|
47
46
|
onClose,
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
progressing,
|
|
48
|
+
secondary,
|
|
49
|
+
size,
|
|
50
|
+
text,
|
|
51
|
+
type
|
|
52
|
+
}, reference) => {
|
|
53
|
+
type = type || color;
|
|
54
|
+
const ref = useRef(null);
|
|
50
55
|
const clearIconRef = useRef(null);
|
|
51
56
|
const [percentState, setPercentState] = useState(100);
|
|
52
|
-
const
|
|
57
|
+
const [isClose, setIsClose] = useState(false);
|
|
58
|
+
const showAlert = useDelayUnmount(!isClose, transitionTime);
|
|
59
|
+
const mainColor = colors[type];
|
|
53
60
|
const opacityColor = hexToRGBA(mainColor, 0.15);
|
|
61
|
+
const iconName = iconMap.get(type);
|
|
62
|
+
const iconSize = iconSizeMap.get(size);
|
|
54
63
|
|
|
55
|
-
const _AlertContainerCSS = AlertContainerCSS(size
|
|
64
|
+
const _AlertContainerCSS = AlertContainerCSS(size);
|
|
56
65
|
|
|
57
66
|
const _AlertInfoCSS = AlertInfoCSS(mainColor, opacityColor);
|
|
58
67
|
|
|
@@ -64,53 +73,51 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
64
73
|
|
|
65
74
|
const _linearProgressCSS = linearProgressCSS(size);
|
|
66
75
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!el) return;
|
|
71
|
-
el.style.pointerEvent = 'none';
|
|
72
|
-
const alertNode = el === null || el === void 0 ? void 0 : (_el$parentNode = el.parentNode) === null || _el$parentNode === void 0 ? void 0 : _el$parentNode.parentNode;
|
|
73
|
-
|
|
74
|
-
if (alertNode) {
|
|
75
|
-
if (urgency) {
|
|
76
|
-
alertNode.style.transition = `opacity 1s ease`;
|
|
77
|
-
alertNode.style.opacity = 1;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
setTimeout(() => {
|
|
81
|
-
alertNode.style.opacity = 0;
|
|
82
|
-
}, 0);
|
|
83
|
-
setTimeout(() => {
|
|
84
|
-
if (onClose) onClose(alertNode);
|
|
85
|
-
alertNode.remove();
|
|
86
|
-
}, !urgency && progressing ? duration * 1000 + 300 : duration * 1000);
|
|
87
|
-
}
|
|
76
|
+
const _onClose = () => {
|
|
77
|
+
setIsClose(true);
|
|
78
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
88
79
|
};
|
|
89
80
|
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
setPercentState(0);
|
|
84
|
+
}, 100);
|
|
85
|
+
}, []);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (ref.current && isClose) ref.current.style.opacity = 0;
|
|
88
|
+
}, [isClose]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
if (autoDisappear) _onClose();
|
|
92
|
+
}, duration);
|
|
93
|
+
}, [autoDisappear]);
|
|
94
|
+
useImperativeHandle(reference, () => {
|
|
95
|
+
const currentRef = ref.current || {};
|
|
96
|
+
currentRef.element = ref.current;
|
|
97
|
+
const _instance = { ...action
|
|
98
|
+
}; // methods
|
|
99
|
+
|
|
100
|
+
_instance.__proto__ = {}; // hidden methods
|
|
101
|
+
|
|
102
|
+
currentRef.instance = _instance;
|
|
103
|
+
return currentRef;
|
|
104
|
+
});
|
|
90
105
|
const AlertView = useMemo(() => {
|
|
91
106
|
let node = children;
|
|
92
107
|
|
|
93
108
|
if (!node) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
color: 'currentColor',
|
|
102
|
-
viewBox: true
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
node = jsx("span", {
|
|
106
|
-
css: NotFoundIconCSS
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
+
node = jsx(Icon, {
|
|
110
|
+
name: iconName,
|
|
111
|
+
width: iconSize,
|
|
112
|
+
height: iconSize,
|
|
113
|
+
color: 'currentColor',
|
|
114
|
+
viewBox: true
|
|
115
|
+
});
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
return jsx("div", {
|
|
112
119
|
css: _AlertInfoCSS,
|
|
113
|
-
className:
|
|
120
|
+
className: classNames('DGN-UI-Alert', className)
|
|
114
121
|
}, jsx("span", {
|
|
115
122
|
css: AlertIconCSS,
|
|
116
123
|
className: 'DGN-UI-Alert-Icon'
|
|
@@ -125,17 +132,17 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
125
132
|
className: 'DGN-UI-Alert-Content-Secondary'
|
|
126
133
|
}, secondary)), jsx("span", {
|
|
127
134
|
css: AlertClearIconCSS,
|
|
128
|
-
onClick:
|
|
135
|
+
onClick: _onClose,
|
|
129
136
|
ref: clearIconRef,
|
|
130
137
|
className: 'DGN-UI-Alert-Clear'
|
|
131
138
|
}, clearAble ? jsx(ButtonIcon, {
|
|
132
139
|
circular: true,
|
|
133
140
|
viewType: 'text',
|
|
134
141
|
size: size,
|
|
135
|
-
color:
|
|
142
|
+
color: type,
|
|
136
143
|
name: 'Close'
|
|
137
144
|
}) : null));
|
|
138
|
-
}, [color, text, clearAble, secondary, size, children, className]);
|
|
145
|
+
}, [color, text, clearAble, secondary, size, children, className, type, onClose, mainColor, opacityColor, isClose]);
|
|
139
146
|
const LinearView = useMemo(() => {
|
|
140
147
|
return progressing ? jsx("span", {
|
|
141
148
|
css: _linearProgressCSS,
|
|
@@ -145,39 +152,30 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
145
152
|
background: 'transparent',
|
|
146
153
|
color: mainColor,
|
|
147
154
|
percent: percentState,
|
|
148
|
-
duration: duration,
|
|
155
|
+
duration: duration / 1000,
|
|
149
156
|
height: linearProgressSizeMap.get(size),
|
|
150
157
|
style: {
|
|
151
158
|
boxShadow: 'none'
|
|
152
159
|
}
|
|
153
160
|
})) : null;
|
|
154
|
-
}, [progressing, size, percentState]);
|
|
155
|
-
|
|
156
|
-
if (progressing) {
|
|
157
|
-
setTimeout(() => {
|
|
158
|
-
setPercentState(0);
|
|
159
|
-
}, 1);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (autoDisappear) {
|
|
163
|
-
onClearAlert(clearIconRef.current);
|
|
164
|
-
}
|
|
165
|
-
}, []);
|
|
166
|
-
return jsx("div", {
|
|
161
|
+
}, [progressing, size, duration, percentState]);
|
|
162
|
+
return showAlert ? jsx("div", {
|
|
167
163
|
css: _AlertContainerCSS,
|
|
168
164
|
className: 'DGN-UI-Container-Alert',
|
|
169
165
|
ref: ref
|
|
170
|
-
}, AlertView, LinearView);
|
|
166
|
+
}, AlertView, LinearView) : null;
|
|
171
167
|
}));
|
|
168
|
+
const fadeIn = animations.fadeIn;
|
|
172
169
|
|
|
173
|
-
const AlertContainerCSS =
|
|
170
|
+
const AlertContainerCSS = size => css`
|
|
174
171
|
${positionRelative};
|
|
175
172
|
${displayBlock};
|
|
176
173
|
max-width: ${maxWidthMap.get(size)}px;
|
|
177
|
-
transition: opacity ${
|
|
174
|
+
transition: opacity ${transitionTime}ms ease;
|
|
178
175
|
margin-bottom: 1rem;
|
|
179
176
|
pointer-events: auto;
|
|
180
177
|
z-index: ${zIndexCORE(1)};
|
|
178
|
+
animation: ${fadeIn} ${transitionTime}ms ease;
|
|
181
179
|
`;
|
|
182
180
|
|
|
183
181
|
const AlertInfoCSS = (mainColor, opacityColor) => css`
|
|
@@ -189,7 +187,7 @@ const AlertInfoCSS = (mainColor, opacityColor) => css`
|
|
|
189
187
|
${border(1, mainColor)};
|
|
190
188
|
color: ${mainColor};
|
|
191
189
|
background-image: linear-gradient(${opacityColor}, ${opacityColor});
|
|
192
|
-
background-color: ${
|
|
190
|
+
background-color: ${systemWhite};
|
|
193
191
|
width: 100%;
|
|
194
192
|
min-width: 320px;
|
|
195
193
|
padding: ${spacing([0, 1, 0, 4])};
|
|
@@ -198,13 +196,13 @@ const AlertInfoCSS = (mainColor, opacityColor) => css`
|
|
|
198
196
|
|
|
199
197
|
const AlertIconCSS = css`
|
|
200
198
|
display: inherit;
|
|
201
|
-
margin-right:
|
|
199
|
+
margin-right: ${spacing([2.5])};
|
|
202
200
|
padding: ${spacing([2, 0])};
|
|
203
201
|
`;
|
|
204
202
|
|
|
205
203
|
const AlertTextCSS = clearAble => css`
|
|
206
204
|
${displayBlock};
|
|
207
|
-
margin-right: ${clearAble ?
|
|
205
|
+
margin-right: ${spacing([clearAble ? 2.5 : 0])};
|
|
208
206
|
padding: ${spacing([2, 0])};
|
|
209
207
|
align-self: center;
|
|
210
208
|
`;
|
|
@@ -231,57 +229,51 @@ const AlertClearIconCSS = css`
|
|
|
231
229
|
const linearProgressCSS = size => css`
|
|
232
230
|
${displayBlock};
|
|
233
231
|
${positionRelative};
|
|
234
|
-
margin-top: ${size === 'medium' ?
|
|
235
|
-
padding: 0
|
|
232
|
+
margin-top: ${spacing([size === 'medium' ? 1 : 0.5])};
|
|
233
|
+
padding: ${spacing([0, 1.25])};
|
|
236
234
|
`;
|
|
237
235
|
|
|
238
|
-
const NotFoundIconCSS = css`
|
|
239
|
-
${displayBlock};
|
|
240
|
-
width: 70%;
|
|
241
|
-
height: 70%;
|
|
242
|
-
border: 1px dashed ${rest};
|
|
243
|
-
`;
|
|
244
236
|
Alert.defaultProps = {
|
|
245
|
-
|
|
246
|
-
size: 'medium',
|
|
237
|
+
autoDisappear: false,
|
|
247
238
|
className: '',
|
|
248
239
|
clearAble: true,
|
|
240
|
+
color: 'info',
|
|
241
|
+
duration: 2000,
|
|
249
242
|
progressing: false,
|
|
250
|
-
|
|
251
|
-
duration: 5
|
|
243
|
+
size: 'medium'
|
|
252
244
|
};
|
|
253
245
|
Alert.propTypes = {
|
|
254
|
-
/**
|
|
255
|
-
|
|
246
|
+
/** Automatically remove the Alert component after the timer ends (milliseconds). */
|
|
247
|
+
autoDisappear: PropTypes.bool,
|
|
256
248
|
|
|
257
|
-
/**
|
|
258
|
-
|
|
249
|
+
/** The element to display in alert like text props (priority). */
|
|
250
|
+
children: PropTypes.node,
|
|
259
251
|
|
|
260
|
-
/**
|
|
261
|
-
|
|
252
|
+
/** Class for component. */
|
|
253
|
+
className: PropTypes.string,
|
|
262
254
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
255
|
+
/** If `true`, show clear icon to close alert. */
|
|
256
|
+
clearAble: PropTypes.bool,
|
|
265
257
|
|
|
266
|
-
/**
|
|
267
|
-
|
|
258
|
+
/** The amount of time the alert is displayed. The unit is the milliseconds. */
|
|
259
|
+
duration: PropTypes.number,
|
|
268
260
|
|
|
269
|
-
/**
|
|
270
|
-
|
|
261
|
+
/** Callback fired when the component closed. */
|
|
262
|
+
onClose: PropTypes.func,
|
|
271
263
|
|
|
272
|
-
/**
|
|
264
|
+
/** If `true`, show linear progress in duration time.*/
|
|
273
265
|
progressing: PropTypes.bool,
|
|
274
266
|
|
|
275
|
-
/**
|
|
276
|
-
|
|
267
|
+
/** The secondary text to show in alert (under primary). */
|
|
268
|
+
secondary: PropTypes.string,
|
|
277
269
|
|
|
278
|
-
/** The
|
|
279
|
-
|
|
270
|
+
/** The size of the component. */
|
|
271
|
+
size: PropTypes.oneOf(['tiny', 'small', 'medium']),
|
|
280
272
|
|
|
281
|
-
/** The
|
|
282
|
-
|
|
273
|
+
/** The text to show in alert. */
|
|
274
|
+
text: PropTypes.string,
|
|
283
275
|
|
|
284
|
-
/**
|
|
285
|
-
|
|
276
|
+
/** Type of the component. */
|
|
277
|
+
type: PropTypes.oneOf(['info', 'success', 'warning', 'danger'])
|
|
286
278
|
};
|
|
287
279
|
export default Alert;
|
|
@@ -1,198 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** @jsxRuntime classic */
|
|
2
|
+
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { memo, useEffect, forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
5
|
+
import ReactDOM, { createPortal } from 'react-dom';
|
|
3
6
|
import PropTypes from 'prop-types';
|
|
7
|
+
import { jsx, css } from '@emotion/core';
|
|
4
8
|
import Alert from './';
|
|
5
|
-
import { randomString } from '../../utils';
|
|
6
9
|
import theme from '../../theme/settings';
|
|
10
|
+
import { classNames, refType as ref } from '../../utils';
|
|
11
|
+
import { backgroundTransparent, pointerEventsNone, positionFixed } from '../../styles/general';
|
|
7
12
|
const {
|
|
8
13
|
zIndex: zIndexCORE
|
|
9
14
|
} = theme;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
horizontal: {
|
|
32
|
-
left: {
|
|
33
|
-
left: '15px'
|
|
34
|
-
},
|
|
35
|
-
center: {
|
|
36
|
-
left: '50%',
|
|
37
|
-
transform: 'translateX(-50%)'
|
|
38
|
-
},
|
|
39
|
-
right: {
|
|
40
|
-
right: '15px'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const str = randomString(6, {
|
|
45
|
-
allowSymbol: false
|
|
46
|
-
});
|
|
47
|
-
const AlertNotify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
48
|
-
position,
|
|
15
|
+
const positionVerticalMap = new Map([['top', css`
|
|
16
|
+
top: 15px;
|
|
17
|
+
`], ['center', css`
|
|
18
|
+
top: 50%;
|
|
19
|
+
transform: translateY(-50%);
|
|
20
|
+
`], ['bottom', css`
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column-reverse;
|
|
23
|
+
bottom: 0;
|
|
24
|
+
`]]);
|
|
25
|
+
const positionHorizontalMap = new Map([['left', css`
|
|
26
|
+
left: 15px;
|
|
27
|
+
`], ['center', css`
|
|
28
|
+
left: 50%;
|
|
29
|
+
transform: translateX(-50%);
|
|
30
|
+
`], ['right', css`
|
|
31
|
+
right: 15px;
|
|
32
|
+
`]]);
|
|
33
|
+
const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
34
|
+
action = {},
|
|
35
|
+
className,
|
|
49
36
|
getAddNotify,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
maxHeight,
|
|
37
|
+
id,
|
|
38
|
+
position,
|
|
39
|
+
style,
|
|
54
40
|
...props
|
|
55
41
|
}, reference) => {
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (pos === 'center') {
|
|
63
|
-
pos = {
|
|
64
|
-
vertical: 'center',
|
|
65
|
-
horizontal: 'center'
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (pos.vertical && pos.horizontal && /^top|center|bottom$/.test(pos.vertical) && /^left|center|right$/.test(pos.horizontal)) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const renderNotifyAlertPosition = (pos, className) => {
|
|
77
|
-
if (pos === 'center') {
|
|
78
|
-
pos = {
|
|
79
|
-
vertical: 'center',
|
|
80
|
-
horizontal: 'center'
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const el = document.createElement('div');
|
|
85
|
-
el.className = `Notify-Alert-${className || pos.vertical + '-' + pos.horizontal}`;
|
|
86
|
-
Object.assign(el.style, positions.general, positions.vertical[pos.vertical || 'bottom'], positions.horizontal[pos.horizontal || 'center'], pos.vertical === pos.horizontal ? {
|
|
87
|
-
transform: 'translate(-50%, -50%)'
|
|
88
|
-
} : {}, {
|
|
89
|
-
width,
|
|
90
|
-
maxWidth,
|
|
91
|
-
height,
|
|
92
|
-
maxHeight
|
|
93
|
-
});
|
|
94
|
-
document.body.appendChild(el);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const onClose = (e, removePosition) => {
|
|
98
|
-
var _e$parentNode;
|
|
99
|
-
|
|
100
|
-
(_e$parentNode = e.parentNode) === null || _e$parentNode === void 0 ? void 0 : _e$parentNode.remove();
|
|
101
|
-
|
|
102
|
-
if (removePosition) {
|
|
103
|
-
const node = document.querySelector(`div[class^="Notify-Alert-${removePosition.vertical}-${removePosition.horizontal}"]`);
|
|
104
|
-
|
|
105
|
-
if (node && node.childNodes && !node.childNodes.length) {
|
|
106
|
-
node.remove();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
42
|
+
const ref = useRef(null);
|
|
43
|
+
const [positionState, setPositionState] = useState(position);
|
|
44
|
+
const PositionVerticalCSS = positionVerticalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.vertical) || 'bottom');
|
|
45
|
+
const PositionHorizontalCSS = positionHorizontalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.horizontal) || 'center');
|
|
110
46
|
|
|
111
|
-
const
|
|
47
|
+
const showNotify = (message, {
|
|
112
48
|
position,
|
|
113
49
|
...options
|
|
114
50
|
} = {}) => {
|
|
115
51
|
options = typeof options === 'object' ? options : {};
|
|
116
|
-
const el = document.createElement('div');
|
|
117
|
-
el.className = `Notify-Alert-${str}-item`;
|
|
118
52
|
|
|
119
|
-
if (position
|
|
120
|
-
|
|
121
|
-
renderNotifyAlertPosition(position);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(Alert, {
|
|
125
|
-
onClose: e => onClose(e, position),
|
|
126
|
-
secondary: message,
|
|
127
|
-
...props,
|
|
128
|
-
...options
|
|
129
|
-
}), document.querySelector(`div[class^="Notify-Alert-${position.vertical}-${position.horizontal}"]`).appendChild(el));
|
|
130
|
-
} else {
|
|
131
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(Alert, {
|
|
132
|
-
onClose: onClose,
|
|
133
|
-
secondary: message,
|
|
134
|
-
...props,
|
|
135
|
-
...options
|
|
136
|
-
}), document.querySelector(`div[class^="Notify-Alert-"]`).appendChild(el));
|
|
53
|
+
if (position) {
|
|
54
|
+
setPositionState(position);
|
|
137
55
|
}
|
|
56
|
+
|
|
57
|
+
const el = document.createElement('div');
|
|
58
|
+
el.className = 'DGN-UI-Notify-Alert-Item';
|
|
59
|
+
ReactDOM.render(jsx(Alert // onClose={() => el.remove()}
|
|
60
|
+
, {
|
|
61
|
+
secondary: message,
|
|
62
|
+
...props,
|
|
63
|
+
...options
|
|
64
|
+
}), ref.current.appendChild(el));
|
|
138
65
|
};
|
|
139
66
|
|
|
140
67
|
useEffect(() => {
|
|
141
|
-
if (getAddNotify && typeof getAddNotify === 'function') getAddNotify(
|
|
68
|
+
if (getAddNotify && typeof getAddNotify === 'function') getAddNotify(showNotify);
|
|
142
69
|
}, [props]);
|
|
143
70
|
useEffect(() => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
71
|
+
setPositionState(position);
|
|
72
|
+
}, [position]);
|
|
73
|
+
useImperativeHandle(reference, () => {
|
|
74
|
+
const currentRef = ref.current || {};
|
|
75
|
+
currentRef.element = ref.current;
|
|
76
|
+
const _instance = {
|
|
77
|
+
show: showNotify,
|
|
78
|
+
...action
|
|
79
|
+
}; // methods
|
|
80
|
+
|
|
81
|
+
_instance.__proto__ = {}; // hidden methods
|
|
82
|
+
|
|
83
|
+
currentRef.instance = _instance;
|
|
84
|
+
currentRef.add = showNotify;
|
|
85
|
+
return currentRef;
|
|
86
|
+
});
|
|
87
|
+
const NotifyContainerView = jsx("div", {
|
|
88
|
+
ref: ref,
|
|
89
|
+
css: [AlertCSS, PositionVerticalCSS, PositionHorizontalCSS],
|
|
90
|
+
id: id,
|
|
91
|
+
style: style,
|
|
92
|
+
className: classNames('DGN-UI-Notify-Alert', (position === null || position === void 0 ? void 0 : position.vertical) || 'center' + '-' + (position === null || position === void 0 ? void 0 : position.horizontal) || 'center', className)
|
|
93
|
+
});
|
|
94
|
+
return /*#__PURE__*/createPortal(NotifyContainerView, document.body);
|
|
153
95
|
}));
|
|
154
|
-
|
|
96
|
+
const AlertCSS = css`
|
|
97
|
+
${positionFixed};
|
|
98
|
+
${pointerEventsNone};
|
|
99
|
+
${backgroundTransparent};
|
|
100
|
+
z-index: ${zIndexCORE(2)};
|
|
101
|
+
`;
|
|
102
|
+
Notify.defaultProps = {
|
|
103
|
+
className: '',
|
|
155
104
|
position: {
|
|
156
105
|
vertical: 'bottom',
|
|
157
106
|
horizontal: 'center'
|
|
158
|
-
}
|
|
107
|
+
},
|
|
108
|
+
style: {}
|
|
159
109
|
};
|
|
160
|
-
|
|
110
|
+
Notify.propTypes = {
|
|
111
|
+
/** Class for component. */
|
|
112
|
+
className: PropTypes.string,
|
|
113
|
+
|
|
161
114
|
/**
|
|
162
115
|
* used to set position of Alert (is a string or an object)
|
|
163
116
|
* string is center (obligatory) as {vertical: 'center', horizontal: 'center'}
|
|
164
117
|
*/
|
|
165
118
|
position: PropTypes.oneOfType([PropTypes.oneOf(['center']), PropTypes.shape({
|
|
166
|
-
|
|
167
|
-
|
|
119
|
+
horizontal: PropTypes.oneOf(['center', 'left', 'right']),
|
|
120
|
+
vertical: PropTypes.oneOf(['bottom', 'center', 'top'])
|
|
168
121
|
})]),
|
|
169
122
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
* 2 parameters:<br />
|
|
173
|
-
* + message: message for notify<br />
|
|
174
|
-
* + options: is an object insist {<br />
|
|
175
|
-
* position: position other than the default (if necessary)<br />
|
|
176
|
-
* duration: new duration,<br />
|
|
177
|
-
* color: new color,<br />
|
|
178
|
-
* progressing: new progressing value,<br />
|
|
179
|
-
* autoDisappear: new autoDisappear value,<br />
|
|
180
|
-
* size: new autoDisappear,<br />
|
|
181
|
-
* and any props else in Alert component <br />
|
|
182
|
-
* }
|
|
183
|
-
*/
|
|
184
|
-
getAddNotify: PropTypes.func.isRequired,
|
|
123
|
+
/** Style inline of component. */
|
|
124
|
+
style: PropTypes.object,
|
|
185
125
|
|
|
186
|
-
/**
|
|
187
|
-
|
|
126
|
+
/** Any [props](https://core.diginet.com.vn/ui/?path=/docs/alert--basic) of Alert */
|
|
127
|
+
props: PropTypes.any,
|
|
188
128
|
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
129
|
+
/**
|
|
130
|
+
* ref methods (ref.current.instance.*method*)
|
|
131
|
+
*
|
|
132
|
+
* * show(message, option): Show notify
|
|
133
|
+
* * @param {message} - number
|
|
134
|
+
* * @param {options} - object
|
|
135
|
+
* * {[Props](https://core.diginet.com.vn/ui/?path=/docs/alert--basic) applied to the `Alert`.}
|
|
136
|
+
*/
|
|
137
|
+
reference: ref
|
|
197
138
|
};
|
|
198
|
-
export default
|
|
139
|
+
export default Notify;
|