diginet-core-ui 1.3.35-beta.3 → 1.3.35-beta.4

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.
@@ -12,6 +12,10 @@ import { randomString, updatePosition, date as moment, capitalizeSentenceCase, i
12
12
  import { getGlobal } from '../../../global';
13
13
  import { generateCalendarCSS, onUpdateNavigator, renderHeader, renderNavigator } from '../calendar/function';
14
14
  import locale from '../../../locale';
15
+ import { useTheme } from '../../../theme';
16
+ const {
17
+ zIndex
18
+ } = useTheme();
15
19
  const DateRangePickerV2 = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
16
20
  actionIconAt,
17
21
  controls,
@@ -9,6 +9,10 @@ import { randomString, useOnClickOutside } from '../../../utils';
9
9
  import theme from '../../../theme/settings';
10
10
  import Swiper from './swiper';
11
11
  import { typography } from '../../../styles/typography';
12
+ import { useTheme } from '../../../theme';
13
+ const {
14
+ zIndex
15
+ } = useTheme();
12
16
 
13
17
  const formatDimension = x => {
14
18
  const regexPercent = /^\d+%$/;
@@ -1,133 +1,69 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { memo, useState, useRef, forwardRef, useEffect, useMemo } from 'react';
4
+ import { memo, useState, useRef, forwardRef, useEffect, useMemo, useImperativeHandle } from 'react';
5
5
  import { createPortal } from 'react-dom';
6
6
  import PropTypes from 'prop-types';
7
- import { jsx, css, keyframes } from '@emotion/core';
7
+ import { jsx, css } from '@emotion/core';
8
8
  import ModalContext from './context';
9
+ import { animations } from '../../styles/animation';
9
10
  import { typography } from '../../styles/typography';
10
11
  import { useTheme } from '../../theme';
11
12
  const {
12
13
  zIndex: zIndexCORE
13
14
  } = useTheme();
15
+ import { borderBox, borderRadius4px, flexCol, flexRow, justifyCenter, parseWidth, positionFixed, positionRelative } from '../../styles/general';
16
+ import { color as colors } from '../../styles/colors';
17
+ const {
18
+ paragraph1
19
+ } = typography;
20
+ const {
21
+ system: {
22
+ white
23
+ }
24
+ } = colors;
25
+ const fadeInDown = animations.fadeInDown;
14
26
  const Modal = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
15
27
  open,
16
- type,
17
- title,
18
28
  moveable,
19
29
  dragAnyWhere,
20
30
  moveOutScreen,
21
31
  style,
22
- top,
23
32
  zIndex,
24
33
  pressESCToClose,
25
34
  darkTheme,
26
35
  autoFocus,
27
- refs,
28
36
  onClose,
29
- onConfirm,
30
- onCancel,
31
37
  children,
32
38
  width,
33
- ...props
34
- }, ref) => {
35
- if (!ref) {
36
- ref = useRef(null);
37
- }
38
-
39
+ alignment
40
+ }, reference) => {
41
+ const ref = useRef(null);
39
42
  const modalBoxRef = useRef(null);
40
43
  const [openState, setOpenState] = useState(open);
41
- const ModalContainer = css`
42
- position: fixed;
43
- display: flex;
44
- width: 100%;
45
- height: 100vh;
46
- background-color: ${darkTheme ? 'rgba(21, 26, 48, 0.5)' : 'transparent'};
47
- top: 0;
48
- left: 0;
49
- justify-content: center;
50
- align-items: ${top ? 'inherit' : 'center'};
51
- padding-top: ${top ? isNaN(top) ? top : top + 'px' : 0};
52
- opacity: 0;
53
- transition: opacity 0.3s ease;
54
- z-index: ${zIndexCORE()};
55
- `;
56
- const fadeInDown = keyframes`
57
- 0% {
58
- opacity: 0;
59
- -webkit-transform: translate3d(0, -30px, 0);
60
- transform: translate3d(0, -30px, 0);
61
- }
62
- to {
63
- opacity: 1;
64
- -webkit-transform: translateZ(0);
65
- transform: translateZ(0);
66
- }
67
- `;
68
- const fadeOutUp = keyframes`
69
- 0% {
70
- opacity: 1;
71
- }
72
- to {
73
- opacity: 0;
74
- -webkit-transform: translate3d(0, -30px, 0);
75
- transform: translate3d(0, -30px, 0);
76
- }
77
- `;
78
- const ModalBox = css`
79
- display: flex;
80
- flex-direction: column;
81
- position: relative;
82
- background-color: white;
83
- ${typography.paragraph1};
84
- height: max-content;
85
- max-height: calc(100% - ${isNaN(top) ? top : +top + 'px'});
86
- min-width: 150px;
87
- max-width: 90%;
88
- /* min-height: 152px; */
89
- margin: 0 auto;
90
- border-radius: 4px;
91
- box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
92
- box-sizing: border-box;
93
- -webkit-box-orient: vertical;
94
- -webkit-box-direction: normal;
95
- width: ${isNaN(width) ? width : width + 'px'};
96
- animation: ${fadeOutUp} 0.2s ease;
97
- animation-fill-mode: forwards;
98
- cursor: ${moveable && dragAnyWhere ? 'move' : 'initial'};
99
- &.show {
100
- display: flex !important;
101
- animation: ${fadeInDown} 0.2s ease;
102
- }
103
- `;
44
+
45
+ const _ModalContainerCSS = ModalContainerCSS(zIndex, alignment, darkTheme);
46
+
47
+ const _ModalBoxCSS = ModalBoxCSS(width, moveable, dragAnyWhere);
104
48
 
105
49
  const onShowModal = () => {
106
50
  setOpenState(true);
107
51
  };
108
52
 
109
53
  const onCloseModal = () => {
110
- if (onClose) onClose();else {
111
- setTimeout(() => {
112
- setOpenState(false);
113
- }, 500);
114
- }
54
+ onClose && onClose();
55
+ setOpenState(false);
115
56
 
116
57
  if (pressESCToClose) {
117
58
  document.removeEventListener('keydown', pressESCHandler);
118
59
  }
119
-
120
- if (ref.current) {
121
- ref.current.style.opacity = null;
122
- ref.current.firstChild.classList.remove('show');
123
- }
124
60
  };
125
61
 
126
62
  const pressESCHandler = event => {
127
63
  if (event.key === 'Escape') {
128
64
  const modals = document.querySelectorAll('.DGN-UI-Portal');
129
65
 
130
- if (modals && modals.length > 1 && Array.from(modals)[modals.length - 1] && !Array.from(modals)[modals.length - 1].contains(ref.current)) {
66
+ if ((modals === null || modals === void 0 ? void 0 : modals.length) > 1 && Array.from(modals)[modals.length - 1] && !Array.from(modals)[modals.length - 1].contains(ref.current)) {
131
67
  return;
132
68
  }
133
69
 
@@ -191,30 +127,11 @@ const Modal = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
191
127
  };
192
128
 
193
129
  useEffect(() => {
194
- if (open) {
195
- setOpenState(open);
196
- }
197
-
198
- return () => {
199
- if (open && ref.current) {
200
- setTimeout(() => {
201
- setOpenState(!open);
202
- }, 500);
203
- }
204
- };
130
+ setOpenState(open);
205
131
  }, [open]);
206
- useEffect(() => {
207
- return () => {
208
- if (pressESCToClose) {
209
- document.removeEventListener('keydown', pressESCHandler);
210
- }
211
- };
212
- }, []);
213
132
  useEffect(() => {
214
133
  if (openState) {
215
134
  if (ref.current) {
216
- ref.current.style.opacity = 1;
217
- ref.current.firstChild.classList.add('show');
218
135
  const modals = document.querySelectorAll('.DGN-UI-Modal');
219
136
 
220
137
  if (!darkTheme && modals && modals.length > 1) {
@@ -229,18 +146,25 @@ const Modal = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
229
146
  }
230
147
  }
231
148
 
232
- document.body.style.overflow = 'hidden'; // Allow press ESC to close popup
149
+ document.documentElement.style.overflow = 'hidden'; // Allow press ESC to close popup
233
150
 
234
151
  if (pressESCToClose) {
235
152
  document.addEventListener('keydown', pressESCHandler);
236
153
  }
237
-
238
- return () => {
239
- document.body.style.overflow = null;
240
- };
154
+ } else {
155
+ document.documentElement.style.overflow = null;
241
156
  }
242
157
  }, [openState]);
243
- const ModalView = useMemo(() => {
158
+ useImperativeHandle(reference, () => {
159
+ const currentRef = ref.current || {};
160
+ const _instance = {}; // methods
161
+
162
+ _instance.__proto__ = {}; // hidden methods
163
+
164
+ currentRef.instance = _instance;
165
+ return currentRef;
166
+ });
167
+ return useMemo(() => {
244
168
  if (openState) {
245
169
  const node = jsx("div", {
246
170
  className: 'DGN-UI-Portal DGN-UI-Modal',
@@ -250,13 +174,14 @@ const Modal = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
250
174
  inset: 0
251
175
  }
252
176
  }, jsx("div", {
253
- css: ModalContainer,
177
+ css: _ModalContainerCSS,
178
+ className: 'DGN-UI-Modal-Container',
254
179
  ref: ref
255
180
  }, jsx("div", {
256
- css: ModalBox,
181
+ css: _ModalBoxCSS,
257
182
  ref: modalBoxRef,
258
- ...props,
259
183
  onMouseDown: moveable && dragAnyWhere ? dragMouseDown : null,
184
+ className: 'DGN-UI-Modal-Box',
260
185
  style: style
261
186
  }, jsx(ModalContext.Provider, {
262
187
  value: {
@@ -269,9 +194,44 @@ const Modal = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
269
194
  }
270
195
 
271
196
  return null;
272
- });
273
- return ModalView;
197
+ }, [moveable, dragAnyWhere, style, children, openState]);
274
198
  }));
199
+
200
+ const ModalContainerCSS = (zIndex, alignment, darkTheme) => css`
201
+ ${flexRow};
202
+ ${positionFixed};
203
+ ${justifyCenter};
204
+ z-index: ${zIndex};
205
+ align-items: ${alignment === 'top' ? 'inherit' : 'center'};
206
+ padding-top: ${alignment === 'top' ? '12px' : 0};
207
+ background-color: ${darkTheme ? 'rgba(21, 26, 48, 0.5)' : 'transparent'};
208
+ width: 100%;
209
+ height: 100vh;
210
+ top: 0;
211
+ left: 0;
212
+ `;
213
+
214
+ const ModalBoxCSS = (width, moveable, dragAnyWhere) => css`
215
+ ${paragraph1};
216
+ ${flexCol};
217
+ ${positionRelative};
218
+ ${borderRadius4px}
219
+ ${borderBox};
220
+ ${parseWidth(width)}
221
+ cursor: ${moveable && dragAnyWhere ? 'move' : 'initial'};
222
+ max-height: calc(100% - 12px);
223
+ height: max-content;
224
+ background-color: ${white};
225
+ min-width: 150px;
226
+ max-width: 90%;
227
+ margin: 0 auto;
228
+ box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
229
+ -webkit-box-orient: vertical;
230
+ -webkit-box-direction: normal;
231
+ animation: ${fadeInDown} 0.2s ease;
232
+ animation-fill-mode: forwards;
233
+ `;
234
+
275
235
  Modal.defaultProps = {
276
236
  darkTheme: true,
277
237
  open: false,
@@ -280,11 +240,14 @@ Modal.defaultProps = {
280
240
  dragAnyWhere: false,
281
241
  moveOutScreen: false,
282
242
  autoFocus: true,
283
- top: '',
243
+ alignment: 'top',
284
244
  width: '80%',
285
245
  zIndex: zIndexCORE()
286
246
  };
287
247
  Modal.propTypes = {
248
+ /** Set the position on the component. */
249
+ alignment: PropTypes.oneOf(['top', 'center']),
250
+
288
251
  /** park a good colored background under the modal box if true */
289
252
  darkTheme: PropTypes.bool,
290
253
 
@@ -309,25 +272,16 @@ Modal.propTypes = {
309
272
  /** z-index style of Modal */
310
273
  zIndex: PropTypes.number,
311
274
 
312
- /** customize the vertical position of the screen, if not set, the modal will be fixed in the middle of the screen */
313
- top: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
314
-
315
275
  /** width of the modal */
316
276
  width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
317
277
 
318
278
  /** customize style inline */
319
279
  style: PropTypes.object,
320
280
 
321
- /** get modal ref by function */
322
- refs: PropTypes.func,
323
-
324
281
  /** the function to run when close modal */
325
282
  onClose: PropTypes.func,
326
283
 
327
284
  /** child content in body */
328
- children: PropTypes.node,
329
-
330
- /** any props else */
331
- props: PropTypes.any
285
+ children: PropTypes.node
332
286
  };
333
287
  export default Modal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.35-beta.3",
3
+ "version": "1.3.35-beta.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",