@wandelbots/wandelbots-js-react-components 2.28.0 → 2.29.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wandelbots/wandelbots-js-react-components",
3
- "version": "2.28.0",
3
+ "version": "2.29.0",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -0,0 +1,217 @@
1
+ import { Pause, PlayArrow, Stop } from "@mui/icons-material"
2
+ import { Box, Button, Typography, useTheme } from "@mui/material"
3
+ import { observer } from "mobx-react-lite"
4
+ import { useTranslation } from "react-i18next"
5
+ import { externalizeComponent } from "../externalizeComponent"
6
+
7
+ export type ProgramState = "idle" | "running" | "paused" | "stopping"
8
+
9
+ export interface ProgramControlProps {
10
+ /** The current state of the program control */
11
+ state: ProgramState
12
+ /** Callback fired when the run/resume button is clicked */
13
+ onRun: () => void
14
+ /** Callback fired when the pause button is clicked (only available in 'with_pause' variant) */
15
+ onPause?: () => void
16
+ /** Callback fired when the stop button is clicked */
17
+ onStop: () => void
18
+ /**
19
+ * Function to reset the component from 'stopping' state back to 'idle'.
20
+ * This must be called manually by the user when requiresManualReset is true.
21
+ */
22
+ onReset?: () => void
23
+ /**
24
+ * When true, the component will stay in 'stopping' state until onReset is called manually.
25
+ * When false (default), auto-resets to 'idle' after 2 seconds.
26
+ */
27
+ requiresManualReset?: boolean
28
+ /**
29
+ * Variant of the component:
30
+ * - 'with_pause': Shows run/pause/stop buttons (default)
31
+ * - 'without_pause': Shows only run/stop buttons
32
+ */
33
+ variant?: "with_pause" | "without_pause"
34
+ /** Additional CSS class name */
35
+ className?: string
36
+ }
37
+
38
+ interface ButtonConfig {
39
+ enabled: boolean
40
+ label: string
41
+ color: string
42
+ onClick: () => void
43
+ }
44
+
45
+ /**
46
+ * A control component for program execution with run, pause, and stop functionality.
47
+ *
48
+ * Features:
49
+ * - State machine with idle, running, paused, and stopping states
50
+ * - Two variants: with_pause (3 buttons) and without_pause (2 buttons)
51
+ * - Optional manual reset functionality
52
+ * - Responsive design with 110px circular buttons
53
+ * - Material-UI theming integration
54
+ */
55
+ export const ProgramControl = externalizeComponent(
56
+ observer(
57
+ ({
58
+ state,
59
+ onRun,
60
+ onPause,
61
+ onStop,
62
+ onReset,
63
+ requiresManualReset = false,
64
+ variant = "with_pause",
65
+ className,
66
+ }: ProgramControlProps) => {
67
+ const theme = useTheme()
68
+ const { t } = useTranslation()
69
+
70
+ const getButtonConfigs = (): ButtonConfig[] => {
71
+ const baseConfigs: Record<string, ButtonConfig> = {
72
+ run: {
73
+ enabled: state === "idle" || state === "paused",
74
+ label:
75
+ state === "paused"
76
+ ? t("ProgramControl.Resume.bt")
77
+ : t("ProgramControl.Start.bt"),
78
+ color: theme.palette.success.main,
79
+ onClick: onRun,
80
+ },
81
+ pause: {
82
+ enabled: state === "running",
83
+ label: t("ProgramControl.Pause.bt"),
84
+ color: "#FFFFFF33",
85
+ onClick: onPause || (() => {}),
86
+ },
87
+ stop: {
88
+ enabled: state === "running" || state === "paused",
89
+ label: t("ProgramControl.Stop.bt"),
90
+ color: theme.palette.error.main,
91
+ onClick: onStop,
92
+ },
93
+ }
94
+
95
+ if (variant === "without_pause") {
96
+ return [baseConfigs.run, baseConfigs.stop]
97
+ }
98
+
99
+ return [baseConfigs.run, baseConfigs.pause, baseConfigs.stop]
100
+ }
101
+
102
+ const getButtonIcon = (index: number) => {
103
+ const iconProps = { sx: { fontSize: "55px" } }
104
+
105
+ if (variant === "without_pause") {
106
+ return index === 0 ? (
107
+ <PlayArrow {...iconProps} />
108
+ ) : (
109
+ <Stop {...iconProps} />
110
+ )
111
+ }
112
+
113
+ switch (index) {
114
+ case 0:
115
+ return <PlayArrow {...iconProps} />
116
+ case 1:
117
+ return <Pause {...iconProps} />
118
+ case 2:
119
+ return <Stop {...iconProps} />
120
+ default:
121
+ return null
122
+ }
123
+ }
124
+
125
+ const buttonConfigs = getButtonConfigs()
126
+
127
+ return (
128
+ <Box
129
+ className={className}
130
+ sx={{
131
+ display: "flex",
132
+ flexDirection: "column",
133
+ alignItems: "center",
134
+ gap: 2,
135
+ }}
136
+ >
137
+ <Box
138
+ sx={{
139
+ display: "flex",
140
+ gap: "40px",
141
+ flexWrap: "wrap",
142
+ justifyContent: "center",
143
+ alignItems: "center",
144
+ }}
145
+ >
146
+ {buttonConfigs.map((config, index) => (
147
+ <Box
148
+ key={config.label}
149
+ sx={{
150
+ display: "flex",
151
+ flexDirection: "column",
152
+ alignItems: "center",
153
+ gap: 1,
154
+ }}
155
+ >
156
+ <Button
157
+ variant="contained"
158
+ disabled={
159
+ !config.enabled ||
160
+ (state === "stopping" && !requiresManualReset)
161
+ }
162
+ onClick={config.onClick}
163
+ sx={{
164
+ width: "110px",
165
+ height: "110px",
166
+ borderRadius: "110px",
167
+ backgroundColor: config.color,
168
+ opacity:
169
+ config.enabled &&
170
+ !(state === "stopping" && !requiresManualReset)
171
+ ? 1
172
+ : 0.3,
173
+ "&:hover": {
174
+ backgroundColor: config.color,
175
+ opacity:
176
+ config.enabled &&
177
+ !(state === "stopping" && !requiresManualReset)
178
+ ? 0.8
179
+ : 0.3,
180
+ },
181
+ "&:disabled": {
182
+ backgroundColor: config.color,
183
+ opacity: 0.3,
184
+ },
185
+ minWidth: "110px",
186
+ flexShrink: 0,
187
+ }}
188
+ >
189
+ {getButtonIcon(index)}
190
+ </Button>
191
+
192
+ <Typography
193
+ variant="body1"
194
+ sx={{
195
+ color:
196
+ config.enabled &&
197
+ !(state === "stopping" && !requiresManualReset)
198
+ ? config.color
199
+ : theme.palette.text.disabled,
200
+ textAlign: "center",
201
+ opacity:
202
+ config.enabled &&
203
+ !(state === "stopping" && !requiresManualReset)
204
+ ? 1
205
+ : 0.3,
206
+ }}
207
+ >
208
+ {config.label}
209
+ </Typography>
210
+ </Box>
211
+ ))}
212
+ </Box>
213
+ </Box>
214
+ )
215
+ },
216
+ ),
217
+ )
@@ -43,5 +43,9 @@
43
43
  "Jogging.CoordinateSystem.hlb": "Koordinatensystem",
44
44
  "Jogging.Cartesian.bt": "Kartesisch",
45
45
  "Jogging.Joints.bt": "Gelenke",
46
- "Jogging.Velocity.bt": "Geschwindigkeit"
46
+ "Jogging.Velocity.bt": "Geschwindigkeit",
47
+ "ProgramControl.Start.bt": "Start",
48
+ "ProgramControl.Resume.bt": "Weiter",
49
+ "ProgramControl.Pause.bt": "Pause",
50
+ "ProgramControl.Stop.bt": "Stopp"
47
51
  }
@@ -44,5 +44,9 @@
44
44
  "Jogging.CoordinateSystem.hlb": "Coordinate system",
45
45
  "Jogging.Cartesian.bt": "Cartesian",
46
46
  "Jogging.Joints.bt": "Joints",
47
- "Jogging.Velocity.bt": "Velocity"
47
+ "Jogging.Velocity.bt": "Velocity",
48
+ "ProgramControl.Start.bt": "Start",
49
+ "ProgramControl.Resume.bt": "Resume",
50
+ "ProgramControl.Pause.bt": "Pause",
51
+ "ProgramControl.Stop.bt": "Stop"
48
52
  }
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export * from "./components/jogging/PoseCartesianValues"
9
9
  export * from "./components/jogging/PoseJointValues"
10
10
  export * from "./components/LoadingCover"
11
11
  export * from "./components/modal/NoMotionGroupModal"
12
+ export * from "./components/ProgramControl"
12
13
  export * from "./components/robots/AxisConfig"
13
14
  export * from "./components/robots/Robot"
14
15
  export { defaultGetModel } from "./components/robots/robotModelLogic"