dce-reactkit 2.0.11 → 3.0.0-beta.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.
- package/dist/cjs/index.js +36424 -0
- package/dist/cjs/index.js.map +1 -0
- package/{lib → dist/cjs/types}/components/AppWrapper.d.ts +8 -3
- package/{lib → dist/cjs/types}/components/ErrorBox.d.ts +0 -0
- package/{lib → dist/cjs/types}/components/LoadingSpinner.d.ts +1 -0
- package/{lib → dist/cjs/types}/components/Modal.d.ts +5 -36
- package/{lib → dist/cjs/types}/components/TabBox.d.ts +0 -0
- package/{lib → dist/cjs/types}/errors/ErrorWithCode.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/abbreviate.d.ts +1 -0
- package/{lib → dist/cjs/types}/helpers/avg.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/ceilToNumDecimals.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/floorToNumDecimals.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/forceNumIntoBounds.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/padDecimalZeros.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/padZerosLeft.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/roundToNumDecimals.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/sum.d.ts +0 -0
- package/{lib → dist/cjs/types}/helpers/waitMs.d.ts +0 -0
- package/dist/cjs/types/index.d.ts +22 -0
- package/dist/cjs/types/types/ModalButtonType.d.ts +17 -0
- package/dist/cjs/types/types/ModalSize.d.ts +11 -0
- package/dist/cjs/types/types/ModalType.d.ts +16 -0
- package/{lib → dist/cjs/types}/types/ReactKitErrorCode.d.ts +0 -0
- package/{lib → dist/cjs/types}/types/Variant.d.ts +0 -0
- package/dist/esm/index.js +36375 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/components/AppWrapper.d.ts +40 -0
- package/dist/esm/types/components/ErrorBox.d.ts +12 -0
- package/dist/esm/types/components/LoadingSpinner.d.ts +7 -0
- package/dist/esm/types/components/Modal.d.ts +40 -0
- package/dist/esm/types/components/TabBox.d.ts +11 -0
- package/dist/esm/types/errors/ErrorWithCode.d.ts +9 -0
- package/dist/esm/types/helpers/abbreviate.d.ts +10 -0
- package/dist/esm/types/helpers/avg.d.ts +8 -0
- package/dist/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
- package/dist/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
- package/dist/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
- package/dist/esm/types/helpers/padDecimalZeros.d.ts +10 -0
- package/dist/esm/types/helpers/padZerosLeft.d.ts +9 -0
- package/dist/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
- package/dist/esm/types/helpers/sum.d.ts +8 -0
- package/dist/esm/types/helpers/waitMs.d.ts +7 -0
- package/dist/esm/types/index.d.ts +22 -0
- package/dist/esm/types/types/ModalButtonType.d.ts +17 -0
- package/dist/esm/types/types/ModalSize.d.ts +11 -0
- package/dist/esm/types/types/ModalType.d.ts +16 -0
- package/dist/esm/types/types/ReactKitErrorCode.d.ts +13 -0
- package/dist/esm/types/types/Variant.d.ts +15 -0
- package/dist/index.d.ts +274 -0
- package/package.json +20 -22
- package/rollup.config.js +42 -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 +16 -17
- package/.eslintrc.js +0 -95
- 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.d.ts +0 -14
- package/lib/helpers/handleError.js +0 -54
- package/lib/helpers/handleError.js.map +0 -1
- package/lib/helpers/handleSuccess.d.ts +0 -8
- 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.d.ts +0 -21
- 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.d.ts +0 -23
- 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.d.ts +0 -17
- 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/rollup.config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
2
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
3
|
+
import typescript from "@rollup/plugin-typescript";
|
|
4
|
+
import dts from "rollup-plugin-dts";
|
|
5
|
+
|
|
6
|
+
const packageJson = require("./package.json");
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
{
|
|
10
|
+
input: "src/index.ts",
|
|
11
|
+
output: [
|
|
12
|
+
{
|
|
13
|
+
file: packageJson.main,
|
|
14
|
+
format: "cjs",
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
file: packageJson.module,
|
|
19
|
+
format: "esm",
|
|
20
|
+
sourcemap: true,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
plugins: [
|
|
24
|
+
resolve(),
|
|
25
|
+
commonjs(),
|
|
26
|
+
typescript({ tsconfig: "./tsconfig.json" }),
|
|
27
|
+
],
|
|
28
|
+
external: [
|
|
29
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
30
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
input: "dist/esm/types/index.d.ts",
|
|
35
|
+
output: [{ file: "dist/index.d.ts", format: "esm" }],
|
|
36
|
+
plugins: [dts()],
|
|
37
|
+
external: [
|
|
38
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
39
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
@@ -5,16 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// Import React
|
|
8
|
-
import React, { useState
|
|
8
|
+
import React, { useState } from 'react';
|
|
9
9
|
|
|
10
10
|
// Import shared components
|
|
11
11
|
import ErrorBox from './ErrorBox';
|
|
12
12
|
|
|
13
|
-
// Import helpers
|
|
14
|
-
import { setSessionExpiryHandler } from '../helpers/visitServerEndpoint';
|
|
15
|
-
|
|
16
13
|
// Import shared types
|
|
17
14
|
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
15
|
+
import ModalButtonType from '../types/ModalButtonType';
|
|
16
|
+
import ModalType from '../types/ModalType';
|
|
18
17
|
|
|
19
18
|
// Import shared components
|
|
20
19
|
import Modal from './Modal';
|
|
@@ -53,17 +52,18 @@ let onAlertClosed: () => void;
|
|
|
53
52
|
* @param title the title text to display at the top of the alert
|
|
54
53
|
* @param text the text to display in the alert
|
|
55
54
|
*/
|
|
56
|
-
export const alert = async (title: string, text: string) => {
|
|
55
|
+
export const alert = async (title: string, text: string): Promise<undefined> => {
|
|
57
56
|
// Fallback if alert not available
|
|
58
57
|
if (!setAlertInfo) {
|
|
59
|
-
|
|
58
|
+
window.alert(`${title}\n\n${text}`);
|
|
59
|
+
return undefined;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// Return promise that resolves when alert is closed
|
|
63
63
|
return new Promise((resolve) => {
|
|
64
64
|
// Setup handler
|
|
65
65
|
onAlertClosed = () => {
|
|
66
|
-
resolve(
|
|
66
|
+
resolve(undefined);
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
// Show the alert
|
|
@@ -131,7 +131,7 @@ let setFatalErrorTitle: (title: string) => void;
|
|
|
131
131
|
export const showFatalError = (
|
|
132
132
|
error: any,
|
|
133
133
|
errorTitle: string = 'An Error Occurred',
|
|
134
|
-
) => {
|
|
134
|
+
): undefined => {
|
|
135
135
|
// Determine message and code
|
|
136
136
|
const message: string = (
|
|
137
137
|
typeof error === 'string'
|
|
@@ -146,23 +146,42 @@ export const showFatalError = (
|
|
|
146
146
|
|
|
147
147
|
// Handle case where app hasn't loaded
|
|
148
148
|
if (!setFatalErrorMessage || !setFatalErrorCode) {
|
|
149
|
-
|
|
149
|
+
alert(
|
|
150
150
|
errorTitle,
|
|
151
151
|
`${message} (code: ${code}). Please contact support.`,
|
|
152
152
|
);
|
|
153
|
+
return undefined;
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
// Use setters
|
|
156
157
|
setFatalErrorMessage(message);
|
|
157
158
|
setFatalErrorCode(code);
|
|
158
159
|
setFatalErrorTitle(errorTitle);
|
|
160
|
+
|
|
161
|
+
return undefined;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/*----------------------------------------*/
|
|
165
|
+
/* Session Expired */
|
|
166
|
+
/*----------------------------------------*/
|
|
167
|
+
|
|
168
|
+
// Stored copies of setters
|
|
169
|
+
let setSessionHasExpired: (isExpired: boolean) => void;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Show the "session expired" message
|
|
173
|
+
* @author Gabe Abrams
|
|
174
|
+
*/
|
|
175
|
+
export const showSessionExpiredMessage = (): undefined => {
|
|
176
|
+
setSessionHasExpired(true);
|
|
177
|
+
return undefined;
|
|
159
178
|
};
|
|
160
179
|
|
|
161
180
|
/*------------------------------------------------------------------------*/
|
|
162
181
|
/* Component */
|
|
163
182
|
/*------------------------------------------------------------------------*/
|
|
164
183
|
|
|
165
|
-
const AppWrapper = (props: Props): React.ReactElement => {
|
|
184
|
+
const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
|
|
166
185
|
/*------------------------------------------------------------------------*/
|
|
167
186
|
/* Setup */
|
|
168
187
|
/*------------------------------------------------------------------------*/
|
|
@@ -217,27 +236,9 @@ const AppWrapper = (props: Props): React.ReactElement => {
|
|
|
217
236
|
// Session expired
|
|
218
237
|
const [
|
|
219
238
|
sessionHasExpired,
|
|
220
|
-
|
|
239
|
+
setSessionHasExpiredInner,
|
|
221
240
|
] = useState<boolean>(false);
|
|
222
|
-
|
|
223
|
-
/*------------------------------------------------------------------------*/
|
|
224
|
-
/* Lifecycle Functions */
|
|
225
|
-
/*------------------------------------------------------------------------*/
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Mount
|
|
229
|
-
* @author Gabe Abrams
|
|
230
|
-
*/
|
|
231
|
-
useEffect(
|
|
232
|
-
() => {
|
|
233
|
-
// Add session expired handler
|
|
234
|
-
setSessionExpiryHandler(() => {
|
|
235
|
-
// Session expired!
|
|
236
|
-
setSessionHasExpired(true);
|
|
237
|
-
});
|
|
238
|
-
},
|
|
239
|
-
[],
|
|
240
|
-
);
|
|
241
|
+
setSessionHasExpired = setSessionHasExpiredInner;
|
|
241
242
|
|
|
242
243
|
/*------------------------------------------------------------------------*/
|
|
243
244
|
/* Render */
|
|
@@ -256,7 +257,7 @@ const AppWrapper = (props: Props): React.ReactElement => {
|
|
|
256
257
|
modal = (
|
|
257
258
|
<Modal
|
|
258
259
|
title={alertInfo.title}
|
|
259
|
-
type={
|
|
260
|
+
type={ModalType.Okay}
|
|
260
261
|
onClose={() => {
|
|
261
262
|
// Alert closed
|
|
262
263
|
if (onAlertClosed) {
|
|
@@ -276,10 +277,10 @@ const AppWrapper = (props: Props): React.ReactElement => {
|
|
|
276
277
|
modal = (
|
|
277
278
|
<Modal
|
|
278
279
|
title={confirmInfo.title}
|
|
279
|
-
type={
|
|
280
|
+
type={ModalType.OkayCancel}
|
|
280
281
|
onClose={(buttonType) => {
|
|
281
282
|
if (onConfirmClosed) {
|
|
282
|
-
onConfirmClosed(buttonType ===
|
|
283
|
+
onConfirmClosed(buttonType === ModalButtonType.Okay);
|
|
283
284
|
}
|
|
284
285
|
}}
|
|
285
286
|
dontAllowBackdropExit
|
|
@@ -303,8 +304,8 @@ const AppWrapper = (props: Props): React.ReactElement => {
|
|
|
303
304
|
const error = (
|
|
304
305
|
sessionHasExpired
|
|
305
306
|
? new ErrorWithCode(
|
|
306
|
-
fatalErrorMessage,
|
|
307
|
-
fatalErrorCode,
|
|
307
|
+
(fatalErrorMessage ?? 'An unknown error has occurred. Please contact support.'),
|
|
308
|
+
(fatalErrorCode ?? ReactKitErrorCode.NoCode),
|
|
308
309
|
)
|
|
309
310
|
: new ErrorWithCode(
|
|
310
311
|
sessionExpiredMessage,
|
|
@@ -319,7 +320,7 @@ const AppWrapper = (props: Props): React.ReactElement => {
|
|
|
319
320
|
display: 'block',
|
|
320
321
|
width: '100vw',
|
|
321
322
|
minHeight: '100vh',
|
|
322
|
-
paddingTop: '
|
|
323
|
+
paddingTop: '2rem',
|
|
323
324
|
backgroundColor: (
|
|
324
325
|
dark
|
|
325
326
|
? '#222'
|
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,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
3
|
+
"target": "es2016",
|
|
4
4
|
"esModuleInterop": true,
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
"jsx": "react",
|
|
10
|
+
"module": "ESNext",
|
|
8
11
|
"declaration": true,
|
|
12
|
+
"declarationDir": "types",
|
|
9
13
|
"sourceMap": true,
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"dom"
|
|
15
|
-
],
|
|
16
|
-
"outDir": "./lib"
|
|
14
|
+
"outDir": "dist",
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
"emitDeclarationOnly": true
|
|
17
18
|
},
|
|
19
|
+
|
|
18
20
|
"include": [
|
|
19
|
-
"./src"
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
"files": true
|
|
23
|
-
}
|
|
24
|
-
}
|
|
21
|
+
"./src/**/*"
|
|
22
|
+
]
|
|
23
|
+
}
|