dce-reactkit 3.0.0-beta.1 → 3.0.0-beta.4

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Pad a number with zeros on the left (e.g. 5 becomes 05 with 2 digit padding)
3
+ * @author Gabe Abrams
4
+ * @param num the number to pad
5
+ * @param numDigits the minimum number of digits before the decimal
6
+ * @returns padded number
7
+ */
8
+ const padZerosLeft = (num: number, numDigits: number): string => {
9
+ // Convert to string
10
+ let out = String(num);
11
+
12
+ // Add zeros
13
+ while (out.split('.')[0].length < numDigits) {
14
+ out = `0${out}`;
15
+ }
16
+
17
+ // Return
18
+ return out;
19
+ };
20
+
21
+ export default padZerosLeft;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Round a number 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 roundToNumDecimals = (num: number, numDecimals: number): number => {
9
+ const rounder = 10 ** numDecimals;
10
+ return (Math.round(num * rounder) / rounder);
11
+ };
12
+
13
+ export default roundToNumDecimals;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Sum the numbers in an array
3
+ * @author Gabe Abrams
4
+ * @param nums the numbers to sum
5
+ * @returns the sum of the numbers
6
+ */
7
+ const sum = (nums: number[]): number => {
8
+ return nums.reduce(
9
+ (a: number, b: number) => {
10
+ return (a + b);
11
+ },
12
+ 0,
13
+ );
14
+ };
15
+
16
+ export default sum;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wait for a certain number of ms
3
+ * @author Gabe Abrams
4
+ * @param ms number of ms to wait
5
+ */
6
+ const waitMs = async (ms = 0) => {
7
+ return new Promise((resolve) => {
8
+ setTimeout(resolve, ms);
9
+ });
10
+ };
11
+
12
+ export default waitMs;
package/src/index.ts ADDED
@@ -0,0 +1,61 @@
1
+ // Import components
2
+ import AppWrapper, { alert, confirm, showFatalError } from './components/AppWrapper';
3
+ import LoadingSpinner from './components/LoadingSpinner';
4
+ import ErrorBox from './components/ErrorBox';
5
+ import Modal from './components/Modal';
6
+ import TabBox from './components/TabBox';
7
+
8
+ // Import errors
9
+ import ErrorWithCode from './errors/ErrorWithCode';
10
+
11
+ // Import helpers
12
+ import abbreviate from './helpers/abbreviate';
13
+ import avg from './helpers/avg';
14
+ import ceilToNumDecimals from './helpers/ceilToNumDecimals';
15
+ import floorToNumDecimals from './helpers/floorToNumDecimals';
16
+ import forceNumIntoBounds from './helpers/forceNumIntoBounds';
17
+ import padDecimalZeros from './helpers/padDecimalZeros';
18
+ import padZerosLeft from './helpers/padZerosLeft';
19
+ import roundToNumDecimals from './helpers/roundToNumDecimals';
20
+ import sum from './helpers/sum';
21
+ import waitMs from './helpers/waitMs';
22
+
23
+ // Import types
24
+ import ModalButtonType from './types/ModalButtonType';
25
+ import ModalSize from './types/ModalSize';
26
+ import ModalType from './types/ModalType';
27
+ import ReactKitErrorCode from './types/ReactKitErrorCode';
28
+ import Variant from './types/Variant';
29
+
30
+ // Export each item
31
+ export {
32
+ // Components
33
+ AppWrapper,
34
+ LoadingSpinner,
35
+ ErrorBox,
36
+ Modal,
37
+ TabBox,
38
+ // Global functions
39
+ alert,
40
+ confirm,
41
+ showFatalError,
42
+ // Errors
43
+ ErrorWithCode,
44
+ // Helpers
45
+ abbreviate,
46
+ avg,
47
+ ceilToNumDecimals,
48
+ floorToNumDecimals,
49
+ forceNumIntoBounds,
50
+ padDecimalZeros,
51
+ padZerosLeft,
52
+ roundToNumDecimals,
53
+ sum,
54
+ waitMs,
55
+ // Types
56
+ ModalButtonType,
57
+ ModalSize,
58
+ ModalType,
59
+ ReactKitErrorCode,
60
+ Variant,
61
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Types of buttons in the modal
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalButtonType {
6
+ Okay = 'okay',
7
+ Cancel = 'cancel',
8
+ Yes = 'yes',
9
+ No = 'no',
10
+ Abandon = 'abandon',
11
+ GoBack = 'goBack',
12
+ Continue = 'continue',
13
+ ImSure = 'imSure',
14
+ Delete = 'delete',
15
+ Confirm = 'confirm',
16
+ }
17
+
18
+ export default ModalButtonType;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Modal sizes
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalSize {
6
+ Small = 'sm',
7
+ Medium = 'md',
8
+ Large = 'lg',
9
+ ExtraLarge = 'xl',
10
+ }
11
+
12
+ export default ModalSize;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Types of modals
3
+ * @author Gabe Abrams
4
+ */
5
+ enum ModalType {
6
+ Okay = 'okay', // [Okay]
7
+ OkayCancel = 'okay-cancel', // [Okay] [Cancel]
8
+ YesNo = 'yes-no', // [Yes] [No]
9
+ YesNoCancel = 'yes-no-cancel', // [Yes] [No] [Cancel]
10
+ AbandonGoBack = 'abandon-goBack', // [Abandon Changes] [Go Back]
11
+ ImSureCancel = 'imSure-cancel', // [I am sure] [Cancel]
12
+ DeleteCancel = 'delete-cancel', // [Yes, Delete] [Cancel]
13
+ ConfirmCancel = 'confirm-cancel', // [Confirm] [Cancel]
14
+ NoButtons = '-', // No buttons
15
+ }
16
+
17
+ export default ModalType;
@@ -0,0 +1,16 @@
1
+ // Highest error code = DRK2
2
+
3
+ /**
4
+ * List of error codes built into the react kit
5
+ * @author Gabe Abrams
6
+ */
7
+ enum ReactKitErrorCode {
8
+ NoResponse = 'DRK1',
9
+ NoCode = 'DRK2',
10
+ SessionExpired = 'DRK3',
11
+ MissingParameter = 'DRK4',
12
+ InvalidParameter = 'DRK5',
13
+ WrongCourse = 'DRK6',
14
+ }
15
+
16
+ export default ReactKitErrorCode;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bootstrap variants
3
+ * @author Gabe Abrams
4
+ */
5
+ enum Variant {
6
+ Primary = 'primary',
7
+ Secondary = 'secondary',
8
+ Success = 'success',
9
+ Warning = 'warning',
10
+ Info = 'info',
11
+ Danger = 'danger',
12
+ Light = 'light',
13
+ Dark = 'dark',
14
+ }
15
+
16
+ export default Variant;
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "esModuleInterop": true,
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+
9
+ "jsx": "react",
10
+ "module": "ESNext",
11
+ "declaration": true,
12
+ "declarationDir": "types",
13
+ "sourceMap": true,
14
+ "outDir": "dist",
15
+ "moduleResolution": "node",
16
+ "allowSyntheticDefaultImports": true,
17
+ "emitDeclarationOnly": true
18
+ },
19
+
20
+ "include": [
21
+ "./src/**/*"
22
+ ]
23
+ }