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.
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/lib/components/AppWrapper.d.ts +35 -0
- package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
- package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
- package/lib/cjs/lib/components/Modal.d.ts +40 -0
- package/lib/cjs/lib/components/TabBox.d.ts +11 -0
- package/lib/{errors → cjs/lib/errors}/ErrorWithCode.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/abbreviate.d.ts +1 -0
- package/lib/{helpers → cjs/lib/helpers}/avg.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/ceilToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/floorToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/forceNumIntoBounds.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/handleError.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/handleSuccess.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/padDecimalZeros.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/padZerosLeft.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/parseRequest.d.ts +1 -1
- package/lib/{helpers → cjs/lib/helpers}/roundToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/sum.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/visitServerEndpoint.d.ts +2 -2
- package/lib/{helpers → cjs/lib/helpers}/waitMs.d.ts +0 -0
- package/lib/cjs/lib/index.d.ts +27 -0
- package/lib/cjs/lib/types/ModalButtonType.d.ts +17 -0
- package/lib/cjs/lib/types/ModalSize.d.ts +11 -0
- package/lib/cjs/lib/types/ModalType.d.ts +16 -0
- package/lib/{types → cjs/lib/types}/ParamType.d.ts +0 -0
- package/lib/{types → cjs/lib/types}/ReactKitErrorCode.d.ts +0 -0
- package/lib/{types → cjs/lib/types}/Variant.d.ts +0 -0
- package/lib/cjs/types/components/AppWrapper.d.ts +40 -0
- package/lib/cjs/types/components/ErrorBox.d.ts +12 -0
- package/lib/cjs/types/components/LoadingSpinner.d.ts +7 -0
- package/lib/cjs/types/components/Modal.d.ts +40 -0
- package/lib/cjs/types/components/TabBox.d.ts +11 -0
- package/lib/cjs/types/errors/ErrorWithCode.d.ts +9 -0
- package/lib/cjs/types/helpers/abbreviate.d.ts +10 -0
- package/lib/cjs/types/helpers/alert.d.ts +2 -0
- package/lib/cjs/types/helpers/avg.d.ts +8 -0
- package/lib/cjs/types/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/confirm.d.ts +2 -0
- package/lib/cjs/types/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/cjs/types/helpers/handleError.d.ts +14 -0
- package/lib/cjs/types/helpers/handleSuccess.d.ts +8 -0
- package/lib/cjs/types/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/cjs/types/helpers/padZerosLeft.d.ts +9 -0
- package/lib/cjs/types/helpers/parseRequest.d.ts +21 -0
- package/lib/cjs/types/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/showFatalError.d.ts +2 -0
- package/lib/cjs/types/helpers/sum.d.ts +8 -0
- package/lib/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/cjs/types/helpers/waitMs.d.ts +7 -0
- package/lib/cjs/types/index.d.ts +22 -0
- package/lib/cjs/types/types/ModalButtonType.d.ts +17 -0
- package/lib/cjs/types/types/ModalSize.d.ts +11 -0
- package/lib/cjs/types/types/ModalType.d.ts +16 -0
- package/lib/cjs/types/types/ParamType.d.ts +17 -0
- package/lib/cjs/types/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/cjs/types/types/Variant.d.ts +15 -0
- package/lib/esm/index.js +16 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/lib/components/AppWrapper.d.ts +35 -0
- package/lib/esm/lib/components/ErrorBox.d.ts +12 -0
- package/lib/esm/lib/components/LoadingSpinner.d.ts +7 -0
- package/lib/esm/lib/components/Modal.d.ts +40 -0
- package/lib/esm/lib/components/TabBox.d.ts +11 -0
- package/lib/esm/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/esm/lib/helpers/abbreviate.d.ts +10 -0
- package/lib/esm/lib/helpers/avg.d.ts +8 -0
- package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/esm/lib/helpers/handleError.d.ts +14 -0
- package/lib/esm/lib/helpers/handleSuccess.d.ts +8 -0
- package/lib/esm/lib/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/esm/lib/helpers/padZerosLeft.d.ts +9 -0
- package/lib/esm/lib/helpers/parseRequest.d.ts +21 -0
- package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/sum.d.ts +8 -0
- package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/esm/lib/helpers/waitMs.d.ts +7 -0
- package/lib/esm/lib/index.d.ts +27 -0
- package/lib/esm/lib/types/ModalButtonType.d.ts +17 -0
- package/lib/esm/lib/types/ModalSize.d.ts +11 -0
- package/lib/esm/lib/types/ModalType.d.ts +16 -0
- package/lib/esm/lib/types/ParamType.d.ts +17 -0
- package/lib/esm/lib/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/esm/lib/types/Variant.d.ts +15 -0
- package/lib/esm/types/components/AppWrapper.d.ts +40 -0
- package/lib/esm/types/components/ErrorBox.d.ts +12 -0
- package/lib/esm/types/components/LoadingSpinner.d.ts +7 -0
- package/lib/esm/types/components/Modal.d.ts +40 -0
- package/lib/esm/types/components/TabBox.d.ts +11 -0
- package/lib/esm/types/errors/ErrorWithCode.d.ts +9 -0
- package/lib/esm/types/helpers/abbreviate.d.ts +10 -0
- package/lib/esm/types/helpers/alert.d.ts +2 -0
- package/lib/esm/types/helpers/avg.d.ts +8 -0
- package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/confirm.d.ts +2 -0
- package/lib/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/esm/types/helpers/handleError.d.ts +14 -0
- package/lib/esm/types/helpers/handleSuccess.d.ts +8 -0
- package/lib/esm/types/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/esm/types/helpers/padZerosLeft.d.ts +9 -0
- package/lib/esm/types/helpers/parseRequest.d.ts +21 -0
- package/lib/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/showFatalError.d.ts +2 -0
- package/lib/esm/types/helpers/sum.d.ts +8 -0
- package/lib/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/esm/types/helpers/waitMs.d.ts +7 -0
- package/lib/esm/types/index.d.ts +22 -0
- package/lib/esm/types/types/ModalButtonType.d.ts +17 -0
- package/lib/esm/types/types/ModalSize.d.ts +11 -0
- package/lib/esm/types/types/ModalType.d.ts +16 -0
- package/lib/esm/types/types/ParamType.d.ts +17 -0
- package/lib/esm/types/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/esm/types/types/Variant.d.ts +15 -0
- package/lib/index.d.ts +274 -0
- package/package.json +26 -5
- package/rollup.config.js +43 -0
- package/src/components/AppWrapper.tsx +212 -36
- package/src/components/LoadingSpinner.tsx +3 -0
- package/src/components/Modal.tsx +65 -95
- package/src/components/TabBox.tsx +136 -0
- package/src/helpers/abbreviate.tsx +2 -0
- package/src/helpers/padDecimalZeros.tsx +1 -1
- package/src/index.ts +61 -0
- package/src/types/ModalButtonType.tsx +18 -0
- package/src/types/ModalSize.tsx +12 -0
- package/src/types/ModalType.tsx +17 -0
- package/tsconfig.json +14 -17
- package/lib/components/AppWrapper.d.ts +0 -20
- package/lib/components/AppWrapper.js +0 -133
- package/lib/components/AppWrapper.js.map +0 -1
- package/lib/components/ErrorBox.js +0 -65
- package/lib/components/ErrorBox.js.map +0 -1
- package/lib/components/LoadingSpinner.js +0 -41
- package/lib/components/LoadingSpinner.js.map +0 -1
- package/lib/components/Modal.d.ts +0 -69
- package/lib/components/Modal.js +0 -315
- package/lib/components/Modal.js.map +0 -1
- package/lib/errors/ErrorWithCode.js +0 -33
- package/lib/errors/ErrorWithCode.js.map +0 -1
- package/lib/helpers/abbreviate.js +0 -21
- package/lib/helpers/abbreviate.js.map +0 -1
- package/lib/helpers/avg.js +0 -24
- package/lib/helpers/avg.js.map +0 -1
- package/lib/helpers/ceilToNumDecimals.js +0 -15
- package/lib/helpers/ceilToNumDecimals.js.map +0 -1
- package/lib/helpers/floorToNumDecimals.js +0 -15
- package/lib/helpers/floorToNumDecimals.js.map +0 -1
- package/lib/helpers/forceNumIntoBounds.js +0 -15
- package/lib/helpers/forceNumIntoBounds.js.map +0 -1
- package/lib/helpers/handleError.js +0 -54
- package/lib/helpers/handleError.js.map +0 -1
- package/lib/helpers/handleSuccess.js +0 -20
- package/lib/helpers/handleSuccess.js.map +0 -1
- package/lib/helpers/padDecimalZeros.js +0 -30
- package/lib/helpers/padDecimalZeros.js.map +0 -1
- package/lib/helpers/padZerosLeft.js +0 -21
- package/lib/helpers/padZerosLeft.js.map +0 -1
- package/lib/helpers/parseRequest.js +0 -240
- package/lib/helpers/parseRequest.js.map +0 -1
- package/lib/helpers/roundToNumDecimals.js +0 -15
- package/lib/helpers/roundToNumDecimals.js.map +0 -1
- package/lib/helpers/showFatalError.d.ts +0 -2
- package/lib/helpers/showFatalError.js +0 -5
- package/lib/helpers/showFatalError.js.map +0 -1
- package/lib/helpers/sum.js +0 -15
- package/lib/helpers/sum.js.map +0 -1
- package/lib/helpers/visitServerEndpoint.js +0 -135
- package/lib/helpers/visitServerEndpoint.js.map +0 -1
- package/lib/helpers/waitMs.js +0 -55
- package/lib/helpers/waitMs.js.map +0 -1
- package/lib/types/ParamType.js +0 -21
- package/lib/types/ParamType.js.map +0 -1
- package/lib/types/ReactKitErrorCode.js +0 -18
- package/lib/types/ReactKitErrorCode.js.map +0 -1
- package/lib/types/Variant.js +0 -19
- package/lib/types/Variant.js.map +0 -1
- package/src/helpers/handleError.ts +0 -65
- package/src/helpers/handleSuccess.ts +0 -18
- package/src/helpers/parseRequest.ts +0 -299
- package/src/helpers/showFatalError.tsx +0 -3
- package/src/helpers/visitServerEndpoint.tsx +0 -110
- package/src/types/ParamType.ts +0 -18
package/src/components/Modal.tsx
CHANGED
|
@@ -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
|
|
117
|
-
[k: string]:
|
|
84
|
+
const modalTypeToModalButtonTypes: {
|
|
85
|
+
[k: string]: ModalButtonType[]
|
|
118
86
|
} = {
|
|
119
87
|
[ModalType.Okay]: [
|
|
120
|
-
|
|
88
|
+
ModalButtonType.Okay,
|
|
121
89
|
],
|
|
122
90
|
[ModalType.OkayCancel]: [
|
|
123
|
-
|
|
124
|
-
|
|
91
|
+
ModalButtonType.Okay,
|
|
92
|
+
ModalButtonType.Cancel,
|
|
125
93
|
],
|
|
126
94
|
[ModalType.YesNo]: [
|
|
127
|
-
|
|
128
|
-
|
|
95
|
+
ModalButtonType.Yes,
|
|
96
|
+
ModalButtonType.No,
|
|
129
97
|
],
|
|
130
98
|
[ModalType.YesNoCancel]: [
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
99
|
+
ModalButtonType.Yes,
|
|
100
|
+
ModalButtonType.No,
|
|
101
|
+
ModalButtonType.Cancel,
|
|
134
102
|
],
|
|
135
103
|
[ModalType.AbandonGoBack]: [
|
|
136
|
-
|
|
137
|
-
|
|
104
|
+
ModalButtonType.Abandon,
|
|
105
|
+
ModalButtonType.GoBack,
|
|
138
106
|
],
|
|
139
107
|
[ModalType.ImSureCancel]: [
|
|
140
|
-
|
|
141
|
-
|
|
108
|
+
ModalButtonType.ImSure,
|
|
109
|
+
ModalButtonType.Cancel,
|
|
142
110
|
],
|
|
143
111
|
[ModalType.DeleteCancel]: [
|
|
144
|
-
|
|
145
|
-
|
|
112
|
+
ModalButtonType.Delete,
|
|
113
|
+
ModalButtonType.Cancel,
|
|
146
114
|
],
|
|
147
115
|
[ModalType.ConfirmCancel]: [
|
|
148
|
-
|
|
149
|
-
|
|
116
|
+
ModalButtonType.Confirm,
|
|
117
|
+
ModalButtonType.Cancel,
|
|
150
118
|
],
|
|
151
119
|
};
|
|
152
120
|
|
|
153
121
|
// Button type styling and labels
|
|
154
|
-
const
|
|
155
|
-
[
|
|
122
|
+
const ModalButtonTypeToLabelAndVariant = {
|
|
123
|
+
[ModalButtonType.Okay]: {
|
|
156
124
|
label: 'Okay',
|
|
157
125
|
variant: Variant.Dark,
|
|
158
126
|
},
|
|
159
|
-
[
|
|
127
|
+
[ModalButtonType.Cancel]: {
|
|
160
128
|
label: 'Cancel',
|
|
161
129
|
variant: Variant.Secondary,
|
|
162
130
|
},
|
|
163
|
-
[
|
|
131
|
+
[ModalButtonType.Yes]: {
|
|
164
132
|
label: 'Yes',
|
|
165
133
|
variant: Variant.Dark,
|
|
166
134
|
},
|
|
167
|
-
[
|
|
135
|
+
[ModalButtonType.No]: {
|
|
168
136
|
label: 'No',
|
|
169
137
|
variant: Variant.Secondary,
|
|
170
138
|
},
|
|
171
|
-
[
|
|
139
|
+
[ModalButtonType.Abandon]: {
|
|
172
140
|
label: 'Abandon Changes',
|
|
173
141
|
variant: Variant.Warning,
|
|
174
142
|
},
|
|
175
|
-
[
|
|
143
|
+
[ModalButtonType.GoBack]: {
|
|
176
144
|
label: 'Go Back',
|
|
177
145
|
variant: Variant.Secondary,
|
|
178
146
|
},
|
|
179
|
-
[
|
|
147
|
+
[ModalButtonType.Continue]: {
|
|
180
148
|
label: 'Continue',
|
|
181
149
|
variant: Variant.Dark,
|
|
182
150
|
},
|
|
183
|
-
[
|
|
151
|
+
[ModalButtonType.ImSure]: {
|
|
184
152
|
label: 'I am sure',
|
|
185
153
|
variant: Variant.Warning,
|
|
186
154
|
},
|
|
187
|
-
[
|
|
155
|
+
[ModalButtonType.Delete]: {
|
|
188
156
|
label: 'Yes, Delete',
|
|
189
157
|
variant: Variant.Danger,
|
|
190
158
|
},
|
|
191
|
-
[
|
|
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:
|
|
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
|
|
285
|
+
* @param ModalButtonType the button that was clicked when closing the
|
|
320
286
|
* modal
|
|
321
287
|
*/
|
|
322
|
-
const handleClose = async (
|
|
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(
|
|
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
|
|
321
|
+
const ModalButtonTypes: ModalButtonType[] = modalTypeToModalButtonTypes[type] ?? [];
|
|
356
322
|
|
|
357
323
|
// Create buttons
|
|
358
|
-
const buttons =
|
|
324
|
+
const buttons = ModalButtonTypes.map((ModalButtonType: ModalButtonType, i) => {
|
|
359
325
|
// Get default style
|
|
360
326
|
let {
|
|
361
327
|
label,
|
|
362
328
|
variant,
|
|
363
|
-
} =
|
|
329
|
+
} = ModalButtonTypeToLabelAndVariant[ModalButtonType];
|
|
364
330
|
|
|
365
331
|
// Override with customizations
|
|
366
|
-
|
|
367
|
-
|
|
332
|
+
const newLabel = props[`${ModalButtonType}Label`];
|
|
333
|
+
if (newLabel) {
|
|
334
|
+
label = newLabel;
|
|
368
335
|
}
|
|
369
|
-
|
|
370
|
-
|
|
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 ===
|
|
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-${
|
|
348
|
+
className={`Modal-${ModalButtonType}-button btn btn-${variant} ${last ? '' : 'mr-1'}`}
|
|
381
349
|
onClick={() => {
|
|
382
|
-
handleClose(
|
|
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
|
-
|
|
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;
|
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,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
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"strict": true,
|
|
5
|
+
"skipLibCheck": true,
|
|
6
|
+
"jsx": "react",
|
|
7
|
+
"module": "ESNext",
|
|
8
8
|
"declaration": true,
|
|
9
|
+
"declarationDir": "types",
|
|
9
10
|
"sourceMap": true,
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
],
|
|
16
|
-
"outDir": "./lib"
|
|
11
|
+
"outDir": "./lib",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"emitDeclarationOnly": true,
|
|
14
|
+
"allowSyntheticDefaultImports": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
16
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
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;
|