dce-reactkit 2.0.11 → 3.0.1
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/{components → cjs/lib/components}/AppWrapper.d.ts +2 -2
- package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
- package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
- package/lib/{components → cjs/lib/components}/Modal.d.ts +5 -36
- package/lib/{components → cjs/lib/components}/TabBox.d.ts +0 -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 +37 -36
- package/src/components/LoadingSpinner.tsx +3 -0
- package/src/components/Modal.tsx +50 -94
- 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.js +0 -277
- 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.js +0 -321
- package/lib/components/Modal.js.map +0 -1
- package/lib/components/TabBox.js +0 -42
- package/lib/components/TabBox.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/alert.d.ts +0 -2
- package/lib/helpers/alert.js +0 -5
- package/lib/helpers/alert.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/confirm.d.ts +0 -2
- package/lib/helpers/confirm.js +0 -5
- package/lib/helpers/confirm.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/alert.tsx +0 -3
- package/src/helpers/confirm.tsx +0 -3
- 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,7 @@ 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,
|
|
212
180
|
// If true, don't allow the user to click the backdrop to exit
|
|
213
181
|
dontAllowBackdropExit?: boolean,
|
|
214
182
|
// Custom label for "okay" button
|
|
@@ -259,15 +227,7 @@ type Props = {
|
|
|
259
227
|
/* Component */
|
|
260
228
|
/*------------------------------------------------------------------------*/
|
|
261
229
|
|
|
262
|
-
const Modal: (
|
|
263
|
-
React.FC<Props>
|
|
264
|
-
& {
|
|
265
|
-
ModalType: typeof ModalType,
|
|
266
|
-
ModalSize: typeof ModalSize,
|
|
267
|
-
ButtonType: typeof ButtonType,
|
|
268
|
-
Variant: typeof Variant,
|
|
269
|
-
}
|
|
270
|
-
) = (props) => {
|
|
230
|
+
const Modal: React.FC<Props> = (props) => {
|
|
271
231
|
/*------------------------------------------------------------------------*/
|
|
272
232
|
/* Setup */
|
|
273
233
|
/*------------------------------------------------------------------------*/
|
|
@@ -322,10 +282,10 @@ const Modal: (
|
|
|
322
282
|
/**
|
|
323
283
|
* Handles the closing of the modal
|
|
324
284
|
* @author Gabe Abrams
|
|
325
|
-
* @param
|
|
285
|
+
* @param ModalButtonType the button that was clicked when closing the
|
|
326
286
|
* modal
|
|
327
287
|
*/
|
|
328
|
-
const handleClose = async (
|
|
288
|
+
const handleClose = async (ModalButtonType: ModalButtonType) => {
|
|
329
289
|
// Don't close if no handler
|
|
330
290
|
if (!onClose) {
|
|
331
291
|
return;
|
|
@@ -346,7 +306,7 @@ const Modal: (
|
|
|
346
306
|
|
|
347
307
|
// Call the handler after the modal has animated out
|
|
348
308
|
await waitMs(MS_TO_ANIMATE);
|
|
349
|
-
onClose(
|
|
309
|
+
onClose(ModalButtonType);
|
|
350
310
|
};
|
|
351
311
|
|
|
352
312
|
/*------------------------------------------------------------------------*/
|
|
@@ -358,34 +318,36 @@ const Modal: (
|
|
|
358
318
|
/*----------------------------------------*/
|
|
359
319
|
|
|
360
320
|
// Get list of buttons for this modal type
|
|
361
|
-
const
|
|
321
|
+
const ModalButtonTypes: ModalButtonType[] = modalTypeToModalButtonTypes[type] ?? [];
|
|
362
322
|
|
|
363
323
|
// Create buttons
|
|
364
|
-
const buttons =
|
|
324
|
+
const buttons = ModalButtonTypes.map((ModalButtonType: ModalButtonType, i) => {
|
|
365
325
|
// Get default style
|
|
366
326
|
let {
|
|
367
327
|
label,
|
|
368
328
|
variant,
|
|
369
|
-
} =
|
|
329
|
+
} = ModalButtonTypeToLabelAndVariant[ModalButtonType];
|
|
370
330
|
|
|
371
331
|
// Override with customizations
|
|
372
|
-
|
|
373
|
-
|
|
332
|
+
const newLabel = props[`${ModalButtonType}Label`];
|
|
333
|
+
if (newLabel) {
|
|
334
|
+
label = newLabel;
|
|
374
335
|
}
|
|
375
|
-
|
|
376
|
-
|
|
336
|
+
const newVariant = props[`${ModalButtonType}Variant`];
|
|
337
|
+
if (newVariant) {
|
|
338
|
+
variant = newVariant;
|
|
377
339
|
}
|
|
378
340
|
|
|
379
341
|
// Check if this button is last
|
|
380
|
-
const last = (i ===
|
|
342
|
+
const last = (i === ModalButtonTypes.length - 1);
|
|
381
343
|
|
|
382
344
|
// Create the button
|
|
383
345
|
return (
|
|
384
346
|
<button
|
|
385
347
|
type="button"
|
|
386
|
-
className={`Modal-${
|
|
348
|
+
className={`Modal-${ModalButtonType}-button btn btn-${variant} ${last ? '' : 'mr-1'}`}
|
|
387
349
|
onClick={() => {
|
|
388
|
-
handleClose(
|
|
350
|
+
handleClose(ModalButtonType);
|
|
389
351
|
}}
|
|
390
352
|
>
|
|
391
353
|
{label}
|
|
@@ -411,7 +373,7 @@ const Modal: (
|
|
|
411
373
|
size={size !== ModalSize.Medium ? size : undefined}
|
|
412
374
|
onHide={() => {
|
|
413
375
|
if (!dontAllowBackdropExit) {
|
|
414
|
-
handleClose(
|
|
376
|
+
handleClose(ModalButtonType.Cancel);
|
|
415
377
|
}
|
|
416
378
|
}}
|
|
417
379
|
style={{
|
|
@@ -452,10 +414,4 @@ const Modal: (
|
|
|
452
414
|
/* Wrap Up */
|
|
453
415
|
/*------------------------------------------------------------------------*/
|
|
454
416
|
|
|
455
|
-
// Add enums
|
|
456
|
-
Modal.ModalType = ModalType;
|
|
457
|
-
Modal.ModalSize = ModalSize;
|
|
458
|
-
Modal.ButtonType = ButtonType;
|
|
459
|
-
Modal.Variant = Variant;
|
|
460
|
-
|
|
461
417
|
export default Modal;
|
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
|
}
|