dce-reactkit 2.0.10 → 3.0.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.
Files changed (187) hide show
  1. package/lib/cjs/index.js +2 -0
  2. package/lib/cjs/index.js.map +1 -0
  3. package/lib/cjs/lib/components/AppWrapper.d.ts +35 -0
  4. package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
  5. package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
  6. package/lib/cjs/lib/components/Modal.d.ts +40 -0
  7. package/lib/cjs/lib/components/TabBox.d.ts +11 -0
  8. package/lib/{errors → cjs/lib/errors}/ErrorWithCode.d.ts +0 -0
  9. package/lib/{helpers → cjs/lib/helpers}/abbreviate.d.ts +1 -0
  10. package/lib/{helpers → cjs/lib/helpers}/avg.d.ts +0 -0
  11. package/lib/{helpers → cjs/lib/helpers}/ceilToNumDecimals.d.ts +0 -0
  12. package/lib/{helpers → cjs/lib/helpers}/floorToNumDecimals.d.ts +0 -0
  13. package/lib/{helpers → cjs/lib/helpers}/forceNumIntoBounds.d.ts +0 -0
  14. package/lib/{helpers → cjs/lib/helpers}/handleError.d.ts +0 -0
  15. package/lib/{helpers → cjs/lib/helpers}/handleSuccess.d.ts +0 -0
  16. package/lib/{helpers → cjs/lib/helpers}/padDecimalZeros.d.ts +0 -0
  17. package/lib/{helpers → cjs/lib/helpers}/padZerosLeft.d.ts +0 -0
  18. package/lib/{helpers → cjs/lib/helpers}/parseRequest.d.ts +1 -1
  19. package/lib/{helpers → cjs/lib/helpers}/roundToNumDecimals.d.ts +0 -0
  20. package/lib/{helpers → cjs/lib/helpers}/sum.d.ts +0 -0
  21. package/lib/{helpers → cjs/lib/helpers}/visitServerEndpoint.d.ts +2 -2
  22. package/lib/{helpers → cjs/lib/helpers}/waitMs.d.ts +0 -0
  23. package/lib/cjs/lib/index.d.ts +27 -0
  24. package/lib/cjs/lib/types/ModalButtonType.d.ts +17 -0
  25. package/lib/cjs/lib/types/ModalSize.d.ts +11 -0
  26. package/lib/cjs/lib/types/ModalType.d.ts +16 -0
  27. package/lib/{types → cjs/lib/types}/ParamType.d.ts +0 -0
  28. package/lib/{types → cjs/lib/types}/ReactKitErrorCode.d.ts +0 -0
  29. package/lib/{types → cjs/lib/types}/Variant.d.ts +0 -0
  30. package/lib/cjs/types/components/AppWrapper.d.ts +40 -0
  31. package/lib/cjs/types/components/ErrorBox.d.ts +12 -0
  32. package/lib/cjs/types/components/LoadingSpinner.d.ts +7 -0
  33. package/lib/cjs/types/components/Modal.d.ts +40 -0
  34. package/lib/cjs/types/components/TabBox.d.ts +11 -0
  35. package/lib/cjs/types/errors/ErrorWithCode.d.ts +9 -0
  36. package/lib/cjs/types/helpers/abbreviate.d.ts +10 -0
  37. package/lib/cjs/types/helpers/alert.d.ts +2 -0
  38. package/lib/cjs/types/helpers/avg.d.ts +8 -0
  39. package/lib/cjs/types/helpers/ceilToNumDecimals.d.ts +9 -0
  40. package/lib/cjs/types/helpers/confirm.d.ts +2 -0
  41. package/lib/cjs/types/helpers/floorToNumDecimals.d.ts +9 -0
  42. package/lib/cjs/types/helpers/forceNumIntoBounds.d.ts +10 -0
  43. package/lib/cjs/types/helpers/handleError.d.ts +14 -0
  44. package/lib/cjs/types/helpers/handleSuccess.d.ts +8 -0
  45. package/lib/cjs/types/helpers/padDecimalZeros.d.ts +10 -0
  46. package/lib/cjs/types/helpers/padZerosLeft.d.ts +9 -0
  47. package/lib/cjs/types/helpers/parseRequest.d.ts +21 -0
  48. package/lib/cjs/types/helpers/roundToNumDecimals.d.ts +9 -0
  49. package/lib/cjs/types/helpers/showFatalError.d.ts +2 -0
  50. package/lib/cjs/types/helpers/sum.d.ts +8 -0
  51. package/lib/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
  52. package/lib/cjs/types/helpers/waitMs.d.ts +7 -0
  53. package/lib/cjs/types/index.d.ts +22 -0
  54. package/lib/cjs/types/types/ModalButtonType.d.ts +17 -0
  55. package/lib/cjs/types/types/ModalSize.d.ts +11 -0
  56. package/lib/cjs/types/types/ModalType.d.ts +16 -0
  57. package/lib/cjs/types/types/ParamType.d.ts +17 -0
  58. package/lib/cjs/types/types/ReactKitErrorCode.d.ts +13 -0
  59. package/lib/cjs/types/types/Variant.d.ts +15 -0
  60. package/lib/esm/index.js +16 -0
  61. package/lib/esm/index.js.map +1 -0
  62. package/lib/esm/lib/components/AppWrapper.d.ts +35 -0
  63. package/lib/esm/lib/components/ErrorBox.d.ts +12 -0
  64. package/lib/esm/lib/components/LoadingSpinner.d.ts +7 -0
  65. package/lib/esm/lib/components/Modal.d.ts +40 -0
  66. package/lib/esm/lib/components/TabBox.d.ts +11 -0
  67. package/lib/esm/lib/errors/ErrorWithCode.d.ts +9 -0
  68. package/lib/esm/lib/helpers/abbreviate.d.ts +10 -0
  69. package/lib/esm/lib/helpers/avg.d.ts +8 -0
  70. package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  71. package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +9 -0
  72. package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  73. package/lib/esm/lib/helpers/handleError.d.ts +14 -0
  74. package/lib/esm/lib/helpers/handleSuccess.d.ts +8 -0
  75. package/lib/esm/lib/helpers/padDecimalZeros.d.ts +10 -0
  76. package/lib/esm/lib/helpers/padZerosLeft.d.ts +9 -0
  77. package/lib/esm/lib/helpers/parseRequest.d.ts +21 -0
  78. package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +9 -0
  79. package/lib/esm/lib/helpers/sum.d.ts +8 -0
  80. package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +23 -0
  81. package/lib/esm/lib/helpers/waitMs.d.ts +7 -0
  82. package/lib/esm/lib/index.d.ts +27 -0
  83. package/lib/esm/lib/types/ModalButtonType.d.ts +17 -0
  84. package/lib/esm/lib/types/ModalSize.d.ts +11 -0
  85. package/lib/esm/lib/types/ModalType.d.ts +16 -0
  86. package/lib/esm/lib/types/ParamType.d.ts +17 -0
  87. package/lib/esm/lib/types/ReactKitErrorCode.d.ts +13 -0
  88. package/lib/esm/lib/types/Variant.d.ts +15 -0
  89. package/lib/esm/types/components/AppWrapper.d.ts +40 -0
  90. package/lib/esm/types/components/ErrorBox.d.ts +12 -0
  91. package/lib/esm/types/components/LoadingSpinner.d.ts +7 -0
  92. package/lib/esm/types/components/Modal.d.ts +40 -0
  93. package/lib/esm/types/components/TabBox.d.ts +11 -0
  94. package/lib/esm/types/errors/ErrorWithCode.d.ts +9 -0
  95. package/lib/esm/types/helpers/abbreviate.d.ts +10 -0
  96. package/lib/esm/types/helpers/alert.d.ts +2 -0
  97. package/lib/esm/types/helpers/avg.d.ts +8 -0
  98. package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
  99. package/lib/esm/types/helpers/confirm.d.ts +2 -0
  100. package/lib/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
  101. package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
  102. package/lib/esm/types/helpers/handleError.d.ts +14 -0
  103. package/lib/esm/types/helpers/handleSuccess.d.ts +8 -0
  104. package/lib/esm/types/helpers/padDecimalZeros.d.ts +10 -0
  105. package/lib/esm/types/helpers/padZerosLeft.d.ts +9 -0
  106. package/lib/esm/types/helpers/parseRequest.d.ts +21 -0
  107. package/lib/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
  108. package/lib/esm/types/helpers/showFatalError.d.ts +2 -0
  109. package/lib/esm/types/helpers/sum.d.ts +8 -0
  110. package/lib/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
  111. package/lib/esm/types/helpers/waitMs.d.ts +7 -0
  112. package/lib/esm/types/index.d.ts +22 -0
  113. package/lib/esm/types/types/ModalButtonType.d.ts +17 -0
  114. package/lib/esm/types/types/ModalSize.d.ts +11 -0
  115. package/lib/esm/types/types/ModalType.d.ts +16 -0
  116. package/lib/esm/types/types/ParamType.d.ts +17 -0
  117. package/lib/esm/types/types/ReactKitErrorCode.d.ts +13 -0
  118. package/lib/esm/types/types/Variant.d.ts +15 -0
  119. package/lib/index.d.ts +274 -0
  120. package/package.json +26 -5
  121. package/rollup.config.js +43 -0
  122. package/src/components/AppWrapper.tsx +212 -36
  123. package/src/components/LoadingSpinner.tsx +3 -0
  124. package/src/components/Modal.tsx +65 -95
  125. package/src/components/TabBox.tsx +136 -0
  126. package/src/helpers/abbreviate.tsx +2 -0
  127. package/src/helpers/padDecimalZeros.tsx +1 -1
  128. package/src/index.ts +61 -0
  129. package/src/types/ModalButtonType.tsx +18 -0
  130. package/src/types/ModalSize.tsx +12 -0
  131. package/src/types/ModalType.tsx +17 -0
  132. package/tsconfig.json +14 -17
  133. package/lib/components/AppWrapper.d.ts +0 -20
  134. package/lib/components/AppWrapper.js +0 -133
  135. package/lib/components/AppWrapper.js.map +0 -1
  136. package/lib/components/ErrorBox.js +0 -65
  137. package/lib/components/ErrorBox.js.map +0 -1
  138. package/lib/components/LoadingSpinner.js +0 -41
  139. package/lib/components/LoadingSpinner.js.map +0 -1
  140. package/lib/components/Modal.d.ts +0 -69
  141. package/lib/components/Modal.js +0 -315
  142. package/lib/components/Modal.js.map +0 -1
  143. package/lib/errors/ErrorWithCode.js +0 -33
  144. package/lib/errors/ErrorWithCode.js.map +0 -1
  145. package/lib/helpers/abbreviate.js +0 -21
  146. package/lib/helpers/abbreviate.js.map +0 -1
  147. package/lib/helpers/avg.js +0 -24
  148. package/lib/helpers/avg.js.map +0 -1
  149. package/lib/helpers/ceilToNumDecimals.js +0 -15
  150. package/lib/helpers/ceilToNumDecimals.js.map +0 -1
  151. package/lib/helpers/floorToNumDecimals.js +0 -15
  152. package/lib/helpers/floorToNumDecimals.js.map +0 -1
  153. package/lib/helpers/forceNumIntoBounds.js +0 -15
  154. package/lib/helpers/forceNumIntoBounds.js.map +0 -1
  155. package/lib/helpers/handleError.js +0 -54
  156. package/lib/helpers/handleError.js.map +0 -1
  157. package/lib/helpers/handleSuccess.js +0 -20
  158. package/lib/helpers/handleSuccess.js.map +0 -1
  159. package/lib/helpers/padDecimalZeros.js +0 -30
  160. package/lib/helpers/padDecimalZeros.js.map +0 -1
  161. package/lib/helpers/padZerosLeft.js +0 -21
  162. package/lib/helpers/padZerosLeft.js.map +0 -1
  163. package/lib/helpers/parseRequest.js +0 -240
  164. package/lib/helpers/parseRequest.js.map +0 -1
  165. package/lib/helpers/roundToNumDecimals.js +0 -15
  166. package/lib/helpers/roundToNumDecimals.js.map +0 -1
  167. package/lib/helpers/showFatalError.d.ts +0 -2
  168. package/lib/helpers/showFatalError.js +0 -5
  169. package/lib/helpers/showFatalError.js.map +0 -1
  170. package/lib/helpers/sum.js +0 -15
  171. package/lib/helpers/sum.js.map +0 -1
  172. package/lib/helpers/visitServerEndpoint.js +0 -135
  173. package/lib/helpers/visitServerEndpoint.js.map +0 -1
  174. package/lib/helpers/waitMs.js +0 -55
  175. package/lib/helpers/waitMs.js.map +0 -1
  176. package/lib/types/ParamType.js +0 -21
  177. package/lib/types/ParamType.js.map +0 -1
  178. package/lib/types/ReactKitErrorCode.js +0 -18
  179. package/lib/types/ReactKitErrorCode.js.map +0 -1
  180. package/lib/types/Variant.js +0 -19
  181. package/lib/types/Variant.js.map +0 -1
  182. package/src/helpers/handleError.ts +0 -65
  183. package/src/helpers/handleSuccess.ts +0 -18
  184. package/src/helpers/parseRequest.ts +0 -299
  185. package/src/helpers/showFatalError.tsx +0 -3
  186. package/src/helpers/visitServerEndpoint.tsx +0 -110
  187. package/src/types/ParamType.ts +0 -18
@@ -3,6 +3,9 @@
3
3
  * @author Gabe Abrams
4
4
  */
5
5
 
6
+ // Import react
7
+ import React from 'react';
8
+
6
9
  // Import FontAwesome Icons
7
10
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
11
  import { faCircle } from '@fortawesome/free-solid-svg-icons';
@@ -12,6 +12,9 @@ import waitMs from '../helpers/waitMs';
12
12
 
13
13
  // Import types
14
14
  import Variant from '../types/Variant';
15
+ import ModalButtonType from '../types/ModalButtonType';
16
+ import ModalSize from '../types/ModalSize';
17
+ import ModalType from '../types/ModalType';
15
18
 
16
19
  /*------------------------------------------------------------------------*/
17
20
  /* Style */
@@ -77,118 +80,83 @@ const MS_TO_ANIMATE = 400; // Time to animate in/out (defined by bootstrap)
77
80
  const MS_ANIMATE_IN_DELAY = 10;
78
81
  // Time to wait before animating in (must be >0 or animation won't trigger)
79
82
 
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
83
  // Modal type to list of buttons
116
- const modalTypeToButtonTypes: {
117
- [k: string]: ButtonType[]
84
+ const modalTypeToModalButtonTypes: {
85
+ [k: string]: ModalButtonType[]
118
86
  } = {
119
87
  [ModalType.Okay]: [
120
- ButtonType.Okay,
88
+ ModalButtonType.Okay,
121
89
  ],
122
90
  [ModalType.OkayCancel]: [
123
- ButtonType.Okay,
124
- ButtonType.Cancel,
91
+ ModalButtonType.Okay,
92
+ ModalButtonType.Cancel,
125
93
  ],
126
94
  [ModalType.YesNo]: [
127
- ButtonType.Yes,
128
- ButtonType.No,
95
+ ModalButtonType.Yes,
96
+ ModalButtonType.No,
129
97
  ],
130
98
  [ModalType.YesNoCancel]: [
131
- ButtonType.Yes,
132
- ButtonType.No,
133
- ButtonType.Cancel,
99
+ ModalButtonType.Yes,
100
+ ModalButtonType.No,
101
+ ModalButtonType.Cancel,
134
102
  ],
135
103
  [ModalType.AbandonGoBack]: [
136
- ButtonType.Abandon,
137
- ButtonType.GoBack,
104
+ ModalButtonType.Abandon,
105
+ ModalButtonType.GoBack,
138
106
  ],
139
107
  [ModalType.ImSureCancel]: [
140
- ButtonType.ImSure,
141
- ButtonType.Cancel,
108
+ ModalButtonType.ImSure,
109
+ ModalButtonType.Cancel,
142
110
  ],
143
111
  [ModalType.DeleteCancel]: [
144
- ButtonType.Delete,
145
- ButtonType.Cancel,
112
+ ModalButtonType.Delete,
113
+ ModalButtonType.Cancel,
146
114
  ],
147
115
  [ModalType.ConfirmCancel]: [
148
- ButtonType.Confirm,
149
- ButtonType.Cancel,
116
+ ModalButtonType.Confirm,
117
+ ModalButtonType.Cancel,
150
118
  ],
151
119
  };
152
120
 
153
121
  // Button type styling and labels
154
- const buttonTypeToLabelAndVariant = {
155
- [ButtonType.Okay]: {
122
+ const ModalButtonTypeToLabelAndVariant = {
123
+ [ModalButtonType.Okay]: {
156
124
  label: 'Okay',
157
125
  variant: Variant.Dark,
158
126
  },
159
- [ButtonType.Cancel]: {
127
+ [ModalButtonType.Cancel]: {
160
128
  label: 'Cancel',
161
129
  variant: Variant.Secondary,
162
130
  },
163
- [ButtonType.Yes]: {
131
+ [ModalButtonType.Yes]: {
164
132
  label: 'Yes',
165
133
  variant: Variant.Dark,
166
134
  },
167
- [ButtonType.No]: {
135
+ [ModalButtonType.No]: {
168
136
  label: 'No',
169
137
  variant: Variant.Secondary,
170
138
  },
171
- [ButtonType.Abandon]: {
139
+ [ModalButtonType.Abandon]: {
172
140
  label: 'Abandon Changes',
173
141
  variant: Variant.Warning,
174
142
  },
175
- [ButtonType.GoBack]: {
143
+ [ModalButtonType.GoBack]: {
176
144
  label: 'Go Back',
177
145
  variant: Variant.Secondary,
178
146
  },
179
- [ButtonType.Continue]: {
147
+ [ModalButtonType.Continue]: {
180
148
  label: 'Continue',
181
149
  variant: Variant.Dark,
182
150
  },
183
- [ButtonType.ImSure]: {
151
+ [ModalButtonType.ImSure]: {
184
152
  label: 'I am sure',
185
153
  variant: Variant.Warning,
186
154
  },
187
- [ButtonType.Delete]: {
155
+ [ModalButtonType.Delete]: {
188
156
  label: 'Yes, Delete',
189
157
  variant: Variant.Danger,
190
158
  },
191
- [ButtonType.Confirm]: {
159
+ [ModalButtonType.Confirm]: {
192
160
  label: 'Confirm',
193
161
  variant: Variant.Dark,
194
162
  },
@@ -208,7 +176,9 @@ type Props = {
208
176
  // The body of the modal
209
177
  children?: React.ReactNode,
210
178
  // Handler to call when modal is closed (if excluded, not closable)
211
- onClose?: (type: ButtonType) => void,
179
+ onClose?: (type: ModalButtonType) => void,
180
+ // If true, don't allow the user to click the backdrop to exit
181
+ dontAllowBackdropExit?: boolean,
212
182
  // Custom label for "okay" button
213
183
  okayLabel?: string,
214
184
  // Custom variant for "okay" button
@@ -249,21 +219,15 @@ type Props = {
249
219
  confirmLabel?: string,
250
220
  // Custom variant for "confirm" button
251
221
  confirmVariant?: Variant,
222
+ // True if modal should be on top of other modals
223
+ onTopOfOtherModals?: boolean,
252
224
  };
253
225
 
254
226
  /*------------------------------------------------------------------------*/
255
227
  /* Component */
256
228
  /*------------------------------------------------------------------------*/
257
229
 
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) => {
230
+ const Modal: React.FC<Props> = (props) => {
267
231
  /*------------------------------------------------------------------------*/
268
232
  /* Setup */
269
233
  /*------------------------------------------------------------------------*/
@@ -276,6 +240,8 @@ const Modal: (
276
240
  title,
277
241
  children,
278
242
  onClose,
243
+ dontAllowBackdropExit,
244
+ onTopOfOtherModals,
279
245
  } = props;
280
246
 
281
247
  /* -------------- State ------------- */
@@ -316,10 +282,10 @@ const Modal: (
316
282
  /**
317
283
  * Handles the closing of the modal
318
284
  * @author Gabe Abrams
319
- * @param buttonType the button that was clicked when closing the
285
+ * @param ModalButtonType the button that was clicked when closing the
320
286
  * modal
321
287
  */
322
- const handleClose = async (buttonType: ButtonType) => {
288
+ const handleClose = async (ModalButtonType: ModalButtonType) => {
323
289
  // Don't close if no handler
324
290
  if (!onClose) {
325
291
  return;
@@ -340,7 +306,7 @@ const Modal: (
340
306
 
341
307
  // Call the handler after the modal has animated out
342
308
  await waitMs(MS_TO_ANIMATE);
343
- onClose(buttonType);
309
+ onClose(ModalButtonType);
344
310
  };
345
311
 
346
312
  /*------------------------------------------------------------------------*/
@@ -352,34 +318,36 @@ const Modal: (
352
318
  /*----------------------------------------*/
353
319
 
354
320
  // Get list of buttons for this modal type
355
- const buttonTypes: ButtonType[] = modalTypeToButtonTypes[type] ?? [];
321
+ const ModalButtonTypes: ModalButtonType[] = modalTypeToModalButtonTypes[type] ?? [];
356
322
 
357
323
  // Create buttons
358
- const buttons = buttonTypes.map((buttonType: ButtonType, i) => {
324
+ const buttons = ModalButtonTypes.map((ModalButtonType: ModalButtonType, i) => {
359
325
  // Get default style
360
326
  let {
361
327
  label,
362
328
  variant,
363
- } = buttonTypeToLabelAndVariant[buttonType];
329
+ } = ModalButtonTypeToLabelAndVariant[ModalButtonType];
364
330
 
365
331
  // Override with customizations
366
- if (props[`${buttonType}Label`]) {
367
- label = props[`${buttonType}Label`];
332
+ const newLabel = props[`${ModalButtonType}Label`];
333
+ if (newLabel) {
334
+ label = newLabel;
368
335
  }
369
- if (props[`${buttonType}Variant`]) {
370
- variant = props[`${buttonType}Variant`];
336
+ const newVariant = props[`${ModalButtonType}Variant`];
337
+ if (newVariant) {
338
+ variant = newVariant;
371
339
  }
372
340
 
373
341
  // Check if this button is last
374
- const last = (i === buttonTypes.length - 1);
342
+ const last = (i === ModalButtonTypes.length - 1);
375
343
 
376
344
  // Create the button
377
345
  return (
378
346
  <button
379
347
  type="button"
380
- className={`Modal-${buttonType}-button btn btn-${variant} ${last ? '' : 'mr-1'}`}
348
+ className={`Modal-${ModalButtonType}-button btn btn-${variant} ${last ? '' : 'mr-1'}`}
381
349
  onClick={() => {
382
- handleClose(buttonType);
350
+ handleClose(ModalButtonType);
383
351
  }}
384
352
  >
385
353
  {label}
@@ -404,9 +372,17 @@ const Modal: (
404
372
  show={visible}
405
373
  size={size !== ModalSize.Medium ? size : undefined}
406
374
  onHide={() => {
407
- handleClose(ButtonType.Cancel);
375
+ if (!dontAllowBackdropExit) {
376
+ handleClose(ModalButtonType.Cancel);
377
+ }
378
+ }}
379
+ style={{
380
+ zIndex: (
381
+ onTopOfOtherModals
382
+ ? 6000000000
383
+ : 5000000000
384
+ ),
408
385
  }}
409
- style={{ zIndex: 5000000000 }}
410
386
  backdropClassName="Modal-backdrop"
411
387
  centered
412
388
  >
@@ -438,10 +414,4 @@ const Modal: (
438
414
  /* Wrap Up */
439
415
  /*------------------------------------------------------------------------*/
440
416
 
441
- // Add enums
442
- Modal.ModalType = ModalType;
443
- Modal.ModalSize = ModalSize;
444
- Modal.ButtonType = ButtonType;
445
- Modal.Variant = Variant;
446
-
447
417
  export default Modal;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * A box with a tab on the top that holds buttons and other content
3
+ * @author Gabe Abrams
4
+ */
5
+
6
+ // Import React
7
+ import React from 'react';
8
+
9
+ /*------------------------------------------------------------------------*/
10
+ /* Types */
11
+ /*------------------------------------------------------------------------*/
12
+
13
+ type Props = {
14
+ // Title of the box
15
+ title: React.ReactNode,
16
+ // Children/contents inside the box
17
+ children: React.ReactNode,
18
+ };
19
+
20
+ /*------------------------------------------------------------------------*/
21
+ /* Style */
22
+ /*------------------------------------------------------------------------*/
23
+
24
+ const style = `
25
+ /* Tab Box */
26
+ .TabBox-box {
27
+ /* Light Border */
28
+ border: 2px solid #dedede;
29
+
30
+ /* Rounded Corners (except top-left) */
31
+ border-bottom-right-radius: 5px;
32
+ border-bottom-left-radius: 5px;
33
+ border-top-right-radius: 5px;
34
+
35
+ /* Very Light Gray Border */
36
+ background: #fdfdfd;
37
+
38
+ /* Align Contents on Left */
39
+ text-align: left;
40
+ }
41
+
42
+ /* Container for Title */
43
+ .TabBox-title-container {
44
+ /* Place on Left */
45
+ position: relative;
46
+ left: 0;
47
+ text-align: left;
48
+ }
49
+
50
+ /* Tab-style Title */
51
+ .TabBox-title {
52
+ /* Place so it Barely Overlaps the Box Border */
53
+ display: inline-block;
54
+ position: relative;
55
+ top: 2px; /* Gives Illusion that Border Doesn't Exist Below Tab */
56
+
57
+ /* Title-sized Font */
58
+ font-size: 25px;
59
+
60
+ /* Add Border on Top and Sides */
61
+ border-top: 2px solid #dedede;
62
+ border-left: 2px solid #dedede;
63
+ border-right: 2px solid #dedede;
64
+
65
+ /* Round the Top Corners */
66
+ border-top-left-radius: 5px;
67
+ border-top-right-radius: 5px;
68
+
69
+ /* Add Text Padding */
70
+ padding-left: 12px;
71
+ padding-right: 12px;
72
+
73
+ /* Match Background Color of Box */
74
+ background: #fdfdfd;
75
+ }
76
+
77
+ /* Make the TabBox's Children Appear Above Title if Overlap Occurs */
78
+ .TabBox-children {
79
+ position: relative;
80
+ z-index: 1;
81
+ }
82
+ `;
83
+
84
+ /*------------------------------------------------------------------------*/
85
+ /* Component */
86
+ /*------------------------------------------------------------------------*/
87
+
88
+ const TabBox: React.FC<Props> = (props) => {
89
+ /*------------------------------------------------------------------------*/
90
+ /* Setup */
91
+ /*------------------------------------------------------------------------*/
92
+
93
+ /* -------------- Props ------------- */
94
+
95
+ const {
96
+ title,
97
+ children,
98
+ } = props;
99
+
100
+ /*------------------------------------------------------------------------*/
101
+ /* Render */
102
+ /*------------------------------------------------------------------------*/
103
+
104
+ /*----------------------------------------*/
105
+ /* Main UI */
106
+ /*----------------------------------------*/
107
+
108
+ // Full UI
109
+ return (
110
+ <div>
111
+ {/* Style */}
112
+ <style>{style}</style>
113
+
114
+ {/* Title */}
115
+ <div className="TabBox-title-container">
116
+ <div className="TabBox-title">
117
+ {title}
118
+ </div>
119
+ </div>
120
+
121
+ {/* Contents */}
122
+ <div className="TabBox-box p-2">
123
+ <div className="TabBox-children">
124
+ {children}
125
+ </div>
126
+ </div>
127
+ </div>
128
+ );
129
+ };
130
+
131
+ /*------------------------------------------------------------------------*/
132
+ /* Wrap Up */
133
+ /*------------------------------------------------------------------------*/
134
+
135
+ // Export component
136
+ export default TabBox;
@@ -21,3 +21,5 @@ const abbreviate = (text: string, maxChars: number): string => {
21
21
  );
22
22
  return `${shortenedText}...`;
23
23
  };
24
+
25
+ export default abbreviate;
@@ -9,7 +9,7 @@
9
9
  const padDecimalZeros = (num: number, numDigits: number): string => {
10
10
  // Skip if nothing to do
11
11
  if (numDigits < 1) {
12
- return;
12
+ return String(num);
13
13
  }
14
14
 
15
15
  // Convert to string
package/src/index.ts ADDED
@@ -0,0 +1,61 @@
1
+ // Import components
2
+ import AppWrapper, { alert, confirm, showFatalError } from './components/AppWrapper';
3
+ import LoadingSpinner from './components/LoadingSpinner';
4
+ import ErrorBox from './components/ErrorBox';
5
+ import Modal from './components/Modal';
6
+ import TabBox from './components/TabBox';
7
+
8
+ // Import errors
9
+ import ErrorWithCode from './errors/ErrorWithCode';
10
+
11
+ // Import helpers
12
+ import abbreviate from './helpers/abbreviate';
13
+ import avg from './helpers/avg';
14
+ import ceilToNumDecimals from './helpers/ceilToNumDecimals';
15
+ import floorToNumDecimals from './helpers/floorToNumDecimals';
16
+ import forceNumIntoBounds from './helpers/forceNumIntoBounds';
17
+ import padDecimalZeros from './helpers/padDecimalZeros';
18
+ import padZerosLeft from './helpers/padZerosLeft';
19
+ import roundToNumDecimals from './helpers/roundToNumDecimals';
20
+ import sum from './helpers/sum';
21
+ import waitMs from './helpers/waitMs';
22
+
23
+ // Import types
24
+ import ModalButtonType from './types/ModalButtonType';
25
+ import ModalSize from './types/ModalSize';
26
+ import ModalType from './types/ModalType';
27
+ import ReactKitErrorCode from './types/ReactKitErrorCode';
28
+ import Variant from './types/Variant';
29
+
30
+ // Export each item
31
+ export {
32
+ // Components
33
+ AppWrapper,
34
+ LoadingSpinner,
35
+ ErrorBox,
36
+ Modal,
37
+ TabBox,
38
+ // Global functions
39
+ alert,
40
+ confirm,
41
+ showFatalError,
42
+ // Errors
43
+ ErrorWithCode,
44
+ // Helpers
45
+ abbreviate,
46
+ avg,
47
+ ceilToNumDecimals,
48
+ floorToNumDecimals,
49
+ forceNumIntoBounds,
50
+ padDecimalZeros,
51
+ padZerosLeft,
52
+ roundToNumDecimals,
53
+ sum,
54
+ waitMs,
55
+ // Types
56
+ ModalButtonType,
57
+ ModalSize,
58
+ ModalType,
59
+ ReactKitErrorCode,
60
+ Variant,
61
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Types of buttons in the modal
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalButtonType {
6
+ Okay = 'okay',
7
+ Cancel = 'cancel',
8
+ Yes = 'yes',
9
+ No = 'no',
10
+ Abandon = 'abandon',
11
+ GoBack = 'goBack',
12
+ Continue = 'continue',
13
+ ImSure = 'imSure',
14
+ Delete = 'delete',
15
+ Confirm = 'confirm',
16
+ }
17
+
18
+ export default ModalButtonType;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Modal sizes
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalSize {
6
+ Small = 'sm',
7
+ Medium = 'md',
8
+ Large = 'lg',
9
+ ExtraLarge = 'xl',
10
+ }
11
+
12
+ export default ModalSize;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Types of modals
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalType {
6
+ Okay = 'okay', // [Okay]
7
+ OkayCancel = 'okay-cancel', // [Okay] [Cancel]
8
+ YesNo = 'yes-no', // [Yes] [No]
9
+ YesNoCancel = 'yes-no-cancel', // [Yes] [No] [Cancel]
10
+ AbandonGoBack = 'abandon-goBack', // [Abandon Changes] [Go Back]
11
+ ImSureCancel = 'imSure-cancel', // [I am sure] [Cancel]
12
+ DeleteCancel = 'delete-cancel', // [Yes, Delete] [Cancel]
13
+ ConfirmCancel = 'confirm-cancel', // [Confirm] [Cancel]
14
+ NoButtons = '-', // No buttons
15
+ }
16
+
17
+ export default ModalType;
package/tsconfig.json CHANGED
@@ -1,24 +1,21 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "commonjs",
4
3
  "esModuleInterop": true,
5
- "noImplicitAny": true,
6
- "noEmitOnError": true,
7
- "removeComments": false,
4
+ "strict": true,
5
+ "skipLibCheck": true,
6
+ "jsx": "react",
7
+ "module": "ESNext",
8
8
  "declaration": true,
9
+ "declarationDir": "types",
9
10
  "sourceMap": true,
10
- "target": "es5",
11
- "jsx": "react-jsx",
12
- "lib": [
13
- "es2017",
14
- "dom"
15
- ],
16
- "outDir": "./lib"
11
+ "outDir": "./lib",
12
+ "moduleResolution": "node",
13
+ "emitDeclarationOnly": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "forceConsistentCasingInFileNames": true,
17
16
  },
18
- "include": [
19
- "./src"
20
- ],
21
- "ts-node": {
22
- "files": true
23
- }
17
+ "exclude": [
18
+ "lib",
19
+ "node_modules"
20
+ ]
24
21
  }
@@ -1,20 +0,0 @@
1
- /**
2
- * A wrapper for the entire React app that adds global functionality like
3
- * handling for fatal error messages
4
- * @author Gabe Abrams
5
- */
6
- import React from 'react';
7
- declare type Props = {
8
- children: React.ReactNode;
9
- dark?: boolean;
10
- sessionExpiredMessage?: string;
11
- };
12
- /**
13
- * Show a fatal error message
14
- * @author Gabe Abrams
15
- * @param error the error to show
16
- * @param [errorTitle] title of the error box
17
- */
18
- export declare const showFatalError: (error: any, errorTitle?: string) => void;
19
- declare const AppWrapper: (props: Props) => React.ReactElement;
20
- export default AppWrapper;