@adcops/autocore-react 3.0.0

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 (136) hide show
  1. package/LICENSE +59 -0
  2. package/additional-docs/ButtonApiSpecs.md +48 -0
  3. package/additional-docs/GlobalEventEmitter.md +244 -0
  4. package/additional-docs/general_recommendations.md +22 -0
  5. package/dist/components/DPad.css +522 -0
  6. package/dist/components/DPad.d.ts +34 -0
  7. package/dist/components/DPad.js +1 -0
  8. package/dist/components/Indicator.d.ts +81 -0
  9. package/dist/components/Indicator.js +1 -0
  10. package/dist/components/IndicatorButton.d.ts +137 -0
  11. package/dist/components/IndicatorButton.js +1 -0
  12. package/dist/components/IndicatorColor.d.ts +26 -0
  13. package/dist/components/IndicatorColor.js +1 -0
  14. package/dist/components/Osk.d.ts +14 -0
  15. package/dist/components/Osk.js +1 -0
  16. package/dist/components/OskDialog.d.ts +33 -0
  17. package/dist/components/OskDialog.js +1 -0
  18. package/dist/components/ValueDisplay.d.ts +99 -0
  19. package/dist/components/ValueDisplay.js +1 -0
  20. package/dist/components/osk.css +123 -0
  21. package/dist/core/EventEmitterContext.d.ts +223 -0
  22. package/dist/core/EventEmitterContext.js +1 -0
  23. package/dist/core/MaskPatterns.d.ts +71 -0
  24. package/dist/core/MaskPatterns.js +1 -0
  25. package/dist/core/NumerableTypes.d.ts +58 -0
  26. package/dist/core/NumerableTypes.js +1 -0
  27. package/dist/core/PositionContext.d.ts +38 -0
  28. package/dist/core/PositionContext.js +1 -0
  29. package/dist/core/UniqueId.d.ts +16 -0
  30. package/dist/core/UniqueId.js +1 -0
  31. package/dist/core/ValueSimulator.d.ts +71 -0
  32. package/dist/core/ValueSimulator.js +1 -0
  33. package/dist/core/hoc.d.ts +31 -0
  34. package/dist/core/hoc.js +1 -0
  35. package/dist/hub/HubBase.d.ts +169 -0
  36. package/dist/hub/HubBase.js +1 -0
  37. package/dist/hub/HubSimulate.d.ts +20 -0
  38. package/dist/hub/HubSimulate.js +1 -0
  39. package/dist/hub/HubSocketIo.d.ts +101 -0
  40. package/dist/hub/HubSocketIo.js +1 -0
  41. package/dist/hub/HubTauri.d.ts +86 -0
  42. package/dist/hub/HubTauri.js +1 -0
  43. package/dist/hub/index.d.ts +13 -0
  44. package/dist/hub/index.js +1 -0
  45. package/docs/.nojekyll +1 -0
  46. package/docs/assets/highlight.css +106 -0
  47. package/docs/assets/icons.js +15 -0
  48. package/docs/assets/icons.svg +1 -0
  49. package/docs/assets/main.js +59 -0
  50. package/docs/assets/navigation.js +1 -0
  51. package/docs/assets/search.js +1 -0
  52. package/docs/assets/style.css +1414 -0
  53. package/docs/classes/components_Indicator.Indicator.html +105 -0
  54. package/docs/classes/components_IndicatorButton.IndicatorButton.html +119 -0
  55. package/docs/classes/components_OskDialog.OskDialog.html +117 -0
  56. package/docs/classes/components_ValueDisplay.ValueDisplay.html +104 -0
  57. package/docs/classes/core_ValueSimulator.ValueSimulator.html +41 -0
  58. package/docs/classes/hub_HubBase.HubBase.html +67 -0
  59. package/docs/classes/hub_HubSimulate.HubSimulate.html +72 -0
  60. package/docs/classes/hub_HubSocketIo.HubSocketIo.html +80 -0
  61. package/docs/classes/hub_HubTauri.HubTauri.html +80 -0
  62. package/docs/enums/components_DPad.VcJoyPadAction.html +10 -0
  63. package/docs/enums/components_DPad.VcJoyPadButtonId.html +7 -0
  64. package/docs/enums/components_IndicatorButton.ActionMode.html +6 -0
  65. package/docs/enums/components_IndicatorColor.IndicatorColor.html +13 -0
  66. package/docs/functions/components_DPad.VcDPad.html +5 -0
  67. package/docs/functions/components_Osk.Osk.html +5 -0
  68. package/docs/functions/core_EventEmitterContext.EventEmitterProvider.html +8 -0
  69. package/docs/functions/core_UniqueId.UniqueId.html +4 -0
  70. package/docs/functions/core_hoc.hocAddSubscription.html +6 -0
  71. package/docs/functions/hub.createHub.html +3 -0
  72. package/docs/hierarchy.html +1 -0
  73. package/docs/index.html +69 -0
  74. package/docs/interfaces/components_IndicatorButton.IndicatorButtonProps.html +635 -0
  75. package/docs/interfaces/components_IndicatorButton.IndicatorButtonState.html +10 -0
  76. package/docs/interfaces/core_DimensionsContext.IDimensionsContext.html +4 -0
  77. package/docs/interfaces/core_EventEmitterContext.Action.html +5 -0
  78. package/docs/interfaces/core_EventEmitterContext.EventEmitterContextType.html +18 -0
  79. package/docs/interfaces/core_EventEmitterContext.State.html +8 -0
  80. package/docs/interfaces/core_EventEmitterContext.Subscription.html +6 -0
  81. package/docs/modules/components_DPad.html +5 -0
  82. package/docs/modules/components_Indicator.html +4 -0
  83. package/docs/modules/components_IndicatorButton.html +7 -0
  84. package/docs/modules/components_IndicatorColor.html +2 -0
  85. package/docs/modules/components_Osk.html +3 -0
  86. package/docs/modules/components_OskDialog.html +3 -0
  87. package/docs/modules/components_ValueDisplay.html +3 -0
  88. package/docs/modules/core_DimensionsContext.html +4 -0
  89. package/docs/modules/core_EventEmitterContext.html +11 -0
  90. package/docs/modules/core_InputPatterns.html +2 -0
  91. package/docs/modules/core_NumerableTypes.html +2 -0
  92. package/docs/modules/core_UniqueId.html +2 -0
  93. package/docs/modules/core_ValueSimulator.html +3 -0
  94. package/docs/modules/core_hoc.html +3 -0
  95. package/docs/modules/hub.html +6 -0
  96. package/docs/modules/hub_HubBase.html +3 -0
  97. package/docs/modules/hub_HubSimulate.html +3 -0
  98. package/docs/modules/hub_HubSocketIo.html +3 -0
  99. package/docs/modules/hub_HubTauri.html +2 -0
  100. package/docs/types/core_EventEmitterContext.EmitterDispatchFunction.html +1 -0
  101. package/docs/types/core_EventEmitterContext.EmitterSubscribeFunction.html +1 -0
  102. package/docs/types/core_EventEmitterContext.EmitterUnsubscribeFunction.html +1 -0
  103. package/docs/types/core_NumerableTypes.NumerableFormatOptions.html +1 -0
  104. package/docs/types/core_hoc.HocAddSubscriptionProps.html +4 -0
  105. package/docs/variables/core_DimensionsContext.DimensionsContext.html +1 -0
  106. package/docs/variables/core_EventEmitterContext.EventEmitterContext.html +5 -0
  107. package/docs/variables/core_InputPatterns.InputPatterns.html +2 -0
  108. package/package.json +79 -0
  109. package/readme.md +140 -0
  110. package/src/components/DPad.css +522 -0
  111. package/src/components/DPad.tsx +94 -0
  112. package/src/components/Indicator.tsx +243 -0
  113. package/src/components/IndicatorButton.tsx +306 -0
  114. package/src/components/IndicatorColor.ts +36 -0
  115. package/src/components/Osk.tsx +193 -0
  116. package/src/components/OskDialog.tsx +165 -0
  117. package/src/components/ValueDisplay.tsx +181 -0
  118. package/src/components/osk.css +123 -0
  119. package/src/core/EventEmitterContext.tsx +394 -0
  120. package/src/core/MaskPatterns.ts +82 -0
  121. package/src/core/NumerableTypes.ts +81 -0
  122. package/src/core/PositionContext.ts +60 -0
  123. package/src/core/UniqueId.ts +41 -0
  124. package/src/core/ValueSimulator.ts +167 -0
  125. package/src/core/hoc.tsx +65 -0
  126. package/src/hub/HubBase.ts +293 -0
  127. package/src/hub/HubSimulate.ts +47 -0
  128. package/src/hub/HubSocketIo.ts +166 -0
  129. package/src/hub/HubTauri.ts +145 -0
  130. package/src/hub/index.ts +41 -0
  131. package/terser.config.cjs +25 -0
  132. package/todo.md +18 -0
  133. package/tools/copy-distribution-files.cjs +73 -0
  134. package/tools/minify.cjs +56 -0
  135. package/tsconfig.json +34 -0
  136. package/typedoc.json +13 -0
@@ -0,0 +1,243 @@
1
+ /*
2
+ * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
+ * Created Date: 2024-01-16 14:39:41
4
+ * -----
5
+ * Last Modified: 2024-03-08 07:48:42
6
+ * -----
7
+ *
8
+ */
9
+
10
+
11
+
12
+ // import { useContext } from 'react';
13
+ // import clsx from 'clsx';
14
+
15
+ // import DimensionsContext from '../core/DimensionsContext';
16
+
17
+
18
+
19
+ // /**
20
+ // * Displays boolean values<br/>
21
+ // * Supports 3 states: **on**, **off** and **invalid/not available**:
22
+ // */
23
+ // const Indicator = ({
24
+ // value: value,
25
+ // x,
26
+ // y,
27
+ // width = 22,
28
+ // height = width,
29
+ // className,
30
+ // onColor: onColor = IndicatorGreen,
31
+ // offColor: offColor = IndicatorOff,
32
+ // invalidColor: invalidColor = IndicatorInvalid,
33
+ // useAbsolutePositioning = false, // Default to false
34
+ // }: Props): JSX.Element => {
35
+ // const { scale, xOffset, yOffset } = useContext(DimensionsContext);
36
+
37
+ // let color;
38
+ // switch (value) {
39
+ // case true:
40
+ // color = onColor;
41
+ // break;
42
+ // case false:
43
+ // color = offColor;
44
+ // break;
45
+ // default:
46
+ // color = invalidColor;
47
+ // break;
48
+ // }
49
+
50
+ // return (
51
+ // <div
52
+ // className={clsx(className)}
53
+ // style={{
54
+ // position: useAbsolutePositioning ? 'absolute' : 'relative',
55
+ // display: useAbsolutePositioning ? "": "inline-block",
56
+ // verticalAlign: 'middle',
57
+ // top: useAbsolutePositioning && y ? `${yOffset + scale * y}px` : undefined,
58
+ // left: useAbsolutePositioning && x? `${xOffset + scale * x}px` : undefined,
59
+ // width: width ? `${width * scale}px` : undefined,
60
+ // height: height ? `${height * scale}px` : undefined,
61
+ // lineHeight: height ? `${height * scale}px` : undefined,
62
+ // backgroundColor: color,
63
+ // borderRadius: "20px"
64
+ // }}
65
+ // />
66
+ // );
67
+ // };
68
+
69
+ // export { Indicator };
70
+
71
+
72
+
73
+
74
+ import React, { Component } from 'react';
75
+ import clsx from 'clsx';
76
+ import { EventEmitterContext, EventEmitterContextType } from '../core/EventEmitterContext';
77
+ import { IPositionContext } from '../core/PositionContext';
78
+ import {IndicatorColor} from "./IndicatorColor";
79
+ export {IndicatorColor}
80
+
81
+
82
+
83
+
84
+ interface IndicatorProps {
85
+ /**
86
+ * State to be displayed<br/>
87
+ *
88
+ * Available states: **on**, **off** and **not available**:
89
+ *
90
+ * * `true` is treated as **on**
91
+ * * `false` is treated as **off**
92
+ * * `undefined` is treated as **not available**
93
+ */
94
+ value?: boolean | undefined;
95
+ /**
96
+ * X position (in pixels)
97
+ */
98
+ x?: number;
99
+ /**
100
+ * Y position (in pixels)
101
+ */
102
+ y?: number;
103
+ /**
104
+ * Width (in pixels)
105
+ */
106
+ width?: number;
107
+ /**
108
+ * Height (in pixels)<br/>
109
+ * @default width
110
+ */
111
+ height?: number;
112
+ /**
113
+ * CSS color for **enabled** state
114
+ */
115
+ onColor?: string;
116
+ /**
117
+ * CSS color for **disabled** state
118
+ */
119
+ offColor?: string;
120
+ /**
121
+ * CSS color for **not available** state
122
+ */
123
+ invalidColor?: string;
124
+ /**
125
+ * Custom class name to be attached
126
+ */
127
+ className?: string;
128
+
129
+
130
+ /**
131
+ * Enable absolute positioning for the component, allowing it to be
132
+ * placed on a specific position of its parent. This is useful when
133
+ * laying components over an image or wireframe.
134
+ */
135
+ useAbsolutePositioning?: boolean;
136
+
137
+ /**
138
+ * The topic to monitor to display. Optional.
139
+ */
140
+ topic?: string;
141
+ }
142
+
143
+
144
+ interface IndicatorState {
145
+ subscribedValue?: boolean | null;
146
+ fontSize?: string;
147
+ }
148
+
149
+
150
+ export class Indicator extends Component<IndicatorProps, IndicatorState> {
151
+ static contextType = EventEmitterContext;
152
+ protected unsubscribeTopicId: number | null = null;
153
+
154
+ // Define default properties
155
+ static defaultProps = {
156
+ width: 22,
157
+ height: 22,
158
+ onColor: "green",
159
+ offColor: "gray",
160
+ invalidColor: "yellow",
161
+ useAbsolutePositioning: false
162
+ };
163
+
164
+ constructor(props: IndicatorProps) {
165
+ super(props);
166
+ this.state = {
167
+ subscribedValue: props.value,
168
+ fontSize: "100%"
169
+ };
170
+ }
171
+
172
+ componentDidMount() {
173
+ const { topic } = this.props;
174
+ if (topic && this.unsubscribeTopicId === null) {
175
+ const { subscribe } = this.context as EventEmitterContextType;
176
+ this.unsubscribeTopicId = subscribe(topic, (value: any) => {
177
+ this.setState({ subscribedValue: value });
178
+ });
179
+ }
180
+ }
181
+
182
+ componentDidUpdate(prevProps: IndicatorProps) {
183
+ if (prevProps.value !== this.props.value) {
184
+ this.setState({ subscribedValue: this.props.value });
185
+ }
186
+ }
187
+
188
+ componentWillUnmount() {
189
+ if (this.unsubscribeTopicId !== null) {
190
+ const { unsubscribe } = this.context as EventEmitterContextType;
191
+ unsubscribe(this.unsubscribeTopicId);
192
+ this.unsubscribeTopicId = null;
193
+ }
194
+ }
195
+
196
+ render() {
197
+ const { x, y, width, height, className, onColor, offColor, invalidColor, useAbsolutePositioning } = this.props;
198
+ const { scale, xOffset, yOffset } = this.context as IPositionContext;
199
+ const { subscribedValue } = this.state;
200
+
201
+ let adjWidth = width || 10;
202
+ if (adjWidth < 10)
203
+ adjWidth = 10;
204
+ let adjHeight = height || 10;
205
+ if (adjHeight < 10)
206
+ adjHeight = 10;
207
+ let adjScale = scale || 1;
208
+ if (adjScale === 0)
209
+ adjScale = 1;
210
+
211
+ let color;
212
+ switch (subscribedValue) {
213
+ case true:
214
+ color = onColor;
215
+ break;
216
+ case false:
217
+ color = offColor;
218
+ break;
219
+ default:
220
+ color = invalidColor;
221
+ break;
222
+ }
223
+
224
+ const style: React.CSSProperties = {
225
+ position: useAbsolutePositioning ? 'absolute' : 'relative',
226
+ display: useAbsolutePositioning ? "" : "inline-block",
227
+ verticalAlign: 'middle',
228
+ top: useAbsolutePositioning && y ? `${yOffset + adjScale * y}px` : undefined,
229
+ left: useAbsolutePositioning && x ? `${xOffset + adjScale * x}px` : undefined,
230
+ width: adjWidth ? `${adjWidth * adjScale}px` : undefined,
231
+ height: adjHeight ? `${adjHeight * adjScale}px` : undefined,
232
+ lineHeight: adjHeight ? `${adjHeight * adjScale}px` : undefined,
233
+ backgroundColor: color,
234
+ borderRadius: "20px"
235
+ };
236
+
237
+ return (
238
+ <div className={clsx(className)} style={style} />
239
+ );
240
+ }
241
+ }
242
+
243
+ export default Indicator;
@@ -0,0 +1,306 @@
1
+ /*
2
+ * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
+ * Created Date: 2024-01-21 10:33:58
4
+ * -----
5
+ * Last Modified: 2024-03-08 07:17:08
6
+ * Modified By: ADC
7
+ * -----
8
+ *
9
+ */
10
+
11
+
12
+ import { Component } from 'react';
13
+ import { Button, ButtonProps} from 'primereact/button';
14
+ import { EventEmitterContext, EventEmitterContextType } from '../core/EventEmitterContext';
15
+ import {IndicatorColor} from "./IndicatorColor";
16
+ export {IndicatorColor}
17
+
18
+ /**
19
+ * Enum for different input modes of the IndicatorButton.
20
+ */
21
+ export enum ActionMode {
22
+ Tap = 'Tap',
23
+ Toggle = 'Toggle',
24
+ Pressed = 'Pressed',
25
+ Released = 'Released'
26
+ }
27
+
28
+ /**
29
+ * Properties for the IndicatorButton.
30
+ *
31
+ * For more information on the AutoCore Button API Specification, see
32
+ * [Additional Documentation](../additional-docs/ButtonApiSpecs.md).
33
+ */
34
+ export interface IndicatorButtonProps extends ButtonProps {
35
+ /**
36
+ * Topic name to monitor for state indication.
37
+ */
38
+ topic?: string;
39
+
40
+ /**
41
+ * Color for the button when the state is TRUE.
42
+ */
43
+ onColor?: IndicatorColor;
44
+
45
+ /**
46
+ * Color for the button when the state is FALSE.
47
+ */
48
+ offColor?: IndicatorColor;
49
+
50
+ /**
51
+ * Text displayed when the state is TRUE. Falls back to `label` if undefined.
52
+ */
53
+ onLabel?: string;
54
+
55
+ /**
56
+ * Text displayed when the state is FALSE. Falls back to `label` if undefined.
57
+ */
58
+ offLabel?: string;
59
+
60
+ /**
61
+ * Name of the command to invoke on button events.
62
+ * If command is "*", then the commandTopic will be dispatched
63
+ * internally.
64
+ */
65
+ command?: string;
66
+
67
+ /**
68
+ * Optional topic parameter to send along with the command.
69
+ * If set, will automatically be included with commandArgs as
70
+ * the value of field 'topic.'
71
+ */
72
+ commandTopic? : string;
73
+
74
+ /**
75
+ * Optional arguments sent with the command.
76
+ */
77
+ commandArgs?: any;
78
+
79
+ /**
80
+ * Topic to disable button interaction.
81
+ */
82
+ disableTopic?: string;
83
+
84
+ /**
85
+ * Topic to control the visibility of the button.
86
+ */
87
+ invisibleTopic?: string;
88
+
89
+ /**
90
+ * Mode of input for the button (e.g., TAP, TOGGLE).
91
+ */
92
+ actionMode?: ActionMode;
93
+
94
+ /**
95
+ * Inverts the signal values for TAP, PRESSED, and RELEASED modes.
96
+ */
97
+ invert?: boolean;
98
+ }
99
+
100
+ /**
101
+ * State for the IndicatorButton.
102
+ */
103
+ export interface IndicatorButtonState {
104
+ /**
105
+ * Current value/state of the button based on the subscribed topic.
106
+ */
107
+ currentValue?: boolean;
108
+
109
+ /**
110
+ * Indicates whether the button is disabled.
111
+ */
112
+ isDisabled?: boolean;
113
+
114
+ /**
115
+ * Indicates whether the button is invisible.
116
+ */
117
+ isInvisible?: boolean;
118
+
119
+ /**
120
+ * The button is in the "down" state.
121
+ */
122
+ isPressed : boolean;
123
+ }
124
+
125
+
126
+
127
+
128
+ export class IndicatorButton extends Component<IndicatorButtonProps, IndicatorButtonState> {
129
+ static contextType = EventEmitterContext;
130
+
131
+ // Define default props
132
+ static defaultProps = {
133
+ onColor: IndicatorColor.IndicatorGreen,
134
+ offColor: "gray", // Default offColor
135
+ // ... other default values for props ...
136
+ };
137
+
138
+ constructor(props: IndicatorButtonProps) {
139
+ super(props);
140
+ this.state = {
141
+ currentValue: undefined,
142
+ isDisabled: false,
143
+ isInvisible: false,
144
+ isPressed: false
145
+ };
146
+ }
147
+
148
+ componentDidMount() {
149
+ this.setupSubscriptions();
150
+ }
151
+
152
+ componentDidUpdate(prevProps: IndicatorButtonProps) {
153
+ prevProps;
154
+ // Logic to handle updates in props, if necessary
155
+ }
156
+
157
+ componentWillUnmount() {
158
+ // Unsubscribe logic if needed
159
+ }
160
+
161
+ /**
162
+ * Sets up subscriptions based on provided topics.
163
+ */
164
+ private setupSubscriptions() {
165
+ const { topic, disableTopic, invisibleTopic } = this.props;
166
+ const { subscribe } = this.context as EventEmitterContextType;
167
+
168
+ if (topic) {
169
+ // Subscribe to the main topic
170
+ subscribe(topic, this.handleTopicUpdate);
171
+ }
172
+
173
+ if (disableTopic) {
174
+ // Subscribe to the disable topic
175
+ subscribe(disableTopic, this.handleDisableTopicUpdate);
176
+ }
177
+
178
+ if (invisibleTopic) {
179
+ // Subscribe to the invisible topic
180
+ subscribe(invisibleTopic, this.handleInvisibleTopicUpdate);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Handles updates for the main topic.
186
+ */
187
+ private handleTopicUpdate = (value: boolean) => {
188
+ this.setState({ currentValue: value });
189
+ };
190
+
191
+ /**
192
+ * Handles updates for the disable topic.
193
+ */
194
+ private handleDisableTopicUpdate = (value: boolean) => {
195
+ this.setState({ isDisabled: value });
196
+ };
197
+
198
+ /**
199
+ * Handles updates for the invisible topic.
200
+ */
201
+ private handleInvisibleTopicUpdate = (value: boolean) => {
202
+ this.setState({ isInvisible: value });
203
+ };
204
+
205
+ /**
206
+ * Handle the button being pressed down. Used for TAP and PRESSED action modes.
207
+ */
208
+ protected handleOnPressed() {
209
+ const { isPressed } = this.state;
210
+ const {actionMode} = this.props;
211
+
212
+ if (!isPressed) {
213
+ this.setState({isPressed: true});
214
+
215
+ if (actionMode === ActionMode.Tap || actionMode === ActionMode.Pressed) {
216
+ this.dispatchCommand(true);
217
+ }
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Handle the button being released. Used for TAP and RELEASED action modes.
223
+ */
224
+ protected handleOnReleased() {
225
+ const { isPressed } = this.state;
226
+ const {actionMode} = this.props;
227
+
228
+ if (isPressed) {
229
+ this.setState({isPressed: false});
230
+
231
+ if (actionMode === ActionMode.Tap ) {
232
+ this.dispatchCommand(false);
233
+ }
234
+ else if (actionMode === ActionMode.Released) {
235
+ this.dispatchCommand(true);
236
+ }
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Dispatch a value to any listeners.
242
+ * @param value The value to dispatch as part of the payload.
243
+ */
244
+ protected dispatchCommand(value : any) {
245
+
246
+ const {command, commandTopic, commandArgs} = this.props;
247
+ const { dispatch } = this.context as EventEmitterContextType;
248
+
249
+ if (command !== undefined && command !== null && command.length > 0 )
250
+ {
251
+ const payload = {
252
+ topic: commandTopic,
253
+ value: value,
254
+ ...commandArgs
255
+ };
256
+
257
+ dispatch({
258
+ topic: command,
259
+ payload: payload
260
+ });
261
+
262
+ }
263
+
264
+ }
265
+
266
+
267
+ render() {
268
+ const { currentValue, isDisabled, isInvisible } = this.state;
269
+ const { className, severity, label, raised,
270
+ onColor, offColor, onLabel, offLabel, topic, command,
271
+ commandArgs, disableTopic, invisibleTopic, inputMode, invert,
272
+ ...restProps
273
+ } = this.props;
274
+
275
+
276
+ // Determine the label and color based on the current state
277
+ let btnLabel = currentValue ? onLabel : offLabel;
278
+ if (btnLabel === undefined || btnLabel === null || btnLabel.length === 0)
279
+ btnLabel = label;
280
+
281
+ let color = currentValue ? onColor : offColor;
282
+
283
+ // Handle special cases like undefined state or specific input modes
284
+ if (currentValue === undefined) {
285
+ color = IndicatorColor.IndicatorInvalid;
286
+ }
287
+
288
+
289
+ return (
290
+ <Button {...restProps}
291
+ label={btnLabel}
292
+ className={className}
293
+ style={{ color: "white", backgroundColor: color, display: isInvisible ? 'none' : 'block' }}
294
+ disabled={isDisabled}
295
+ onMouseDown={() => this.handleOnPressed() }
296
+ onTouchStart={() => this.handleOnPressed() }
297
+ onMouseUp={() => this.handleOnReleased() }
298
+ onTouchEnd={() => this.handleOnReleased() }
299
+
300
+ raised
301
+ />
302
+ );
303
+ }
304
+ }
305
+
306
+ export default IndicatorButton;
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
+ * Created Date: 2024-01-21 11:45:09
4
+ * -----
5
+ * Last Modified: 2024-03-08 07:16:47
6
+ * Modified By: ADC
7
+ * -----
8
+ *
9
+ */
10
+
11
+ /**
12
+ * Standardized indicator colors and their meanings. It's probably
13
+ * best to use their meaning and not the actual color name.
14
+ */
15
+ export enum IndicatorColor {
16
+ /** Green: On, Ok, Ready, Home, General Use */
17
+ IndicatorGreen = "green",
18
+ /** Alias for the ON condition to make meaning clear. Preferred for ON case. */
19
+ IndicatorOn = IndicatorGreen,
20
+ /** Off. ONLY USE THIS FOR OFF. */
21
+ IndicatorOff = "gray",
22
+ /** Red: Error, Fault, Stop, Stopped. Use sparingly. */
23
+ IndicatorRed = "red",
24
+ /** Orange: Warning, Out of position, moving, out of range. */
25
+ IndicatorOrange = "orange",
26
+ /** Alias for Red to make meaning clear. Preferred. */
27
+ IndicatorError = IndicatorRed,
28
+ /** Alias for Orange to make meaning clear. Preferred. */
29
+ IndicatorWarning = IndicatorOrange,
30
+ /** Invalid. If an indicator is black, the interface does not know the current value. */
31
+ IndicatorInvalid = "black",
32
+ /** Use for navigation buttons. No other meaning allowed. */
33
+ IndicatorNavigation = "cyan",
34
+ /** Use for informational buttons. No other meaning allowed. */
35
+ IndicatorInfo = "blue"
36
+ }