dce-reactkit 1.0.20 → 2.0.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.
Files changed (215) hide show
  1. package/.eslintrc.js +95 -0
  2. package/lib/components/LoadingSpinner.d.ts +6 -0
  3. package/lib/components/LoadingSpinner.js +41 -0
  4. package/lib/components/LoadingSpinner.js.map +1 -0
  5. package/lib/components/Modal.d.ts +69 -0
  6. package/lib/components/Modal.js +315 -0
  7. package/lib/components/Modal.js.map +1 -0
  8. package/lib/errors/ErrorWithCode.d.ts +9 -0
  9. package/lib/errors/ErrorWithCode.js +33 -0
  10. package/lib/errors/ErrorWithCode.js.map +1 -0
  11. package/lib/helpers/abbreviate.d.ts +9 -0
  12. package/lib/helpers/abbreviate.js +21 -0
  13. package/lib/helpers/abbreviate.js.map +1 -0
  14. package/lib/helpers/avg.d.ts +8 -0
  15. package/lib/helpers/avg.js +24 -0
  16. package/lib/helpers/avg.js.map +1 -0
  17. package/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  18. package/lib/helpers/ceilToNumDecimals.js +15 -0
  19. package/lib/helpers/ceilToNumDecimals.js.map +1 -0
  20. package/lib/helpers/floorToNumDecimals.d.ts +9 -0
  21. package/lib/helpers/floorToNumDecimals.js +15 -0
  22. package/lib/helpers/floorToNumDecimals.js.map +1 -0
  23. package/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  24. package/lib/helpers/forceNumIntoBounds.js +15 -0
  25. package/lib/helpers/forceNumIntoBounds.js.map +1 -0
  26. package/lib/helpers/padDecimalZeros.d.ts +10 -0
  27. package/lib/helpers/padDecimalZeros.js +30 -0
  28. package/lib/helpers/padDecimalZeros.js.map +1 -0
  29. package/lib/helpers/padZerosLeft.d.ts +9 -0
  30. package/lib/helpers/padZerosLeft.js +21 -0
  31. package/lib/helpers/padZerosLeft.js.map +1 -0
  32. package/lib/helpers/roundToNumDecimals.d.ts +9 -0
  33. package/lib/helpers/roundToNumDecimals.js +15 -0
  34. package/lib/helpers/roundToNumDecimals.js.map +1 -0
  35. package/lib/helpers/sum.d.ts +8 -0
  36. package/lib/helpers/sum.js +15 -0
  37. package/lib/helpers/sum.js.map +1 -0
  38. package/lib/helpers/visitServerEndpoint.d.ts +17 -0
  39. package/lib/helpers/visitServerEndpoint.js +84 -0
  40. package/lib/helpers/visitServerEndpoint.js.map +1 -0
  41. package/lib/helpers/waitMs.d.ts +7 -0
  42. package/lib/helpers/waitMs.js +55 -0
  43. package/lib/helpers/waitMs.js.map +1 -0
  44. package/lib/types/ReactKitErrorCode.d.ts +9 -0
  45. package/lib/types/ReactKitErrorCode.js +14 -0
  46. package/lib/types/ReactKitErrorCode.js.map +1 -0
  47. package/lib/types/Variant.d.ts +15 -0
  48. package/lib/types/Variant.js +19 -0
  49. package/lib/types/Variant.js.map +1 -0
  50. package/package.json +22 -40
  51. package/src/components/LoadingSpinner.tsx +105 -0
  52. package/src/components/Modal.tsx +447 -0
  53. package/src/errors/ErrorWithCode.tsx +15 -0
  54. package/src/helpers/abbreviate.tsx +23 -0
  55. package/src/helpers/avg.tsx +22 -0
  56. package/src/helpers/ceilToNumDecimals.tsx +13 -0
  57. package/src/helpers/floorToNumDecimals.tsx +13 -0
  58. package/src/helpers/forceNumIntoBounds.tsx +19 -0
  59. package/src/helpers/padDecimalZeros.tsx +32 -0
  60. package/src/helpers/padZerosLeft.tsx +21 -0
  61. package/src/helpers/roundToNumDecimals.tsx +13 -0
  62. package/src/helpers/sum.tsx +16 -0
  63. package/src/helpers/visitServerEndpoint.tsx +59 -0
  64. package/src/helpers/waitMs.tsx +12 -0
  65. package/src/types/ReactKitErrorCode.tsx +12 -0
  66. package/src/types/Variant.tsx +16 -0
  67. package/tsconfig.json +24 -0
  68. package/index.js +0 -1
  69. package/lib/Bar.js +0 -169
  70. package/lib/Donut.js +0 -145
  71. package/lib/DownloadButton.js +0 -81
  72. package/lib/Histogram.js +0 -193
  73. package/lib/Scatter.js +0 -162
  74. package/lib/StackedBar.js +0 -243
  75. package/lib/common/chart/Holder/index.js +0 -182
  76. package/lib/common/chart/Holder/style.css +0 -41
  77. package/lib/common/chart/colors.js +0 -12
  78. package/lib/common/csvToString.js +0 -23
  79. package/lib/common/isFloat.js +0 -14
  80. package/lib/common/isInteger.js +0 -24
  81. package/lib/common/math.js +0 -21
  82. package/lib/common/validators.js +0 -18
  83. package/lib/glyph/Adjust.js +0 -13
  84. package/lib/glyph/Angle.js +0 -44
  85. package/lib/glyph/Archive.js +0 -13
  86. package/lib/glyph/Arrow.js +0 -49
  87. package/lib/glyph/ArrowsHorizontal.js +0 -13
  88. package/lib/glyph/ArrowsVertical.js +0 -13
  89. package/lib/glyph/Award.js +0 -13
  90. package/lib/glyph/Ban.js +0 -13
  91. package/lib/glyph/Barcode.js +0 -13
  92. package/lib/glyph/Bed.js +0 -13
  93. package/lib/glyph/Bell.js +0 -35
  94. package/lib/glyph/Bolt.js +0 -13
  95. package/lib/glyph/Bookmark.js +0 -37
  96. package/lib/glyph/Bug.js +0 -13
  97. package/lib/glyph/Calendar.js +0 -13
  98. package/lib/glyph/Check.js +0 -36
  99. package/lib/glyph/Checkbox.js +0 -40
  100. package/lib/glyph/Chevron.js +0 -63
  101. package/lib/glyph/Circle.js +0 -15
  102. package/lib/glyph/Cog.js +0 -13
  103. package/lib/glyph/DoubleAngle.js +0 -45
  104. package/lib/glyph/Download.js +0 -13
  105. package/lib/glyph/Ellipsis.js +0 -36
  106. package/lib/glyph/Envelope.js +0 -13
  107. package/lib/glyph/File.js +0 -37
  108. package/lib/glyph/IdCard.js +0 -13
  109. package/lib/glyph/Menu.js +0 -13
  110. package/lib/glyph/Minus.js +0 -13
  111. package/lib/glyph/Move.js +0 -13
  112. package/lib/glyph/Plus.js +0 -13
  113. package/lib/glyph/Square.js +0 -47
  114. package/lib/glyph/Teacher.js +0 -13
  115. package/lib/glyph/TextAlign.js +0 -53
  116. package/lib/glyph/Times.js +0 -36
  117. package/lib/glyph/WarningTriangle.js +0 -13
  118. package/lib/index.js +0 -1
  119. package/src-old/common/csvToString.js +0 -5
  120. package/src-old/common/isFloat.js +0 -3
  121. package/src-old/common/isInteger.js +0 -14
  122. package/src-old/common/math.js +0 -16
  123. package/src-old/common/validators.js +0 -14
  124. package/src-old/components/Alert.js +0 -79
  125. package/src-old/components/Button.js +0 -64
  126. package/src-old/components/CSV/autoMatch.js +0 -174
  127. package/src-old/components/CSV/getNumCols.js +0 -15
  128. package/src-old/components/CSV/index.js +0 -743
  129. package/src-old/components/Card.js +0 -64
  130. package/src-old/components/Chart/Bar.js +0 -169
  131. package/src-old/components/Chart/Donut.js +0 -160
  132. package/src-old/components/Chart/Histogram.js +0 -189
  133. package/src-old/components/Chart/Scatter.js +0 -162
  134. package/src-old/components/Chart/colors.js +0 -20
  135. package/src-old/components/Checkbox/index.js +0 -106
  136. package/src-old/components/Checkbox/style.css +0 -11
  137. package/src-old/components/DatePicker.js +0 -59
  138. package/src-old/components/DownloadButton.js +0 -72
  139. package/src-old/components/Dropdown.js +0 -120
  140. package/src-old/components/Layout/LeftAddon.js +0 -63
  141. package/src-old/components/Layout/RightAddon.js +0 -64
  142. package/src-old/components/Layout/TwoCol.js +0 -67
  143. package/src-old/components/Modal.js +0 -161
  144. package/src-old/components/PhotoRoster.js +0 -152
  145. package/src-old/components/Pills.js +0 -117
  146. package/src-old/components/Radio.js +0 -94
  147. package/src-old/components/Splash/Error.js +0 -62
  148. package/src-old/components/Splash/Load/index.js +0 -32
  149. package/src-old/components/Splash/Load/style.css +0 -51
  150. package/src-old/components/Stat/General.js +0 -252
  151. package/src-old/components/Stat/helpers/calcAverage.js +0 -20
  152. package/src-old/components/Stat/helpers/calcExtremes.js +0 -27
  153. package/src-old/components/Stat/helpers/calcMedian.js +0 -32
  154. package/src-old/components/Stat/helpers/calcStdDev.js +0 -30
  155. package/src-old/components/Stat/helpers/calcSum.js +0 -8
  156. package/src-old/components/UserProfile/index.js +0 -151
  157. package/src-old/components/UserProfile/style.css +0 -33
  158. package/src-old/components/Well.js +0 -28
  159. package/src-old/components/Wizard/Question/CSV.js +0 -307
  160. package/src-old/components/Wizard/Question/Chooser/Assignment.js +0 -108
  161. package/src-old/components/Wizard/Question/Chooser/Course.js +0 -214
  162. package/src-old/components/Wizard/Question/Chooser/helpers/divideIntoSections.js +0 -16
  163. package/src-old/components/Wizard/Question/Chooser/helpers/genGetItemsPromise.js +0 -20
  164. package/src-old/components/Wizard/Question/Chooser/helpers/preprocessSections.js +0 -36
  165. package/src-old/components/Wizard/Question/Chooser/index.js +0 -306
  166. package/src-old/components/Wizard/Question/Form/Field/CheckableItem.js +0 -155
  167. package/src-old/components/Wizard/Question/Form/Field/Input.js +0 -149
  168. package/src-old/components/Wizard/Question/Form/Field/NumberItem.js +0 -374
  169. package/src-old/components/Wizard/Question/Form/Field/index.js +0 -34
  170. package/src-old/components/Wizard/Question/Form/Field/readme.md +0 -7
  171. package/src-old/components/Wizard/Question/Form/index.js +0 -175
  172. package/src-old/components/Wizard/Question/Form/style.css +0 -3
  173. package/src-old/components/Wizard/Question/OneButton.js +0 -80
  174. package/src-old/components/Wizard/Question/index.js +0 -46
  175. package/src-old/components/Wizard/Question/readme.md +0 -10
  176. package/src-old/components/Wizard/QuestionGroup/AnswerAll.js +0 -126
  177. package/src-old/components/Wizard/QuestionGroup/AnswerAny.js +0 -60
  178. package/src-old/components/Wizard/index.js +0 -233
  179. package/src-old/components/Wizard/style.css +0 -21
  180. package/src-old/glyphs/Adjust.js +0 -13
  181. package/src-old/glyphs/Angle.js +0 -57
  182. package/src-old/glyphs/Archive.js +0 -13
  183. package/src-old/glyphs/Arrow.js +0 -85
  184. package/src-old/glyphs/ArrowsHorizontal.js +0 -13
  185. package/src-old/glyphs/ArrowsVertical.js +0 -13
  186. package/src-old/glyphs/Award.js +0 -13
  187. package/src-old/glyphs/Ban.js +0 -13
  188. package/src-old/glyphs/Barcode.js +0 -13
  189. package/src-old/glyphs/Bed.js +0 -13
  190. package/src-old/glyphs/Bell.js +0 -34
  191. package/src-old/glyphs/Bolt.js +0 -13
  192. package/src-old/glyphs/Bookmark.js +0 -36
  193. package/src-old/glyphs/Bug.js +0 -13
  194. package/src-old/glyphs/Calendar.js +0 -13
  195. package/src-old/glyphs/Check.js +0 -34
  196. package/src-old/glyphs/Checkbox.js +0 -42
  197. package/src-old/glyphs/Chevron.js +0 -88
  198. package/src-old/glyphs/Circle.js +0 -16
  199. package/src-old/glyphs/Cog.js +0 -13
  200. package/src-old/glyphs/DoubleAngle.js +0 -58
  201. package/src-old/glyphs/Download.js +0 -13
  202. package/src-old/glyphs/Ellipsis.js +0 -35
  203. package/src-old/glyphs/Envelope.js +0 -13
  204. package/src-old/glyphs/File.js +0 -40
  205. package/src-old/glyphs/IdCard.js +0 -13
  206. package/src-old/glyphs/Menu.js +0 -13
  207. package/src-old/glyphs/Minus.js +0 -13
  208. package/src-old/glyphs/Move.js +0 -13
  209. package/src-old/glyphs/Plus.js +0 -13
  210. package/src-old/glyphs/Square.js +0 -48
  211. package/src-old/glyphs/Teacher.js +0 -13
  212. package/src-old/glyphs/TextAlign.js +0 -58
  213. package/src-old/glyphs/Times.js +0 -34
  214. package/src-old/glyphs/WarningTriangle.js +0 -13
  215. package/src-old/index.js +0 -1
@@ -0,0 +1,105 @@
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;
@@ -0,0 +1,447 @@
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;
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,22 @@
1
+ import sum from './sum';
2
+
3
+ /**
4
+ * Get the average of a set of numbers
5
+ * @author Gabe Abrams
6
+ * @param nums the numbers to average
7
+ * @returns average value or 0 if no numbers
8
+ */
9
+ const avg = (nums: number[]) => {
10
+ // Handle empty array case
11
+ if (nums.length === 0) {
12
+ return 0;
13
+ }
14
+
15
+ // Get the total value
16
+ const total = sum(nums);
17
+
18
+ // Get average
19
+ return (total / nums.length);
20
+ };
21
+
22
+ export default avg;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Round a number (ceiling) to a certain number of decimals
3
+ * @author Gabe Abrams
4
+ * @param num the number to round
5
+ * @param numDecimals the number of decimals to round to
6
+ * @returns rounded number
7
+ */
8
+ const ceilToNumDecimals = (num: number, numDecimals: number): number => {
9
+ const rounder = 10 ** numDecimals;
10
+ return (Math.ceil(num * rounder) / rounder);
11
+ };
12
+
13
+ export default ceilToNumDecimals;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Round a number (floor) to a certain number of decimals
3
+ * @author Gabe Abrams
4
+ * @param num the number to round
5
+ * @param numDecimals the number of decimals to round to
6
+ * @returns rounded number
7
+ */
8
+ const floorToNumDecimals = (num: number, numDecimals: number): number => {
9
+ const rounder = 10 ** numDecimals;
10
+ return (Math.floor(num * rounder) / rounder);
11
+ };
12
+
13
+ export default floorToNumDecimals;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Force a number to stay within specific bounds
3
+ * @author Gabe Abrams
4
+ * @param num the number to move into the bounds
5
+ * @param min the minimum number in the bound
6
+ * @param max the maximum number in the bound
7
+ * @returns bounded number
8
+ */
9
+ const forceNumIntoBounds = (num: number, min: number, max: number): number => {
10
+ return Math.max(
11
+ min,
12
+ Math.min(
13
+ max,
14
+ num,
15
+ ),
16
+ );
17
+ };
18
+
19
+ export default forceNumIntoBounds;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Pad a number's decimal with zeros on the right
3
+ * (e.g. 5.2 becomes 5.20 with 2 digit padding)
4
+ * @author Gabe Abrams
5
+ * @param num the number to pad
6
+ * @param numDigits the minimum number of digits after the decimal
7
+ * @returns padded number
8
+ */
9
+ const padDecimalZeros = (num: number, numDigits: number): string => {
10
+ // Skip if nothing to do
11
+ if (numDigits < 1) {
12
+ return;
13
+ }
14
+
15
+ // Convert to string
16
+ let out = String(num);
17
+
18
+ // Add a decimal point if there isn't one
19
+ if (!out.includes('.')) {
20
+ out += '.';
21
+ }
22
+
23
+ // Add zeros
24
+ while (out.split('.')[1].length < numDigits) {
25
+ out = `${out}0`;
26
+ }
27
+
28
+ // Return
29
+ return out;
30
+ };
31
+
32
+ export default padDecimalZeros;