@etsoo/react 1.5.48 → 1.5.51

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.
@@ -78,6 +78,33 @@ test('Confirm tests', async () => {
78
78
  jest.runOnlyPendingTimers();
79
79
  });
80
80
 
81
+ test('Confirm tests without cancel button', async () => {
82
+ // Click
83
+ const handleClick = jest.fn();
84
+
85
+ act(() => {
86
+ // Add the notification
87
+ notifier.confirm('Confirm message', undefined, handleClick, {
88
+ cancelButton: false
89
+ });
90
+ });
91
+
92
+ // Button
93
+ const button = root.getElementsByTagName('button');
94
+
95
+ expect(button.length).toBe(1);
96
+ expect(button[0].innerHTML).toContain('OK');
97
+
98
+ await act(async () => {
99
+ button[0].click();
100
+ });
101
+
102
+ expect(handleClick).toBeCalled();
103
+
104
+ // Fast forward
105
+ jest.runOnlyPendingTimers();
106
+ });
107
+
81
108
  test('Prompt tests', async () => {
82
109
  // Click
83
110
  const handleClick = jest.fn((result: boolean) => {
@@ -107,6 +134,33 @@ test('Prompt tests', async () => {
107
134
  jest.runOnlyPendingTimers();
108
135
  });
109
136
 
137
+ test('Prompt tests with form submit', async () => {
138
+ // Click
139
+ const handleClick = jest.fn((result: boolean) => {
140
+ expect(result).toBeTruthy();
141
+ });
142
+
143
+ act(() => {
144
+ // Add the notification
145
+ notifier.prompt<boolean>('Prompt message', handleClick, undefined, {
146
+ type: 'switch',
147
+ required: false
148
+ });
149
+ });
150
+
151
+ await act(async () => {
152
+ (
153
+ root
154
+ .getElementsByTagName('form')[0]
155
+ .elements.namedItem('okButton') as HTMLButtonElement
156
+ )?.click();
157
+ });
158
+
159
+ expect(handleClick).toBeCalled();
160
+
161
+ jest.runOnlyPendingTimers();
162
+ });
163
+
110
164
  test('Message tests', (done) => {
111
165
  // Callback
112
166
  const callback = jest.fn(() => done());
@@ -77,7 +77,7 @@ export class NotificationMU extends NotificationReact {
77
77
  var _a, _b;
78
78
  const labels = Labels.NotificationMU;
79
79
  const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.confirmTitle;
80
- const { okLabel = labels.confirmYes, cancelLabel = labels.confirmNo, inputs, fullScreen, fullWidth = true, maxWidth, primaryButton } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
80
+ const { okLabel = labels.confirmYes, cancelLabel = labels.confirmNo, cancelButton = true, inputs, fullScreen, fullWidth = true, maxWidth, primaryButton } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
81
81
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
82
82
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
83
83
  React.createElement(Help, { color: "action" }),
@@ -86,7 +86,7 @@ export class NotificationMU extends NotificationReact {
86
86
  React.createElement(DialogContentText, null, this.content),
87
87
  inputs),
88
88
  React.createElement(DialogActions, null,
89
- React.createElement(LoadingButton, { color: "secondary", onClick: async () => await this.returnValue(false) }, cancelLabel),
89
+ cancelButton && (React.createElement(LoadingButton, { color: "secondary", onClick: async () => await this.returnValue(false) }, cancelLabel)),
90
90
  React.createElement(LoadingButton, { color: "primary", onClick: async () => await this.returnValue(true), autoFocus: true, ...primaryButton }, okLabel))));
91
91
  }
92
92
  createMessageColor() {
@@ -119,7 +119,7 @@ export class NotificationMU extends NotificationReact {
119
119
  var _a, _b;
120
120
  const labels = Labels.NotificationMU;
121
121
  const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.promptTitle;
122
- const { cancelLabel = labels.promptCancel, okLabel = labels.promptOK, inputs, type, fullScreen, fullWidth = true, maxWidth, primaryButton, ...rest } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
122
+ const { cancelLabel = labels.promptCancel, okLabel = labels.promptOK, cancelButton = true, inputs, type, fullScreen, fullWidth = true, maxWidth, primaryButton, ...rest } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
123
123
  const inputRef = React.createRef();
124
124
  const errorRef = React.createRef();
125
125
  const setError = (error) => {
@@ -200,7 +200,10 @@ export class NotificationMU extends NotificationReact {
200
200
  localInputs = inputs;
201
201
  }
202
202
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
203
- React.createElement("form", null,
203
+ React.createElement("form", { onSubmit: (event) => {
204
+ var _a;
205
+ return (_a = event.currentTarget.elements.namedItem('okButton')) === null || _a === void 0 ? void 0 : _a.click();
206
+ } },
204
207
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
205
208
  React.createElement(Info, { color: "primary" }),
206
209
  React.createElement("span", { className: "dialogTitle" }, title)),
@@ -209,12 +212,12 @@ export class NotificationMU extends NotificationReact {
209
212
  localInputs,
210
213
  React.createElement(Typography, { variant: "caption", display: "block", ref: errorRef, color: (theme) => theme.palette.error.main })),
211
214
  React.createElement(DialogActions, null,
212
- React.createElement(Button, { color: "secondary", onClick: () => {
215
+ cancelButton && (React.createElement(Button, { color: "secondary", onClick: () => {
213
216
  if (this.onReturn)
214
217
  this.onReturn(undefined);
215
218
  this.dismiss();
216
- } }, cancelLabel),
217
- React.createElement(LoadingButton, { color: "primary", autoFocus: true, onClick: handleSubmit, ...primaryButton }, okLabel)))));
219
+ } }, cancelLabel)),
220
+ React.createElement(LoadingButton, { color: "primary", autoFocus: true, onClick: handleSubmit, name: "okButton", ...primaryButton }, okLabel)))));
218
221
  }
219
222
  // Create loading
220
223
  createLoading(_props, className) {
@@ -27,6 +27,10 @@ export interface NotificationReactCallProps extends NotificationCallProps {
27
27
  * OK label
28
28
  */
29
29
  okLabel?: string;
30
+ /**
31
+ * false to hide cancel button
32
+ */
33
+ cancelButton?: boolean;
30
34
  /**
31
35
  * Cancel label
32
36
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.48",
3
+ "version": "1.5.51",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,11 +50,11 @@
50
50
  "@emotion/react": "^11.9.3",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.9.3",
53
- "@etsoo/appscript": "^1.2.62",
53
+ "@etsoo/appscript": "^1.2.63",
54
54
  "@etsoo/notificationbase": "^1.1.4",
55
55
  "@etsoo/shared": "^1.1.40",
56
56
  "@mui/icons-material": "^5.8.4",
57
- "@mui/material": "^5.9.1",
57
+ "@mui/material": "^5.9.2",
58
58
  "@types/pica": "^9.0.1",
59
59
  "@types/pulltorefreshjs": "^0.1.5",
60
60
  "@types/react": "^18.0.15",
@@ -82,8 +82,8 @@
82
82
  "@babel/runtime-corejs3": "^7.18.9",
83
83
  "@types/jest": "^28.1.6",
84
84
  "@types/react-test-renderer": "^18.0.0",
85
- "@typescript-eslint/eslint-plugin": "^5.30.7",
86
- "@typescript-eslint/parser": "^5.30.7",
85
+ "@typescript-eslint/eslint-plugin": "^5.31.0",
86
+ "@typescript-eslint/parser": "^5.31.0",
87
87
  "eslint": "^8.20.0",
88
88
  "eslint-config-airbnb-base": "^15.0.0",
89
89
  "eslint-plugin-import": "^2.26.0",
@@ -144,6 +144,7 @@ export class NotificationMU extends NotificationReact {
144
144
  const {
145
145
  okLabel = labels.confirmYes,
146
146
  cancelLabel = labels.confirmNo,
147
+ cancelButton = true,
147
148
  inputs,
148
149
  fullScreen,
149
150
  fullWidth = true,
@@ -170,12 +171,14 @@ export class NotificationMU extends NotificationReact {
170
171
  {inputs}
171
172
  </DialogContent>
172
173
  <DialogActions>
173
- <LoadingButton
174
- color="secondary"
175
- onClick={async () => await this.returnValue(false)}
176
- >
177
- {cancelLabel}
178
- </LoadingButton>
174
+ {cancelButton && (
175
+ <LoadingButton
176
+ color="secondary"
177
+ onClick={async () => await this.returnValue(false)}
178
+ >
179
+ {cancelLabel}
180
+ </LoadingButton>
181
+ )}
179
182
  <LoadingButton
180
183
  color="primary"
181
184
  onClick={async () => await this.returnValue(true)}
@@ -230,6 +233,7 @@ export class NotificationMU extends NotificationReact {
230
233
  const {
231
234
  cancelLabel = labels.promptCancel,
232
235
  okLabel = labels.promptOK,
236
+ cancelButton = true,
233
237
  inputs,
234
238
  type,
235
239
  fullScreen,
@@ -354,7 +358,15 @@ export class NotificationMU extends NotificationReact {
354
358
  maxWidth={maxWidth}
355
359
  fullScreen={fullScreen}
356
360
  >
357
- <form>
361
+ <form
362
+ onSubmit={(event) =>
363
+ (
364
+ event.currentTarget.elements.namedItem(
365
+ 'okButton'
366
+ ) as HTMLButtonElement
367
+ )?.click()
368
+ }
369
+ >
358
370
  <IconDialogTitle className="draggable-dialog-title">
359
371
  <Info color="primary" />
360
372
  <span className="dialogTitle">{title}</span>
@@ -370,19 +382,22 @@ export class NotificationMU extends NotificationReact {
370
382
  />
371
383
  </DialogContent>
372
384
  <DialogActions>
373
- <Button
374
- color="secondary"
375
- onClick={() => {
376
- if (this.onReturn) this.onReturn(undefined);
377
- this.dismiss();
378
- }}
379
- >
380
- {cancelLabel}
381
- </Button>
385
+ {cancelButton && (
386
+ <Button
387
+ color="secondary"
388
+ onClick={() => {
389
+ if (this.onReturn) this.onReturn(undefined);
390
+ this.dismiss();
391
+ }}
392
+ >
393
+ {cancelLabel}
394
+ </Button>
395
+ )}
382
396
  <LoadingButton
383
397
  color="primary"
384
398
  autoFocus
385
399
  onClick={handleSubmit}
400
+ name="okButton"
386
401
  {...primaryButton}
387
402
  >
388
403
  {okLabel}
@@ -44,6 +44,11 @@ export interface NotificationReactCallProps extends NotificationCallProps {
44
44
  */
45
45
  okLabel?: string;
46
46
 
47
+ /**
48
+ * false to hide cancel button
49
+ */
50
+ cancelButton?: boolean;
51
+
47
52
  /**
48
53
  * Cancel label
49
54
  */