dce-reactkit 2.0.9 → 2.0.12

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.
Files changed (48) hide show
  1. package/lib/components/AppWrapper.d.ts +16 -1
  2. package/lib/components/AppWrapper.js +157 -13
  3. package/lib/components/AppWrapper.js.map +1 -1
  4. package/lib/components/Modal.d.ts +2 -0
  5. package/lib/components/Modal.js +9 -3
  6. package/lib/components/Modal.js.map +1 -1
  7. package/lib/components/TabBox.d.ts +11 -0
  8. package/lib/components/TabBox.js +42 -0
  9. package/lib/components/TabBox.js.map +1 -0
  10. package/lib/helpers/alert.d.ts +2 -0
  11. package/lib/helpers/alert.js +6 -0
  12. package/lib/helpers/alert.js.map +1 -0
  13. package/lib/helpers/confirm.d.ts +2 -0
  14. package/lib/helpers/confirm.js +6 -0
  15. package/lib/helpers/confirm.js.map +1 -0
  16. package/lib/helpers/showFatalError.d.ts +1 -1
  17. package/lib/helpers/showFatalError.js +2 -1
  18. package/lib/helpers/showFatalError.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/components/AppWrapper.tsx +191 -11
  21. package/src/components/Modal.tsx +16 -2
  22. package/src/components/TabBox.tsx +136 -0
  23. package/src/helpers/alert.tsx +5 -0
  24. package/src/helpers/confirm.tsx +5 -0
  25. package/src/helpers/showFatalError.tsx +3 -1
  26. package/lib/components/AppWrapper.tsx +0 -181
  27. package/lib/components/ErrorBox.tsx +0 -124
  28. package/lib/components/LoadingSpinner.tsx +0 -105
  29. package/lib/components/Modal.tsx +0 -447
  30. package/lib/errors/ErrorWithCode.tsx +0 -15
  31. package/lib/helpers/abbreviate.tsx +0 -23
  32. package/lib/helpers/avg.tsx +0 -22
  33. package/lib/helpers/ceilToNumDecimals.tsx +0 -13
  34. package/lib/helpers/floorToNumDecimals.tsx +0 -13
  35. package/lib/helpers/forceNumIntoBounds.tsx +0 -19
  36. package/lib/helpers/handleError.ts +0 -65
  37. package/lib/helpers/handleSuccess.ts +0 -18
  38. package/lib/helpers/padDecimalZeros.tsx +0 -32
  39. package/lib/helpers/padZerosLeft.tsx +0 -21
  40. package/lib/helpers/parseRequest.ts +0 -299
  41. package/lib/helpers/roundToNumDecimals.tsx +0 -13
  42. package/lib/helpers/showFatalError.tsx +0 -3
  43. package/lib/helpers/sum.tsx +0 -16
  44. package/lib/helpers/visitServerEndpoint.tsx +0 -110
  45. package/lib/helpers/waitMs.tsx +0 -12
  46. package/lib/types/ParamType.ts +0 -18
  47. package/lib/types/ReactKitErrorCode.tsx +0 -16
  48. package/lib/types/Variant.tsx +0 -16
@@ -1,124 +0,0 @@
1
- /**
2
- * Displays an error
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import React
7
- import React from 'react';
8
-
9
- // Import FontAwesome Icons
10
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
11
- import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
12
-
13
- // Import shared types
14
- import ReactKitErrorCode from '../types/ReactKitErrorCode';
15
-
16
- /*------------------------------------------------------------------------*/
17
- /* Types */
18
- /*------------------------------------------------------------------------*/
19
-
20
- type Props = {
21
- // Error to display
22
- error: any,
23
- // Customized title of error box
24
- title?: string,
25
- // Handler for close,
26
- onClose?: () => void,
27
- };
28
-
29
- /*------------------------------------------------------------------------*/
30
- /* Component */
31
- /*------------------------------------------------------------------------*/
32
-
33
- const ErrorBox: React.FC<Props> = (props) => {
34
- /*------------------------------------------------------------------------*/
35
- /* Setup */
36
- /*------------------------------------------------------------------------*/
37
-
38
- /* -------------- Props ------------- */
39
-
40
- const {
41
- error,
42
- title = 'An Error Occurred',
43
- onClose,
44
- } = props;
45
-
46
- /*------------------------------------------------------------------------*/
47
- /* Render */
48
- /*------------------------------------------------------------------------*/
49
-
50
- // Determine error text
51
- const errorText: string = (
52
- typeof error === 'string'
53
- ? error.trim()
54
- : String(error.message || 'An unknown error occurred. Please contact support.')
55
- );
56
-
57
- // Error code box
58
- let errorCodeBox;
59
- if (error && (error as any).code) {
60
- errorCodeBox = (
61
- <span>
62
- {' '}
63
- <span
64
- style={{
65
- backgroundColor: 'white',
66
- borderRadius: '5px',
67
- paddingLeft: '3px',
68
- paddingRight: '3px',
69
- color: '#DC4150',
70
- fontVariant: 'small-caps',
71
- fontSize: '80%',
72
- whiteSpace: 'nowrap',
73
- }}
74
- >
75
- code:
76
- {' '}
77
- {String((error as any).code ?? ReactKitErrorCode.NoCode).toUpperCase()}
78
- </span>
79
- </span>
80
- );
81
- }
82
-
83
- // Main UI
84
- return (
85
- <div
86
- className="alert alert-danger text-center"
87
- style={{
88
- maxWidth: '650px',
89
- margin: 'auto',
90
- }}
91
- >
92
- <h4 className="mb-1">
93
- <FontAwesomeIcon
94
- icon={faExclamationTriangle}
95
- className="me-2"
96
- />
97
- {title}
98
- </h4>
99
- <div>
100
- {errorText}
101
- {errorCodeBox}
102
- </div>
103
- {onClose && (
104
- <div className="mt-2">
105
- <button
106
- type="button"
107
- className="btn btn-light"
108
- aria-label="dismiss error and close this activity or view"
109
- onClick={onClose}
110
- >
111
- Close
112
- </button>
113
- </div>
114
- )}
115
- </div>
116
- );
117
- };
118
-
119
- /*------------------------------------------------------------------------*/
120
- /* Wrap Up */
121
- /*------------------------------------------------------------------------*/
122
-
123
- // Export component
124
- export default ErrorBox;
@@ -1,105 +0,0 @@
1
- /**
2
- * Loading spinner/indicator
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import FontAwesome Icons
7
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
- import { faCircle } from '@fortawesome/free-solid-svg-icons';
9
-
10
- /*------------------------------------------------------------------------*/
11
- /* Style */
12
- /*------------------------------------------------------------------------*/
13
-
14
- const style = `
15
- /* Blips */
16
- .LoadingSpinner-blip-1,
17
- .LoadingSpinner-blip-2,
18
- .LoadingSpinner-blip-3,
19
- .LoadingSpinner-blip-4 {
20
- font-size: 25px;
21
- opacity: 0.6;
22
- margin-top: 20px;
23
- margin-bottom: 20px;
24
- }
25
-
26
- /* First Blip */
27
- .LoadingSpinner-blip-1 {
28
- animation: LoadingSpinner-pop-animation 2s infinite;
29
- }
30
-
31
- /* Second Blip */
32
- .LoadingSpinner-blip-2 {
33
- animation: LoadingSpinner-pop-animation 2s infinite;
34
- -webkit-animation-delay: 0.1s;
35
- animation-delay: 0.1s;
36
- }
37
-
38
- /* Third Blip */
39
- .LoadingSpinner-blip-3 {
40
- animation: LoadingSpinner-pop-animation 2s infinite;
41
- animation-delay: 0.2s;
42
- }
43
-
44
- /* Fourth Blip */
45
- .LoadingSpinner-blip-4 {
46
- animation: LoadingSpinner-pop-animation 2s infinite;
47
- animation-delay: 0.3s;
48
- }
49
-
50
- /* Pop Animation for Each Blip */
51
- @keyframes LoadingSpinner-pop-animation {
52
- 0% {
53
- transform: scale(1.0);
54
- }
55
- 10% {
56
- transform: scale(1.5);
57
- }
58
- 30% {
59
- transform: scale(1.0);
60
- }
61
- 100% {
62
- transform: scale(1.0);
63
- }
64
- }
65
- `;
66
-
67
- /*------------------------------------------------------------------------*/
68
- /* Component */
69
- /*------------------------------------------------------------------------*/
70
-
71
- const LoadingSpinner = () => {
72
- /*------------------------------------------------------------------------*/
73
- /* Render */
74
- /*------------------------------------------------------------------------*/
75
-
76
- // Add all four blips to a container
77
- return (
78
- <div className="text-center LoadingSpinner LoadingSpinner-container">
79
- <style>{style}</style>
80
- <FontAwesomeIcon
81
- icon={faCircle}
82
- className="LoadingSpinner-blip-1 me-1"
83
- />
84
- <FontAwesomeIcon
85
- icon={faCircle}
86
- className="LoadingSpinner-blip-2 me-1"
87
- />
88
- <FontAwesomeIcon
89
- icon={faCircle}
90
- className="LoadingSpinner-blip-3 me-1"
91
- />
92
- <FontAwesomeIcon
93
- icon={faCircle}
94
- className="LoadingSpinner-blip-4"
95
- />
96
- </div>
97
- );
98
- };
99
-
100
- /*------------------------------------------------------------------------*/
101
- /* Wrap Up */
102
- /*------------------------------------------------------------------------*/
103
-
104
- // Export component
105
- export default LoadingSpinner;
@@ -1,447 +0,0 @@
1
- /**
2
- * A generic popup modal
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import React
7
- import React, { useState, useEffect } from 'react';
8
-
9
- // Import other components
10
- import BootstrapModal from 'react-bootstrap/Modal';
11
- import waitMs from '../helpers/waitMs';
12
-
13
- // Import types
14
- import Variant from '../types/Variant';
15
-
16
- /*------------------------------------------------------------------------*/
17
- /* Style */
18
- /*------------------------------------------------------------------------*/
19
-
20
- const style = `
21
- /* More opaque backdrop */
22
- .Modal-backdrop {
23
- background-color: black !important;
24
- opacity: 0.8 !important;
25
- z-index: 10000000 !important;
26
- }
27
-
28
- /* Customize the modal header and body */
29
- .modal-header {
30
- /* Dark theme */
31
- background-color: #222 !important;
32
- color: white !important;
33
-
34
- /* Border */
35
- border: 1px solid #545454 !important;
36
- }
37
- .modal-body {
38
- /* Dark theme */
39
- background-color: #222 !important;
40
- color: white !important;
41
-
42
- /* Border */
43
- border-top: 0 !important;
44
- border-left: 1px solid #545454 !important;
45
- border-bottom: 1px solid #545454 !important;
46
- border-right: 1px solid #545454 !important;
47
- border-bottom-left-radius: 3px;
48
- border-bottom-right-radius: 3px;
49
- }
50
-
51
- /* Create our own animation */
52
- .modal-content {
53
- animation-name: Modal-drop-in;
54
- animation-duration: 0.4s;
55
- animation-iteration-count: 1;
56
- animation-fill-mode: forwards;
57
- animation-timing-function: ease-out;
58
- }
59
- @keyframes Modal-drop-in {
60
- 0% {
61
- transform: scale(0.8);
62
- opacity: 0.5;
63
- }
64
- 100% {
65
- transform: scale(1);
66
- opacity: 1;
67
- }
68
- }
69
- `;
70
-
71
- /*------------------------------------------------------------------------*/
72
- /* Constants */
73
- /*------------------------------------------------------------------------*/
74
-
75
- // Constants
76
- const MS_TO_ANIMATE = 400; // Time to animate in/out (defined by bootstrap)
77
- const MS_ANIMATE_IN_DELAY = 10;
78
- // Time to wait before animating in (must be >0 or animation won't trigger)
79
-
80
- // Modal types
81
- enum ModalType {
82
- Okay = 'okay', // [Okay]
83
- OkayCancel = 'okay-cancel', // [Okay] [Cancel]
84
- YesNo = 'yes-no', // [Yes] [No]
85
- YesNoCancel = 'yes-no-cancel', // [Yes] [No] [Cancel]
86
- AbandonGoBack = 'abandon-goBack', // [Abandon Changes] [Go Back]
87
- ImSureCancel = 'imSure-cancel', // [I am sure] [Cancel]
88
- DeleteCancel = 'delete-cancel', // [Yes, Delete] [Cancel]
89
- ConfirmCancel = 'confirm-cancel', // [Confirm] [Cancel]
90
- NoButtons = '-', // No buttons
91
- }
92
-
93
- // Modal sizes
94
- enum ModalSize {
95
- Small = 'sm',
96
- Medium = 'md',
97
- Large = 'lg',
98
- ExtraLarge = 'xl',
99
- }
100
-
101
- // Button types
102
- enum ButtonType {
103
- Okay = 'okay',
104
- Cancel = 'cancel',
105
- Yes = 'yes',
106
- No = 'no',
107
- Abandon = 'abandon',
108
- GoBack = 'goBack',
109
- Continue = 'continue',
110
- ImSure = 'imSure',
111
- Delete = 'delete',
112
- Confirm = 'confirm',
113
- }
114
-
115
- // Modal type to list of buttons
116
- const modalTypeToButtonTypes: {
117
- [k: string]: ButtonType[]
118
- } = {
119
- [ModalType.Okay]: [
120
- ButtonType.Okay,
121
- ],
122
- [ModalType.OkayCancel]: [
123
- ButtonType.Okay,
124
- ButtonType.Cancel,
125
- ],
126
- [ModalType.YesNo]: [
127
- ButtonType.Yes,
128
- ButtonType.No,
129
- ],
130
- [ModalType.YesNoCancel]: [
131
- ButtonType.Yes,
132
- ButtonType.No,
133
- ButtonType.Cancel,
134
- ],
135
- [ModalType.AbandonGoBack]: [
136
- ButtonType.Abandon,
137
- ButtonType.GoBack,
138
- ],
139
- [ModalType.ImSureCancel]: [
140
- ButtonType.ImSure,
141
- ButtonType.Cancel,
142
- ],
143
- [ModalType.DeleteCancel]: [
144
- ButtonType.Delete,
145
- ButtonType.Cancel,
146
- ],
147
- [ModalType.ConfirmCancel]: [
148
- ButtonType.Confirm,
149
- ButtonType.Cancel,
150
- ],
151
- };
152
-
153
- // Button type styling and labels
154
- const buttonTypeToLabelAndVariant = {
155
- [ButtonType.Okay]: {
156
- label: 'Okay',
157
- variant: Variant.Dark,
158
- },
159
- [ButtonType.Cancel]: {
160
- label: 'Cancel',
161
- variant: Variant.Secondary,
162
- },
163
- [ButtonType.Yes]: {
164
- label: 'Yes',
165
- variant: Variant.Dark,
166
- },
167
- [ButtonType.No]: {
168
- label: 'No',
169
- variant: Variant.Secondary,
170
- },
171
- [ButtonType.Abandon]: {
172
- label: 'Abandon Changes',
173
- variant: Variant.Warning,
174
- },
175
- [ButtonType.GoBack]: {
176
- label: 'Go Back',
177
- variant: Variant.Secondary,
178
- },
179
- [ButtonType.Continue]: {
180
- label: 'Continue',
181
- variant: Variant.Dark,
182
- },
183
- [ButtonType.ImSure]: {
184
- label: 'I am sure',
185
- variant: Variant.Warning,
186
- },
187
- [ButtonType.Delete]: {
188
- label: 'Yes, Delete',
189
- variant: Variant.Danger,
190
- },
191
- [ButtonType.Confirm]: {
192
- label: 'Confirm',
193
- variant: Variant.Dark,
194
- },
195
- };
196
-
197
- /*------------------------------------------------------------------------*/
198
- /* Types */
199
- /*------------------------------------------------------------------------*/
200
-
201
- type Props = {
202
- // Type of the modal
203
- type?: ModalType,
204
- // Size of the modal
205
- size?: ModalSize,
206
- // Title of the modal (if excluded, no header)
207
- title?: React.ReactNode,
208
- // The body of the modal
209
- children?: React.ReactNode,
210
- // Handler to call when modal is closed (if excluded, not closable)
211
- onClose?: (type: ButtonType) => void,
212
- // Custom label for "okay" button
213
- okayLabel?: string,
214
- // Custom variant for "okay" button
215
- okayVariant?: Variant,
216
- // Custom label for "cancel" button
217
- cancelLabel?: string,
218
- // Custom variant for "cancel" button
219
- cancelVariant?: Variant,
220
- // Custom label for "yes" button
221
- yesLabel?: string,
222
- // Custom variant for "yes" button
223
- yesVariant?: Variant,
224
- // Custom label for "no" button
225
- noLabel?: string,
226
- // Custom variant for "no" button
227
- noVariant?: Variant,
228
- // Custom label for "abandon" button
229
- abandonLabel?: string,
230
- // Custom variant for "abandon" button
231
- abandonVariant?: Variant,
232
- // Custom label for "goBack" button
233
- goBackLabel?: string,
234
- // Custom variant for "goBack" button
235
- goBackVariant?: Variant,
236
- // Custom label for "continue" button
237
- continueLabel?: string,
238
- // Custom variant for "continue" button
239
- continueVariant?: Variant,
240
- // Custom label for "imSure" button
241
- imSureLabel?: string,
242
- // Custom variant for "imSure" button
243
- imSureVariant?: Variant,
244
- // Custom label for "delete" button
245
- deleteLabel?: string,
246
- // Custom variant for "delete" button
247
- deleteVariant?: Variant,
248
- // Custom label for "confirm" button
249
- confirmLabel?: string,
250
- // Custom variant for "confirm" button
251
- confirmVariant?: Variant,
252
- };
253
-
254
- /*------------------------------------------------------------------------*/
255
- /* Component */
256
- /*------------------------------------------------------------------------*/
257
-
258
- const Modal: (
259
- React.FC<Props>
260
- & {
261
- ModalType: typeof ModalType,
262
- ModalSize: typeof ModalSize,
263
- ButtonType: typeof ButtonType,
264
- Variant: typeof Variant,
265
- }
266
- ) = (props) => {
267
- /*------------------------------------------------------------------------*/
268
- /* Setup */
269
- /*------------------------------------------------------------------------*/
270
-
271
- /* -------------- Props ------------- */
272
-
273
- const {
274
- type = ModalType.NoButtons,
275
- size = ModalSize.Large,
276
- title,
277
- children,
278
- onClose,
279
- } = props;
280
-
281
- /* -------------- State ------------- */
282
-
283
- // If true, the modal is shown
284
- const [visible, setVisible] = useState(false);
285
-
286
- // True if currently animating in
287
- const [animatingIn, setAnimatingIn] = useState(false);
288
-
289
- /*------------------------------------------------------------------------*/
290
- /* Lifecycle Functions */
291
- /*------------------------------------------------------------------------*/
292
-
293
- /**
294
- * Mount
295
- * @author Gabe Abrams
296
- */
297
- useEffect(
298
- () => {
299
- (async () => {
300
- // Start the component animating in
301
- await waitMs(MS_ANIMATE_IN_DELAY);
302
- setAnimatingIn(true);
303
-
304
- // Wait and then set visible to true
305
- await waitMs(MS_TO_ANIMATE);
306
- setVisible(true);
307
- })();
308
- },
309
- [],
310
- );
311
-
312
- /*------------------------------------------------------------------------*/
313
- /* Component Functions */
314
- /*------------------------------------------------------------------------*/
315
-
316
- /**
317
- * Handles the closing of the modal
318
- * @author Gabe Abrams
319
- * @param buttonType the button that was clicked when closing the
320
- * modal
321
- */
322
- const handleClose = async (buttonType: ButtonType) => {
323
- // Don't close if no handler
324
- if (!onClose) {
325
- return;
326
- }
327
-
328
- // Don't close if animating in
329
- if (animatingIn) {
330
- return;
331
- }
332
-
333
- // Don't close if already closed
334
- if (!visible) {
335
- return;
336
- }
337
-
338
- // Update the state
339
- setVisible(false);
340
-
341
- // Call the handler after the modal has animated out
342
- await waitMs(MS_TO_ANIMATE);
343
- onClose(buttonType);
344
- };
345
-
346
- /*------------------------------------------------------------------------*/
347
- /* Render */
348
- /*------------------------------------------------------------------------*/
349
-
350
- /*----------------------------------------*/
351
- /* Footer */
352
- /*----------------------------------------*/
353
-
354
- // Get list of buttons for this modal type
355
- const buttonTypes: ButtonType[] = modalTypeToButtonTypes[type] ?? [];
356
-
357
- // Create buttons
358
- const buttons = buttonTypes.map((buttonType: ButtonType, i) => {
359
- // Get default style
360
- let {
361
- label,
362
- variant,
363
- } = buttonTypeToLabelAndVariant[buttonType];
364
-
365
- // Override with customizations
366
- if (props[`${buttonType}Label`]) {
367
- label = props[`${buttonType}Label`];
368
- }
369
- if (props[`${buttonType}Variant`]) {
370
- variant = props[`${buttonType}Variant`];
371
- }
372
-
373
- // Check if this button is last
374
- const last = (i === buttonTypes.length - 1);
375
-
376
- // Create the button
377
- return (
378
- <button
379
- type="button"
380
- className={`Modal-${buttonType}-button btn btn-${variant} ${last ? '' : 'mr-1'}`}
381
- onClick={() => {
382
- handleClose(buttonType);
383
- }}
384
- >
385
- {label}
386
- </button>
387
- );
388
- });
389
-
390
- // Put all buttons in a footer
391
- const footer = (
392
- (buttons && buttons.length)
393
- ? (
394
- <div>
395
- {buttons}
396
- </div>
397
- )
398
- : undefined
399
- );
400
-
401
- // Render the modal
402
- return (
403
- <BootstrapModal
404
- show={visible}
405
- size={size !== ModalSize.Medium ? size : undefined}
406
- onHide={() => {
407
- handleClose(ButtonType.Cancel);
408
- }}
409
- style={{ zIndex: 5000000000 }}
410
- backdropClassName="Modal-backdrop"
411
- centered
412
- >
413
- <style>{style}</style>
414
- {title && (
415
- <BootstrapModal.Header
416
- closeButton={!!onClose}
417
- >
418
- <BootstrapModal.Title>
419
- {title}
420
- </BootstrapModal.Title>
421
- </BootstrapModal.Header>
422
- )}
423
- {children && (
424
- <BootstrapModal.Body>
425
- {children}
426
- </BootstrapModal.Body>
427
- )}
428
- {footer && (
429
- <BootstrapModal.Footer>
430
- {footer}
431
- </BootstrapModal.Footer>
432
- )}
433
- </BootstrapModal>
434
- );
435
- };
436
-
437
- /*------------------------------------------------------------------------*/
438
- /* Wrap Up */
439
- /*------------------------------------------------------------------------*/
440
-
441
- // Add enums
442
- Modal.ModalType = ModalType;
443
- Modal.ModalSize = ModalSize;
444
- Modal.ButtonType = ButtonType;
445
- Modal.Variant = Variant;
446
-
447
- export default Modal;
@@ -1,15 +0,0 @@
1
- /**
2
- * An error with a code
3
- * @author Gabe Abrams
4
- */
5
- class ErrorWithCode extends Error {
6
- code: string;
7
-
8
- constructor(message: string, code: string) {
9
- super(message);
10
- this.name = 'ErrorWithCode';
11
- this.code = code;
12
- }
13
- }
14
-
15
- export default ErrorWithCode;
@@ -1,23 +0,0 @@
1
- /**
2
- * Shorten text so it fits into a certain number of chars
3
- * @author Gabe Abrams
4
- * @param text the text to abbreviate
5
- * @param maxChars the maximum number of chars to include
6
- * @returns abbreviated text with length no greater than maxChars
7
- * (including ellipses if applicable)
8
- */
9
- const abbreviate = (text: string, maxChars: number): string => {
10
- // Check if already short enough
11
- if (text.trim().length < maxChars) {
12
- return text.trim();
13
- }
14
-
15
- // Abbreviate
16
- const shortenedText = (
17
- text
18
- .trim()
19
- .substring(0, maxChars - 3)
20
- .trim()
21
- );
22
- return `${shortenedText}...`;
23
- };