dce-reactkit 3.5.4 → 3.5.5

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,102 @@
1
+ /**
2
+ * A toggle switch that toggles on or off
3
+ * @author Alessandra De Lucas
4
+ * @author Gabe Abrams
5
+ */
6
+
7
+ // Import React
8
+ import React from 'react';
9
+
10
+ // Import FontAwesome
11
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
12
+ import { faCircle } from '@fortawesome/free-solid-svg-icons';
13
+
14
+ // Import shared types
15
+ import Variant from '../types/Variant';
16
+
17
+ /*------------------------------------------------------------------------*/
18
+ /* -------------------------------- Types ------------------------------- */
19
+ /*------------------------------------------------------------------------*/
20
+
21
+ // Props definition
22
+ type Props = {
23
+ // If true, the toggle switch is in the on position
24
+ isOn: boolean,
25
+ /**
26
+ * A handler to call when the switch is toggled
27
+ * @param isOn Updated value for isOn
28
+ */
29
+ onToggle: (isOn: boolean) => void,
30
+ // Unique ID for the toggle switch
31
+ id?: string,
32
+ // A description for what it means when the toggle switch is on
33
+ // E.g. "airplane mode is active"
34
+ // Description will be placed into a sentence with the structure:
35
+ // `If on, ${description}. Currently on. Click to turn off.`
36
+ description: string,
37
+ // Custom background variant for the "on" state (defaults to Variant.Info)
38
+ backgroundVariantWhenOn?: Variant,
39
+ };
40
+
41
+ /*------------------------------------------------------------------------*/
42
+ /* ------------------------------ Component ----------------------------- */
43
+ /*------------------------------------------------------------------------*/
44
+
45
+ const ToggleSwitch: React.FC<Props> = (props) => {
46
+ /*------------------------------------------------------------------------*/
47
+ /* -------------------------------- Setup ------------------------------- */
48
+ /*------------------------------------------------------------------------*/
49
+
50
+ /* -------------- Props ------------- */
51
+
52
+ // Destructure all props
53
+ const {
54
+ isOn,
55
+ onToggle,
56
+ id,
57
+ description,
58
+ backgroundVariantWhenOn = Variant.Info,
59
+ } = props;
60
+
61
+ /*------------------------------------------------------------------------*/
62
+ /* ------------------------------- Render ------------------------------- */
63
+ /*------------------------------------------------------------------------*/
64
+
65
+ /*----------------------------------------*/
66
+ /* --------------- Main UI -------------- */
67
+ /*----------------------------------------*/
68
+
69
+ const backgroundVariant = (
70
+ isOn
71
+ ? backgroundVariantWhenOn
72
+ : 'secondary'
73
+ );
74
+
75
+ return (
76
+ <button
77
+ id={id}
78
+ aria-label={`If on, ${description}. Currently ${isOn ? 'on' : 'off'}. Click to turn ${isOn ? 'off' : 'on'}.`}
79
+ className={`alert alert-${backgroundVariant} bg-${backgroundVariant} mb-0 rounded-pill d-inline-block pt-0 pb-0 px-3`}
80
+ onClick={() => {
81
+ onToggle(!isOn);
82
+ }}
83
+ type="button"
84
+ >
85
+ <FontAwesomeIcon
86
+ icon={faCircle}
87
+ className="text-light"
88
+ style={{
89
+ transform: `translateX(${isOn ? '' : '-'}0.7rem)`,
90
+ transition: '0.3s transform ease-in-out',
91
+ }}
92
+ />
93
+ </button>
94
+ );
95
+ };
96
+
97
+ /*------------------------------------------------------------------------*/
98
+ /* ------------------------------- Wrap Up ------------------------------ */
99
+ /*------------------------------------------------------------------------*/
100
+
101
+ // Export component
102
+ export default ToggleSwitch;
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  // Import components
2
- import AppWrapper, { alert, confirm, showFatalError } from './components/AppWrapper';
2
+ import AppWrapper, {
3
+ alert,
4
+ confirm,
5
+ showFatalError,
6
+ addFatalErrorHandler,
7
+ } from './components/AppWrapper';
3
8
  import LoadingSpinner from './components/LoadingSpinner';
4
9
  import ErrorBox from './components/ErrorBox';
5
10
  import Modal from './components/Modal';
@@ -19,6 +24,7 @@ import IntelliTable from './components/IntelliTable';
19
24
  import CSVDownloadButton from './components/CSVDownloadButton';
20
25
  import DBEntryManagerPanel from './components/DBEntryManagerPanel';
21
26
  import Tooltip from './components/Tooltip';
27
+ import ToggleSwitch from './components/ToggleSwitch';
22
28
 
23
29
  // Import errors
24
30
  import ErrorWithCode from './errors/ErrorWithCode';
@@ -117,6 +123,7 @@ export {
117
123
  CSVDownloadButton,
118
124
  DBEntryManagerPanel,
119
125
  Tooltip,
126
+ ToggleSwitch,
120
127
  // Global functions
121
128
  alert,
122
129
  confirm,
@@ -164,6 +171,7 @@ export {
164
171
  initClient,
165
172
  visitServerEndpoint,
166
173
  logClientEvent,
174
+ addFatalErrorHandler,
167
175
  // Server helpers
168
176
  initServer,
169
177
  genRouteHandler,