dce-reactkit 3.5.13 → 3.6.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.
Files changed (34) hide show
  1. package/dist/cjs/index.js +355 -298
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/client/initClient.d.ts +7 -0
  4. package/dist/cjs/types/components/AppWrapper.d.ts +0 -1
  5. package/dist/cjs/types/helpers/makeLinksClickable.d.ts +4 -2
  6. package/dist/esm/index.js +355 -298
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/types/client/initClient.d.ts +7 -0
  9. package/dist/esm/types/components/AppWrapper.d.ts +0 -1
  10. package/dist/esm/types/helpers/makeLinksClickable.d.ts +4 -2
  11. package/dist/index.d.ts +5 -3
  12. package/package.json +1 -1
  13. package/src/client/initClient.tsx +20 -4
  14. package/src/components/AppWrapper.tsx +8 -6
  15. package/src/components/ButtonInputGroup.tsx +6 -6
  16. package/src/components/CSVDownloadButton.tsx +6 -6
  17. package/src/components/CheckboxButton.tsx +19 -8
  18. package/src/components/CopiableBox.tsx +8 -8
  19. package/src/components/Drawer.tsx +7 -7
  20. package/src/components/ErrorBox.tsx +5 -5
  21. package/src/components/IntelliTable.tsx +135 -135
  22. package/src/components/ItemPicker/NestableItemList.tsx +7 -7
  23. package/src/components/ItemPicker/index.tsx +7 -7
  24. package/src/components/LoadingSpinner.tsx +4 -4
  25. package/src/components/LogReviewer.tsx +21 -22
  26. package/src/components/Modal.tsx +163 -75
  27. package/src/components/PopFailureMark.tsx +7 -7
  28. package/src/components/PopPendingMark.tsx +7 -7
  29. package/src/components/PopSuccessMark.tsx +7 -7
  30. package/src/components/RadioButton.tsx +17 -8
  31. package/src/components/SimpleDateChooser.tsx +14 -13
  32. package/src/components/TabBox.tsx +7 -7
  33. package/src/helpers/genRouteHandler.ts +45 -41
  34. package/src/helpers/makeLinksClickable.tsx +6 -4
@@ -32,6 +32,12 @@ declare let sessionExpiredMessage: string | undefined;
32
32
  * @returns session expired message
33
33
  */
34
34
  export declare const getSessionExpiredMessage: () => string;
35
+ declare let darkModeOn: boolean;
36
+ /**
37
+ * Get whether dark mode is enabled or not
38
+ * @returns true if dark mode is enabled
39
+ */
40
+ export declare const isDarkModeOn: () => boolean;
35
41
  /**
36
42
  * Initialize the client-side version of reactkit
37
43
  * @author Gabe Abrams
@@ -42,5 +48,6 @@ export declare const getSessionExpiredMessage: () => string;
42
48
  declare const initClient: (opts: {
43
49
  sendRequest: SendRequestFunction;
44
50
  sessionExpiredMessage?: string;
51
+ darkModeOn?: boolean;
45
52
  }) => void;
46
53
  export default initClient;
@@ -7,7 +7,6 @@ import React from 'react';
7
7
  import Variant from '../types/Variant';
8
8
  type Props = {
9
9
  children: React.ReactNode;
10
- dark?: boolean;
11
10
  };
12
11
  /**
13
12
  * Redirect to a new page
@@ -5,12 +5,14 @@ import React from 'react';
5
5
  * @param text the text to process
6
6
  * @param [opts] options to customize behavior
7
7
  * @param [opts.newTab] if true, links will open in a new tab
8
- * @param [opts.preventPropagation] if true, clicks to link will prevent default
9
- * and propagation
8
+ * @param [opts.preventPropagation] if true, clicks to link will prevent
9
+ * propagation
10
+ * @param [opts.inheritColor] if true, inherit text color for links
10
11
  * @returns the processed text
11
12
  */
12
13
  declare const makeLinksClickable: (text: string, opts?: {
13
14
  newTab?: boolean;
14
15
  preventPropagation?: boolean;
16
+ inheritColor?: boolean;
15
17
  }) => React.ReactNode;
16
18
  export default makeLinksClickable;
package/dist/index.d.ts CHANGED
@@ -26,7 +26,6 @@ declare enum Variant {
26
26
 
27
27
  type Props$k = {
28
28
  children: React.ReactNode;
29
- dark?: boolean;
30
29
  };
31
30
  /**
32
31
  * Redirect to a new page
@@ -707,6 +706,7 @@ type SendRequestFunction = (opts: {
707
706
  declare const initClient: (opts: {
708
707
  sendRequest: SendRequestFunction;
709
708
  sessionExpiredMessage?: string;
709
+ darkModeOn?: boolean;
710
710
  }) => void;
711
711
 
712
712
  /**
@@ -1379,13 +1379,15 @@ declare const idify: (str: string) => string;
1379
1379
  * @param text the text to process
1380
1380
  * @param [opts] options to customize behavior
1381
1381
  * @param [opts.newTab] if true, links will open in a new tab
1382
- * @param [opts.preventPropagation] if true, clicks to link will prevent default
1383
- * and propagation
1382
+ * @param [opts.preventPropagation] if true, clicks to link will prevent
1383
+ * propagation
1384
+ * @param [opts.inheritColor] if true, inherit text color for links
1384
1385
  * @returns the processed text
1385
1386
  */
1386
1387
  declare const makeLinksClickable: (text: string, opts?: {
1387
1388
  newTab?: boolean;
1388
1389
  preventPropagation?: boolean;
1390
+ inheritColor?: boolean;
1389
1391
  }) => React.ReactNode;
1390
1392
 
1391
1393
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.5.13",
3
+ "version": "3.6.1",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,4 +1,6 @@
1
1
  // Import other components
2
+ // TODO: fix dependency cycle
3
+ // eslint-disable-next-line import/no-cycle
2
4
  import { showFatalError } from '../components/AppWrapper';
3
5
 
4
6
  // Import shared types
@@ -6,7 +8,6 @@ import ErrorWithCode from '../errors/ErrorWithCode';
6
8
  import waitMs from '../helpers/waitMs';
7
9
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
8
10
 
9
-
10
11
  /*----------------------------------------*/
11
12
  /* ---------------- Types --------------- */
12
13
  /*----------------------------------------*/
@@ -42,7 +43,7 @@ type SendRequestFunction = (
42
43
  /* ----------- Initialized ---------- */
43
44
 
44
45
  let onInitialized: (a: unknown) => void;
45
- let initialized = new Promise((resolve) => {
46
+ const initialized = new Promise((resolve) => {
46
47
  onInitialized = resolve;
47
48
  });
48
49
 
@@ -60,7 +61,7 @@ export const getSendRequest = async () => {
60
61
  let successful = false;
61
62
  (async () => {
62
63
  await waitMs(5000);
63
-
64
+
64
65
  if (!successful) {
65
66
  showFatalError(
66
67
  new ErrorWithCode(
@@ -69,7 +70,7 @@ export const getSendRequest = async () => {
69
70
  ),
70
71
  );
71
72
  }
72
- })(),
73
+ })();
73
74
 
74
75
  // Wait for initialization
75
76
  await initialized;
@@ -96,6 +97,18 @@ export const getSessionExpiredMessage = () => {
96
97
  );
97
98
  };
98
99
 
100
+ /* ------------ Dark Mode ----------- */
101
+
102
+ let darkModeOn = false;
103
+
104
+ /**
105
+ * Get whether dark mode is enabled or not
106
+ * @returns true if dark mode is enabled
107
+ */
108
+ export const isDarkModeOn = () => {
109
+ return darkModeOn;
110
+ };
111
+
99
112
  /*----------------------------------------*/
100
113
  /* ---------------- Init ---------------- */
101
114
  /*----------------------------------------*/
@@ -113,11 +126,14 @@ const initClient = (
113
126
  sendRequest: SendRequestFunction,
114
127
  // Custom session expired message
115
128
  sessionExpiredMessage?: string,
129
+ // If true, dark mode is enabled
130
+ darkModeOn?: boolean,
116
131
  },
117
132
  ) => {
118
133
  // Store values
119
134
  storedSendRequest = opts.sendRequest;
120
135
  sessionExpiredMessage = opts.sessionExpiredMessage;
136
+ darkModeOn = !!opts.darkModeOn;
121
137
 
122
138
  // Mark as initialized
123
139
  onInitialized(null);
@@ -18,15 +18,20 @@ import Variant from '../types/Variant';
18
18
  import LogBuiltInMetadata from '../types/LogBuiltInMetadata';
19
19
 
20
20
  // Import shared components
21
+ // TODO: fix dependency cycle
22
+ // eslint-disable-next-line import/no-cycle
21
23
  import Modal from './Modal';
22
24
 
23
25
  // Import custom errors
24
26
  import ErrorWithCode from '../errors/ErrorWithCode';
25
27
 
26
28
  // Import other helpers
29
+ // TODO: fix dependency cycle
30
+ // eslint-disable-next-line import/no-cycle
27
31
  import logClientEvent from '../helpers/logClientEvent';
28
32
  import {
29
33
  getSessionExpiredMessage,
34
+ isDarkModeOn,
30
35
  } from '../client/initClient';
31
36
 
32
37
  /*------------------------------------------------------------------------*/
@@ -36,8 +41,6 @@ import {
36
41
  type Props = {
37
42
  // The entire app
38
43
  children: React.ReactNode,
39
- // True if this app is a dark-themed app
40
- dark?: boolean,
41
44
  };
42
45
 
43
46
  /*------------------------------------------------------------------------*/
@@ -327,7 +330,6 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
327
330
 
328
331
  const {
329
332
  children,
330
- dark,
331
333
  } = props;
332
334
 
333
335
  /* -------------- State ------------- */
@@ -523,7 +525,7 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
523
525
  minHeight: '100vh',
524
526
  paddingTop: '2rem',
525
527
  backgroundColor: (
526
- dark
528
+ isDarkModeOn()
527
529
  ? '#222'
528
530
  : '#fff'
529
531
  ),
@@ -548,7 +550,7 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
548
550
  }
549
551
 
550
552
  /*----------------------------------------*/
551
- /* Main UI */
553
+ /* --------------- Main UI -------------- */
552
554
  /*----------------------------------------*/
553
555
 
554
556
  return (
@@ -563,7 +565,7 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
563
565
  };
564
566
 
565
567
  /*------------------------------------------------------------------------*/
566
- /* Wrap Up */
568
+ /* ------------------------------- Wrap Up ------------------------------ */
567
569
  /*------------------------------------------------------------------------*/
568
570
 
569
571
  // Export component
@@ -7,7 +7,7 @@
7
7
  import React from 'react';
8
8
 
9
9
  /*------------------------------------------------------------------------*/
10
- /* Types */
10
+ /* -------------------------------- Types ------------------------------- */
11
11
  /*------------------------------------------------------------------------*/
12
12
 
13
13
  // Props definition
@@ -25,12 +25,12 @@ type Props = {
25
25
  };
26
26
 
27
27
  /*------------------------------------------------------------------------*/
28
- /* Component */
28
+ /* ------------------------------ Component ----------------------------- */
29
29
  /*------------------------------------------------------------------------*/
30
30
 
31
31
  const ButtonInputGroup: React.FC<Props> = (props) => {
32
32
  /*------------------------------------------------------------------------*/
33
- /* Setup */
33
+ /* -------------------------------- Setup ------------------------------- */
34
34
  /*------------------------------------------------------------------------*/
35
35
 
36
36
  /* -------------- Props ------------- */
@@ -45,11 +45,11 @@ const ButtonInputGroup: React.FC<Props> = (props) => {
45
45
  } = props;
46
46
 
47
47
  /*------------------------------------------------------------------------*/
48
- /* Render */
48
+ /* ------------------------------- Render ------------------------------- */
49
49
  /*------------------------------------------------------------------------*/
50
50
 
51
51
  /*----------------------------------------*/
52
- /* Main UI */
52
+ /* --------------- Main UI -------------- */
53
53
  /*----------------------------------------*/
54
54
 
55
55
  return (
@@ -96,7 +96,7 @@ const ButtonInputGroup: React.FC<Props> = (props) => {
96
96
  };
97
97
 
98
98
  /*------------------------------------------------------------------------*/
99
- /* Wrap Up */
99
+ /* ------------------------------- Wrap Up ------------------------------ */
100
100
  /*------------------------------------------------------------------------*/
101
101
 
102
102
  // Export component
@@ -11,7 +11,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
11
11
  import { faCloudDownloadAlt } from '@fortawesome/free-solid-svg-icons';
12
12
 
13
13
  /*------------------------------------------------------------------------*/
14
- /* Types */
14
+ /* -------------------------------- Types ------------------------------- */
15
15
  /*------------------------------------------------------------------------*/
16
16
 
17
17
  // Props definition
@@ -35,12 +35,12 @@ type Props = {
35
35
  };
36
36
 
37
37
  /*------------------------------------------------------------------------*/
38
- /* Component */
38
+ /* ------------------------------ Component ----------------------------- */
39
39
  /*------------------------------------------------------------------------*/
40
40
 
41
41
  const CSVDownloadButton: React.FC<Props> = (props) => {
42
42
  /*------------------------------------------------------------------------*/
43
- /* Setup */
43
+ /* -------------------------------- Setup ------------------------------- */
44
44
  /*------------------------------------------------------------------------*/
45
45
 
46
46
  /* -------------- Props ------------- */
@@ -58,11 +58,11 @@ const CSVDownloadButton: React.FC<Props> = (props) => {
58
58
  } = props;
59
59
 
60
60
  /*------------------------------------------------------------------------*/
61
- /* Render */
61
+ /* ------------------------------- Render ------------------------------- */
62
62
  /*------------------------------------------------------------------------*/
63
63
 
64
64
  /*----------------------------------------*/
65
- /* Main UI */
65
+ /* --------------- Main UI -------------- */
66
66
  /*----------------------------------------*/
67
67
 
68
68
  // Render the button
@@ -95,7 +95,7 @@ const CSVDownloadButton: React.FC<Props> = (props) => {
95
95
  };
96
96
 
97
97
  /*------------------------------------------------------------------------*/
98
- /* Wrap Up */
98
+ /* ------------------------------- Wrap Up ------------------------------ */
99
99
  /*------------------------------------------------------------------------*/
100
100
 
101
101
  // Export component
@@ -14,8 +14,11 @@ import { faSquare, faSquareMinus } from '@fortawesome/free-regular-svg-icons';
14
14
  // Import shared types
15
15
  import Variant from '../types/Variant';
16
16
 
17
+ // Import shared helpers
18
+ import { isDarkModeOn } from '../client/initClient';
19
+
17
20
  /*------------------------------------------------------------------------*/
18
- /* Types */
21
+ /* -------------------------------- Types ------------------------------- */
19
22
  /*------------------------------------------------------------------------*/
20
23
 
21
24
  type Props = {
@@ -46,12 +49,12 @@ type Props = {
46
49
  };
47
50
 
48
51
  /*------------------------------------------------------------------------*/
49
- /* Component */
52
+ /* ------------------------------ Component ----------------------------- */
50
53
  /*------------------------------------------------------------------------*/
51
54
 
52
55
  const CheckboxButton: React.FC<Props> = (props) => {
53
56
  /*------------------------------------------------------------------------*/
54
- /* Setup */
57
+ /* -------------------------------- Setup ------------------------------- */
55
58
  /*------------------------------------------------------------------------*/
56
59
 
57
60
  /* -------------- Props ------------- */
@@ -65,18 +68,26 @@ const CheckboxButton: React.FC<Props> = (props) => {
65
68
  id,
66
69
  className,
67
70
  noMarginOnRight,
68
- checkedVariant = Variant.Secondary,
69
- uncheckedVariant = Variant.Light,
71
+ checkedVariant = (
72
+ isDarkModeOn()
73
+ ? Variant.Light
74
+ : Variant.Secondary
75
+ ),
76
+ uncheckedVariant = (
77
+ isDarkModeOn()
78
+ ? Variant.Secondary
79
+ : Variant.Light
80
+ ),
70
81
  small,
71
82
  dashed,
72
83
  } = props;
73
84
 
74
85
  /*------------------------------------------------------------------------*/
75
- /* Render */
86
+ /* ------------------------------- Render ------------------------------- */
76
87
  /*------------------------------------------------------------------------*/
77
88
 
78
89
  /*----------------------------------------*/
79
- /* Main UI */
90
+ /* --------------- Main UI -------------- */
80
91
  /*----------------------------------------*/
81
92
 
82
93
  // Determine the icon
@@ -113,7 +124,7 @@ const CheckboxButton: React.FC<Props> = (props) => {
113
124
  };
114
125
 
115
126
  /*------------------------------------------------------------------------*/
116
- /* Wrap up */
127
+ /* ------------------------------- Wrap Up ------------------------------ */
117
128
  /*------------------------------------------------------------------------*/
118
129
 
119
130
  export default CheckboxButton;
@@ -15,7 +15,7 @@ import { alert } from './AppWrapper';
15
15
  import waitMs from '../helpers/waitMs';
16
16
 
17
17
  /*------------------------------------------------------------------------*/
18
- /* Types */
18
+ /* -------------------------------- Types ------------------------------- */
19
19
  /*------------------------------------------------------------------------*/
20
20
 
21
21
  // Props definition
@@ -43,7 +43,7 @@ type Props = {
43
43
  };
44
44
 
45
45
  /*------------------------------------------------------------------------*/
46
- /* State */
46
+ /* -------------------------------- State ------------------------------- */
47
47
  /*------------------------------------------------------------------------*/
48
48
 
49
49
  /* -------- State Definition -------- */
@@ -97,12 +97,12 @@ const reducer = (state: State, action: Action): State => {
97
97
  };
98
98
 
99
99
  /*------------------------------------------------------------------------*/
100
- /* Component */
100
+ /* ------------------------------ Component ----------------------------- */
101
101
  /*------------------------------------------------------------------------*/
102
102
 
103
103
  const CopiableBox: React.FC<Props> = (props) => {
104
104
  /*------------------------------------------------------------------------*/
105
- /* Setup */
105
+ /* -------------------------------- Setup ------------------------------- */
106
106
  /*------------------------------------------------------------------------*/
107
107
 
108
108
  /* -------------- Props ------------- */
@@ -137,7 +137,7 @@ const CopiableBox: React.FC<Props> = (props) => {
137
137
  } = state;
138
138
 
139
139
  /*------------------------------------------------------------------------*/
140
- /* Component Functions */
140
+ /* ------------------------- Component Functions ------------------------ */
141
141
  /*------------------------------------------------------------------------*/
142
142
 
143
143
  /**
@@ -170,11 +170,11 @@ const CopiableBox: React.FC<Props> = (props) => {
170
170
  };
171
171
 
172
172
  /*------------------------------------------------------------------------*/
173
- /* Render */
173
+ /* ------------------------------- Render ------------------------------- */
174
174
  /*------------------------------------------------------------------------*/
175
175
 
176
176
  /*----------------------------------------*/
177
- /* Main UI */
177
+ /* --------------- Main UI -------------- */
178
178
  /*----------------------------------------*/
179
179
 
180
180
  return (
@@ -292,7 +292,7 @@ const CopiableBox: React.FC<Props> = (props) => {
292
292
  };
293
293
 
294
294
  /*------------------------------------------------------------------------*/
295
- /* Wrap Up */
295
+ /* ------------------------------- Wrap Up ------------------------------ */
296
296
  /*------------------------------------------------------------------------*/
297
297
 
298
298
  // Export component
@@ -7,7 +7,7 @@
7
7
  import React from 'react';
8
8
 
9
9
  /*------------------------------------------------------------------------*/
10
- /* Types */
10
+ /* -------------------------------- Types ------------------------------- */
11
11
  /*------------------------------------------------------------------------*/
12
12
 
13
13
  // Props definition
@@ -19,7 +19,7 @@ type Props = {
19
19
  };
20
20
 
21
21
  /*------------------------------------------------------------------------*/
22
- /* Style */
22
+ /* -------------------------------- Style ------------------------------- */
23
23
  /*------------------------------------------------------------------------*/
24
24
 
25
25
  const style = `
@@ -39,12 +39,12 @@ const style = `
39
39
  `;
40
40
 
41
41
  /*------------------------------------------------------------------------*/
42
- /* Component */
42
+ /* ------------------------------ Component ----------------------------- */
43
43
  /*------------------------------------------------------------------------*/
44
44
 
45
45
  const Drawer: React.FC<Props> = (props) => {
46
46
  /*------------------------------------------------------------------------*/
47
- /* Setup */
47
+ /* -------------------------------- Setup ------------------------------- */
48
48
  /*------------------------------------------------------------------------*/
49
49
 
50
50
  /* -------------- Props ------------- */
@@ -56,11 +56,11 @@ const Drawer: React.FC<Props> = (props) => {
56
56
  } = props;
57
57
 
58
58
  /*------------------------------------------------------------------------*/
59
- /* Render */
59
+ /* ------------------------------- Render ------------------------------- */
60
60
  /*------------------------------------------------------------------------*/
61
61
 
62
62
  /*----------------------------------------*/
63
- /* Main UI */
63
+ /* --------------- Main UI -------------- */
64
64
  /*----------------------------------------*/
65
65
 
66
66
  return (
@@ -77,7 +77,7 @@ const Drawer: React.FC<Props> = (props) => {
77
77
  };
78
78
 
79
79
  /*------------------------------------------------------------------------*/
80
- /* Wrap Up */
80
+ /* ------------------------------- Wrap Up ------------------------------ */
81
81
  /*------------------------------------------------------------------------*/
82
82
 
83
83
  // Export component
@@ -14,7 +14,7 @@ import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
14
14
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
15
15
 
16
16
  /*------------------------------------------------------------------------*/
17
- /* Types */
17
+ /* -------------------------------- Types ------------------------------- */
18
18
  /*------------------------------------------------------------------------*/
19
19
 
20
20
  type Props = {
@@ -27,12 +27,12 @@ type Props = {
27
27
  };
28
28
 
29
29
  /*------------------------------------------------------------------------*/
30
- /* Component */
30
+ /* ------------------------------ Component ----------------------------- */
31
31
  /*------------------------------------------------------------------------*/
32
32
 
33
33
  const ErrorBox: React.FC<Props> = (props) => {
34
34
  /*------------------------------------------------------------------------*/
35
- /* Setup */
35
+ /* -------------------------------- Setup ------------------------------- */
36
36
  /*------------------------------------------------------------------------*/
37
37
 
38
38
  /* -------------- Props ------------- */
@@ -44,7 +44,7 @@ const ErrorBox: React.FC<Props> = (props) => {
44
44
  } = props;
45
45
 
46
46
  /*------------------------------------------------------------------------*/
47
- /* Render */
47
+ /* ------------------------------- Render ------------------------------- */
48
48
  /*------------------------------------------------------------------------*/
49
49
 
50
50
  // Determine error text
@@ -117,7 +117,7 @@ const ErrorBox: React.FC<Props> = (props) => {
117
117
  };
118
118
 
119
119
  /*------------------------------------------------------------------------*/
120
- /* Wrap Up */
120
+ /* ------------------------------- Wrap Up ------------------------------ */
121
121
  /*------------------------------------------------------------------------*/
122
122
 
123
123
  // Export component