dce-reactkit 3.7.8 → 3.7.10-beta.0

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.
@@ -26,7 +26,7 @@ import roundToNumDecimals from '../helpers/roundToNumDecimals';
26
26
  import genCSV from '../helpers/genCSV';
27
27
 
28
28
  // Import shared components
29
- import Modal from './Modal';
29
+ import Modal from './Modal/ModalForWrapper';
30
30
  import ModalType from '../types/ModalType';
31
31
  import CheckboxButton from './CheckboxButton';
32
32
  import CSVDownloadButton from './CSVDownloadButton';
@@ -4,7 +4,8 @@
4
4
  /* eslint-disable react/destructuring-assignment */
5
5
 
6
6
  /**
7
- * A generic popup modal
7
+ * The displayable modal component (this is the modal that's added to the
8
+ * wrapper, not the one that the programmer renders)
8
9
  * @author Gabe Abrams
9
10
  */
10
11
 
@@ -12,18 +13,19 @@
12
13
  import React, { useState, useEffect, useRef } from 'react';
13
14
 
14
15
  // Import other components
15
- import waitMs from '../helpers/waitMs';
16
+ import waitMs from '../../helpers/waitMs';
16
17
 
17
18
  // Import types
18
- import Variant from '../types/Variant';
19
- import ModalButtonType from '../types/ModalButtonType';
20
- import ModalSize from '../types/ModalSize';
21
- import ModalType from '../types/ModalType';
19
+ import Variant from '../../types/Variant';
20
+ import ModalButtonType from '../../types/ModalButtonType';
21
+ import ModalSize from '../../types/ModalSize';
22
+ import ModalType from '../../types/ModalType';
23
+ import ModalProps from './ModalProps';
22
24
 
23
25
  // Import shared helpers
24
26
  // TODO: fix dependency cycle
25
27
  // eslint-disable-next-line import/no-cycle
26
- import { isDarkModeOn } from '../client/initClient';
28
+ import { isDarkModeOn } from '../../client/initClient';
27
29
 
28
30
  /*------------------------------------------------------------------------*/
29
31
  /* ------------------------------ Constants ----------------------------- */
@@ -142,7 +144,7 @@ const getModalButtonTypeToLabelAndVariant = () => {
142
144
  /*------------------------------------------------------------------------*/
143
145
 
144
146
  const style = `
145
- .Modal-backdrop {
147
+ .ModalForWrapper-backdrop {
146
148
  position: fixed;
147
149
  top: 0;
148
150
  left: 0;
@@ -150,7 +152,7 @@ const style = `
150
152
  height: 200vh;
151
153
  background-color: rgba(0, 0, 0, 0.7);
152
154
  }
153
- .Modal-fading-in {
155
+ .ModalForWrapper-fading-in {
154
156
  animation-name: Modal-fading-in;
155
157
  animation-duration: ${Math.floor(MS_TO_ANIMATE * 2)}ms;
156
158
  animation-iteration-count: 1;
@@ -165,7 +167,7 @@ const style = `
165
167
  opacity: 1;
166
168
  }
167
169
  }
168
- .Modal-animating-in {
170
+ .ModalForWrapper-animating-in {
169
171
  animation-name: Modal-animating-in;
170
172
  animation-duration: ${MS_TO_ANIMATE}ms;
171
173
  animation-iteration-count: 1;
@@ -182,14 +184,14 @@ const style = `
182
184
  opacity: 1;
183
185
  }
184
186
  }
185
- .Modal-animating-pop {
186
- animation-name: Modal-animating-pop;
187
+ .ModalForWrapper-animating-pop {
188
+ animation-name: ModalForWrapper-animating-pop;
187
189
  animation-duration: ${MS_TO_ANIMATE}ms;
188
190
  animation-iteration-count: 1;
189
191
  animation-fill-mode: both;
190
192
  animation-timing-function: ease-in-out;
191
193
  }
192
- @keyframes Modal-animating-pop {
194
+ @keyframes ModalForWrapper-animating-pop {
193
195
  0% {
194
196
  transform: scale(1);
195
197
  opacity: 1;
@@ -203,80 +205,13 @@ const style = `
203
205
  opacity: 1;
204
206
  }
205
207
  }
206
-
207
- .modal-dialog-scrollable {
208
- height: 100% !important;
209
- }
210
208
  `;
211
209
 
212
- /*------------------------------------------------------------------------*/
213
- /* -------------------------------- Types ------------------------------- */
214
- /*------------------------------------------------------------------------*/
215
-
216
- type Props = {
217
- // Type of the modal
218
- type?: ModalType,
219
- // Size of the modal
220
- size?: ModalSize,
221
- // Title of the modal (if excluded, no header)
222
- title?: React.ReactNode,
223
- // The body of the modal
224
- children?: React.ReactNode,
225
- // Handler to call when modal is closed (if excluded, not closable)
226
- onClose?: (type: ModalButtonType) => void,
227
- // If true, don't allow the user to click the backdrop to exit
228
- dontAllowBackdropExit?: boolean,
229
- // If true, don't show the "X" close button
230
- dontShowXButton?: boolean,
231
- // Custom label for "okay" button
232
- okayLabel?: string,
233
- // Custom variant for "okay" button
234
- okayVariant?: Variant,
235
- // Custom label for "cancel" button
236
- cancelLabel?: string,
237
- // Custom variant for "cancel" button
238
- cancelVariant?: Variant,
239
- // Custom label for "yes" button
240
- yesLabel?: string,
241
- // Custom variant for "yes" button
242
- yesVariant?: Variant,
243
- // Custom label for "no" button
244
- noLabel?: string,
245
- // Custom variant for "no" button
246
- noVariant?: Variant,
247
- // Custom label for "abandon" button
248
- abandonLabel?: string,
249
- // Custom variant for "abandon" button
250
- abandonVariant?: Variant,
251
- // Custom label for "goBack" button
252
- goBackLabel?: string,
253
- // Custom variant for "goBack" button
254
- goBackVariant?: Variant,
255
- // Custom label for "continue" button
256
- continueLabel?: string,
257
- // Custom variant for "continue" button
258
- continueVariant?: Variant,
259
- // Custom label for "imSure" button
260
- imSureLabel?: string,
261
- // Custom variant for "imSure" button
262
- imSureVariant?: Variant,
263
- // Custom label for "delete" button
264
- deleteLabel?: string,
265
- // Custom variant for "delete" button
266
- deleteVariant?: Variant,
267
- // Custom label for "confirm" button
268
- confirmLabel?: string,
269
- // Custom variant for "confirm" button
270
- confirmVariant?: Variant,
271
- // True if modal should be on top of other modals
272
- onTopOfOtherModals?: boolean,
273
- };
274
-
275
210
  /*------------------------------------------------------------------------*/
276
211
  /* ------------------------------ Component ----------------------------- */
277
212
  /*------------------------------------------------------------------------*/
278
213
 
279
- const Modal: React.FC<Props> = (props) => {
214
+ const Modal: React.FC<ModalProps> = (props) => {
280
215
  /*------------------------------------------------------------------------*/
281
216
  /* -------------------------------- Setup ------------------------------- */
282
217
  /*------------------------------------------------------------------------*/
@@ -387,7 +322,7 @@ const Modal: React.FC<Props> = (props) => {
387
322
  <button
388
323
  key={modalButtonType}
389
324
  type="button"
390
- className={`Modal-${modalButtonType}-button btn btn-${variant} ${last ? '' : 'me-1'}`}
325
+ className={`ModalForWrapper-${modalButtonType}-button btn btn-${variant} ${last ? '' : 'me-1'}`}
391
326
  onClick={() => {
392
327
  handleClose(modalButtonType);
393
328
  }}
@@ -412,10 +347,10 @@ const Modal: React.FC<Props> = (props) => {
412
347
  let animationClass = '';
413
348
  let backdropAnimationClass = '';
414
349
  if (animatingIn) {
415
- animationClass = 'Modal-animating-in';
416
- backdropAnimationClass = 'Modal-fading-in';
350
+ animationClass = 'ModalForWrapper-animating-in';
351
+ backdropAnimationClass = 'ModalForWrapper-fading-in';
417
352
  } else if (animatingPop) {
418
- animationClass = 'Modal-animating-pop';
353
+ animationClass = 'ModalForWrapper-animating-pop';
419
354
  }
420
355
 
421
356
  // Render the modal
@@ -437,7 +372,7 @@ const Modal: React.FC<Props> = (props) => {
437
372
  >
438
373
  <style>{style}</style>
439
374
  <div
440
- className={`Modal-backdrop ${backdropAnimationClass}`}
375
+ className={`ModalForWrapper-backdrop ${backdropAnimationClass}`}
441
376
  style={{
442
377
  zIndex: 5000000003,
443
378
  }}
@@ -506,7 +441,7 @@ const Modal: React.FC<Props> = (props) => {
506
441
  {(onClose && !dontShowXButton) && (
507
442
  <button
508
443
  type="button"
509
- className="Modal-x-button btn-close"
444
+ className="ModalForWrapper-x-button btn-close"
510
445
  aria-label="Close"
511
446
  style={{
512
447
  backgroundColor: (
@@ -0,0 +1,72 @@
1
+ // Import types
2
+ import Variant from '../../types/Variant';
3
+ import ModalButtonType from '../../types/ModalButtonType';
4
+ import ModalSize from '../../types/ModalSize';
5
+ import ModalType from '../../types/ModalType';
6
+
7
+ /**
8
+ * Props for the Modal component
9
+ * @author Gabe Abrams
10
+ */
11
+ type ModalProps = {
12
+ // Key of the modal
13
+ key?: string,
14
+ // Type of the modal
15
+ type?: ModalType,
16
+ // Size of the modal
17
+ size?: ModalSize,
18
+ // Title of the modal (if excluded, no header)
19
+ title?: React.ReactNode,
20
+ // The body of the modal
21
+ children?: React.ReactNode,
22
+ // Handler to call when modal is closed (if excluded, not closable)
23
+ onClose?: (type: ModalButtonType) => void,
24
+ // If true, don't allow the user to click the backdrop to exit
25
+ dontAllowBackdropExit?: boolean,
26
+ // If true, don't show the "X" close button
27
+ dontShowXButton?: boolean,
28
+ // Custom label for "okay" button
29
+ okayLabel?: string,
30
+ // Custom variant for "okay" button
31
+ okayVariant?: Variant,
32
+ // Custom label for "cancel" button
33
+ cancelLabel?: string,
34
+ // Custom variant for "cancel" button
35
+ cancelVariant?: Variant,
36
+ // Custom label for "yes" button
37
+ yesLabel?: string,
38
+ // Custom variant for "yes" button
39
+ yesVariant?: Variant,
40
+ // Custom label for "no" button
41
+ noLabel?: string,
42
+ // Custom variant for "no" button
43
+ noVariant?: Variant,
44
+ // Custom label for "abandon" button
45
+ abandonLabel?: string,
46
+ // Custom variant for "abandon" button
47
+ abandonVariant?: Variant,
48
+ // Custom label for "goBack" button
49
+ goBackLabel?: string,
50
+ // Custom variant for "goBack" button
51
+ goBackVariant?: Variant,
52
+ // Custom label for "continue" button
53
+ continueLabel?: string,
54
+ // Custom variant for "continue" button
55
+ continueVariant?: Variant,
56
+ // Custom label for "imSure" button
57
+ imSureLabel?: string,
58
+ // Custom variant for "imSure" button
59
+ imSureVariant?: Variant,
60
+ // Custom label for "delete" button
61
+ deleteLabel?: string,
62
+ // Custom variant for "delete" button
63
+ deleteVariant?: Variant,
64
+ // Custom label for "confirm" button
65
+ confirmLabel?: string,
66
+ // Custom variant for "confirm" button
67
+ confirmVariant?: Variant,
68
+ // True if modal should be on top of other modals
69
+ onTopOfOtherModals?: boolean,
70
+ };
71
+
72
+ export default ModalProps;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * General use modal component
3
+ * @author Gabe Abrams
4
+ */
5
+
6
+ // Import React
7
+ import React, { useEffect, useRef } from 'react';
8
+
9
+ // Import shared types
10
+ import ModalProps from './ModalProps';
11
+
12
+ // Import helpers from AppWrapper
13
+ import { addModal, removeModal, updateModal } from '../AppWrapper';
14
+
15
+ /*------------------------------------------------------------------------*/
16
+ /* --------------------------- Static Helpers --------------------------- */
17
+ /*------------------------------------------------------------------------*/
18
+
19
+ // Next unique id
20
+ let nextUniqueId = 0;
21
+
22
+ /**
23
+ * Get a new unique id for this modal
24
+ * @author Gabe Abrams
25
+ * @returns new unique id
26
+ */
27
+ const getNextUniqueId = (): number => {
28
+ // eslint-disable-next-line no-plusplus
29
+ return nextUniqueId++;
30
+ };
31
+
32
+ /*------------------------------------------------------------------------*/
33
+ /* ------------------------------ Component ----------------------------- */
34
+ /*------------------------------------------------------------------------*/
35
+
36
+ const Modal: React.FC<ModalProps> = (props) => {
37
+ /*------------------------------------------------------------------------*/
38
+ /* -------------------------------- Setup ------------------------------- */
39
+ /*------------------------------------------------------------------------*/
40
+
41
+ /* -------------- Refs -------------- */
42
+
43
+ // Initialize refs
44
+ const id = useRef<number>(getNextUniqueId());
45
+
46
+ /*------------------------------------------------------------------------*/
47
+ /* ------------------------- Lifecycle Functions ------------------------ */
48
+ /*------------------------------------------------------------------------*/
49
+
50
+ /**
51
+ * Mount: add to app wrapper
52
+ * @author Gabe Abrams
53
+ */
54
+ useEffect(
55
+ () => {
56
+ addModal(id.current, props);
57
+ },
58
+ [],
59
+ );
60
+
61
+ /**
62
+ * Update: update modal props in app wrapper when props change
63
+ * @author Gabe Abrams
64
+ */
65
+ useEffect(
66
+ () => {
67
+ // Update modal props
68
+ updateModal(id.current, props);
69
+ },
70
+ [props],
71
+ );
72
+
73
+ /**
74
+ * Unmount: remove from app wrapper when unmounting
75
+ * @author Gabe Abrams
76
+ */
77
+ useEffect(
78
+ () => {
79
+ return () => {
80
+ // Remove modal
81
+ removeModal(id.current);
82
+ };
83
+ },
84
+ [],
85
+ );
86
+
87
+ /*------------------------------------------------------------------------*/
88
+ /* ------------------------------- Render ------------------------------- */
89
+ /*------------------------------------------------------------------------*/
90
+
91
+ /*----------------------------------------*/
92
+ /* --------------- Main UI -------------- */
93
+ /*----------------------------------------*/
94
+
95
+ return (
96
+ <div className="Modal-shell d-none" />
97
+ );
98
+ };
99
+
100
+ /*------------------------------------------------------------------------*/
101
+ /* ------------------------------- Wrap Up ------------------------------ */
102
+ /*------------------------------------------------------------------------*/
103
+
104
+ // Export component
105
+ export default Modal;
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ import AppWrapper, {
8
8
  } from './components/AppWrapper';
9
9
  import LoadingSpinner from './components/LoadingSpinner';
10
10
  import ErrorBox from './components/ErrorBox';
11
- import Modal from './components/Modal';
11
+ import Modal from './components/Modal/ModalForWrapper';
12
12
  import TabBox from './components/TabBox';
13
13
  import RadioButton from './components/RadioButton';
14
14
  import CheckboxButton from './components/CheckboxButton';