@etsoo/react 1.5.78 → 1.5.81

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 (255) hide show
  1. package/README.md +7 -2
  2. package/__tests__/ReactUtils.ts +6 -0
  3. package/lib/{mu → components}/DnDList.d.ts +1 -14
  4. package/lib/{mu → components}/DnDList.js +1 -24
  5. package/lib/components/GridMethodRef.d.ts +11 -0
  6. package/lib/{mu → components}/GridMethodRef.js +0 -0
  7. package/lib/components/ScrollerGrid.d.ts +6 -6
  8. package/lib/components/ScrollerList.d.ts +3 -3
  9. package/lib/index.d.ts +2 -74
  10. package/lib/index.js +2 -75
  11. package/lib/notifier/Notifier.d.ts +2 -3
  12. package/lib/uses/useWindowScroll.d.ts +10 -0
  13. package/lib/uses/useWindowScroll.js +46 -0
  14. package/lib/uses/useWindowSize.js +11 -5
  15. package/package.json +9 -21
  16. package/src/{mu → components}/DnDList.tsx +11 -34
  17. package/src/components/GridMethodRef.ts +12 -0
  18. package/src/components/ScrollerGrid.tsx +6 -6
  19. package/src/components/ScrollerList.tsx +5 -3
  20. package/src/index.ts +2 -78
  21. package/src/notifier/Notifier.ts +2 -3
  22. package/src/uses/useWindowScroll.ts +60 -0
  23. package/src/uses/useWindowSize.ts +14 -5
  24. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  25. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  26. package/lib/app/CommonApp.d.ts +0 -39
  27. package/lib/app/CommonApp.js +0 -149
  28. package/lib/app/IServiceAppSettings.d.ts +0 -11
  29. package/lib/app/IServiceAppSettings.js +0 -1
  30. package/lib/app/IServicePage.d.ts +0 -6
  31. package/lib/app/IServicePage.js +0 -1
  32. package/lib/app/IServiceUser.d.ts +0 -14
  33. package/lib/app/IServiceUser.js +0 -1
  34. package/lib/app/ISmartERPUser.d.ts +0 -14
  35. package/lib/app/ISmartERPUser.js +0 -1
  36. package/lib/app/Labels.d.ts +0 -65
  37. package/lib/app/Labels.js +0 -62
  38. package/lib/app/ReactApp.d.ts +0 -194
  39. package/lib/app/ReactApp.js +0 -298
  40. package/lib/app/ServiceApp.d.ts +0 -78
  41. package/lib/app/ServiceApp.js +0 -244
  42. package/lib/components/ShowDataComparison.d.ts +0 -20
  43. package/lib/components/ShowDataComparison.js +0 -60
  44. package/lib/mu/AuditDisplay.d.ts +0 -33
  45. package/lib/mu/AuditDisplay.js +0 -52
  46. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -66
  47. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  48. package/lib/mu/BackButton.d.ts +0 -13
  49. package/lib/mu/BackButton.js +0 -33
  50. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  51. package/lib/mu/BridgeCloseButton.js +0 -32
  52. package/lib/mu/ButtonLink.d.ts +0 -17
  53. package/lib/mu/ButtonLink.js +0 -19
  54. package/lib/mu/ComboBox.d.ts +0 -40
  55. package/lib/mu/ComboBox.js +0 -108
  56. package/lib/mu/CountdownButton.d.ts +0 -23
  57. package/lib/mu/CountdownButton.js +0 -81
  58. package/lib/mu/CustomFabProps.d.ts +0 -27
  59. package/lib/mu/CustomFabProps.js +0 -1
  60. package/lib/mu/DataGridEx.d.ts +0 -96
  61. package/lib/mu/DataGridEx.js +0 -331
  62. package/lib/mu/DataGridRenderers.d.ts +0 -22
  63. package/lib/mu/DataGridRenderers.js +0 -99
  64. package/lib/mu/DialogButton.d.ts +0 -54
  65. package/lib/mu/DialogButton.js +0 -45
  66. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  67. package/lib/mu/DraggablePaperComponent.js +0 -12
  68. package/lib/mu/EmailInput.d.ts +0 -11
  69. package/lib/mu/EmailInput.js +0 -15
  70. package/lib/mu/FabBox.d.ts +0 -21
  71. package/lib/mu/FabBox.js +0 -31
  72. package/lib/mu/FlexBox.d.ts +0 -14
  73. package/lib/mu/FlexBox.js +0 -18
  74. package/lib/mu/GridDataFormat.d.ts +0 -10
  75. package/lib/mu/GridDataFormat.js +0 -43
  76. package/lib/mu/GridMethodRef.d.ts +0 -11
  77. package/lib/mu/IconButtonLink.d.ts +0 -17
  78. package/lib/mu/IconButtonLink.js +0 -16
  79. package/lib/mu/InputField.d.ts +0 -21
  80. package/lib/mu/InputField.js +0 -39
  81. package/lib/mu/ItemList.d.ts +0 -55
  82. package/lib/mu/ItemList.js +0 -77
  83. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  84. package/lib/mu/ListItemRightIcon.js +0 -8
  85. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  86. package/lib/mu/ListMoreDisplay.js +0 -99
  87. package/lib/mu/LoadingButton.d.ts +0 -16
  88. package/lib/mu/LoadingButton.js +0 -41
  89. package/lib/mu/MUGlobal.d.ts +0 -102
  90. package/lib/mu/MUGlobal.js +0 -184
  91. package/lib/mu/MaskInput.d.ts +0 -34
  92. package/lib/mu/MaskInput.js +0 -43
  93. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  94. package/lib/mu/MobileListItemRenderer.js +0 -35
  95. package/lib/mu/MoreFab.d.ts +0 -45
  96. package/lib/mu/MoreFab.js +0 -95
  97. package/lib/mu/NotifierMU.d.ts +0 -47
  98. package/lib/mu/NotifierMU.js +0 -387
  99. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  100. package/lib/mu/NotifierPromptProps.js +0 -1
  101. package/lib/mu/OptionGroup.d.ts +0 -62
  102. package/lib/mu/OptionGroup.js +0 -81
  103. package/lib/mu/PList.d.ts +0 -15
  104. package/lib/mu/PList.js +0 -12
  105. package/lib/mu/ProgressCount.d.ts +0 -44
  106. package/lib/mu/ProgressCount.js +0 -79
  107. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  108. package/lib/mu/PullToRefreshUI.js +0 -18
  109. package/lib/mu/RLink.d.ts +0 -14
  110. package/lib/mu/RLink.js +0 -37
  111. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  112. package/lib/mu/ResponsibleContainer.js +0 -159
  113. package/lib/mu/ScrollTopFab.d.ts +0 -7
  114. package/lib/mu/ScrollTopFab.js +0 -25
  115. package/lib/mu/ScrollerListEx.d.ts +0 -81
  116. package/lib/mu/ScrollerListEx.js +0 -167
  117. package/lib/mu/SearchBar.d.ts +0 -29
  118. package/lib/mu/SearchBar.js +0 -262
  119. package/lib/mu/SearchField.d.ts +0 -21
  120. package/lib/mu/SearchField.js +0 -39
  121. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  122. package/lib/mu/SearchOptionGroup.js +0 -14
  123. package/lib/mu/SelectBool.d.ts +0 -14
  124. package/lib/mu/SelectBool.js +0 -22
  125. package/lib/mu/SelectEx.d.ts +0 -54
  126. package/lib/mu/SelectEx.js +0 -156
  127. package/lib/mu/Switch.d.ts +0 -29
  128. package/lib/mu/Switch.js +0 -34
  129. package/lib/mu/SwitchAnt.d.ts +0 -25
  130. package/lib/mu/SwitchAnt.js +0 -40
  131. package/lib/mu/TabBox.d.ts +0 -54
  132. package/lib/mu/TabBox.js +0 -31
  133. package/lib/mu/TableEx.d.ts +0 -68
  134. package/lib/mu/TableEx.js +0 -271
  135. package/lib/mu/TextFieldEx.d.ts +0 -101
  136. package/lib/mu/TextFieldEx.js +0 -127
  137. package/lib/mu/Tiplist.d.ts +0 -18
  138. package/lib/mu/Tiplist.js +0 -158
  139. package/lib/mu/TooltipClick.d.ts +0 -15
  140. package/lib/mu/TooltipClick.js +0 -40
  141. package/lib/mu/UserAvatar.d.ts +0 -24
  142. package/lib/mu/UserAvatar.js +0 -25
  143. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  144. package/lib/mu/UserAvatarEditor.js +0 -129
  145. package/lib/mu/pages/CommonPage.d.ts +0 -11
  146. package/lib/mu/pages/CommonPage.js +0 -60
  147. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  148. package/lib/mu/pages/CommonPageProps.js +0 -1
  149. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  150. package/lib/mu/pages/DataGridPage.js +0 -81
  151. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  152. package/lib/mu/pages/DataGridPageProps.js +0 -1
  153. package/lib/mu/pages/EditPage.d.ts +0 -33
  154. package/lib/mu/pages/EditPage.js +0 -29
  155. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  156. package/lib/mu/pages/FixedListPage.js +0 -72
  157. package/lib/mu/pages/ListPage.d.ts +0 -9
  158. package/lib/mu/pages/ListPage.js +0 -51
  159. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  160. package/lib/mu/pages/ListPageProps.js +0 -1
  161. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  162. package/lib/mu/pages/ResponsivePage.js +0 -45
  163. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  164. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  165. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  166. package/lib/mu/pages/SearchPageProps.js +0 -1
  167. package/lib/mu/pages/TablePage.d.ts +0 -9
  168. package/lib/mu/pages/TablePage.js +0 -71
  169. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  170. package/lib/mu/pages/TablePageProps.js +0 -1
  171. package/lib/mu/pages/ViewPage.d.ts +0 -66
  172. package/lib/mu/pages/ViewPage.js +0 -105
  173. package/lib/mu/texts/DateText.d.ts +0 -34
  174. package/lib/mu/texts/DateText.js +0 -25
  175. package/lib/mu/texts/MoneyText.d.ts +0 -21
  176. package/lib/mu/texts/MoneyText.js +0 -14
  177. package/lib/mu/texts/NumberText.d.ts +0 -25
  178. package/lib/mu/texts/NumberText.js +0 -14
  179. package/src/app/CommonApp.ts +0 -225
  180. package/src/app/IServiceAppSettings.ts +0 -13
  181. package/src/app/IServicePage.ts +0 -6
  182. package/src/app/IServiceUser.ts +0 -17
  183. package/src/app/ISmartERPUser.ts +0 -16
  184. package/src/app/Labels.ts +0 -77
  185. package/src/app/ReactApp.ts +0 -500
  186. package/src/app/ServiceApp.ts +0 -353
  187. package/src/components/ShowDataComparison.tsx +0 -108
  188. package/src/mu/AuditDisplay.tsx +0 -117
  189. package/src/mu/AutocompleteExtendedProps.ts +0 -84
  190. package/src/mu/BackButton.tsx +0 -55
  191. package/src/mu/BridgeCloseButton.tsx +0 -69
  192. package/src/mu/ButtonLink.tsx +0 -32
  193. package/src/mu/ComboBox.tsx +0 -244
  194. package/src/mu/CountdownButton.tsx +0 -119
  195. package/src/mu/CustomFabProps.ts +0 -32
  196. package/src/mu/DataGridEx.tsx +0 -712
  197. package/src/mu/DataGridRenderers.tsx +0 -140
  198. package/src/mu/DialogButton.tsx +0 -163
  199. package/src/mu/DraggablePaperComponent.tsx +0 -19
  200. package/src/mu/EmailInput.tsx +0 -24
  201. package/src/mu/FabBox.tsx +0 -51
  202. package/src/mu/FlexBox.tsx +0 -20
  203. package/src/mu/GridDataFormat.tsx +0 -77
  204. package/src/mu/GridMethodRef.ts +0 -12
  205. package/src/mu/IconButtonLink.tsx +0 -29
  206. package/src/mu/InputField.tsx +0 -82
  207. package/src/mu/ItemList.tsx +0 -201
  208. package/src/mu/ListItemRightIcon.tsx +0 -9
  209. package/src/mu/ListMoreDisplay.tsx +0 -205
  210. package/src/mu/LoadingButton.tsx +0 -75
  211. package/src/mu/MUGlobal.ts +0 -220
  212. package/src/mu/MaskInput.tsx +0 -107
  213. package/src/mu/MobileListItemRenderer.tsx +0 -79
  214. package/src/mu/MoreFab.tsx +0 -211
  215. package/src/mu/NotifierMU.tsx +0 -654
  216. package/src/mu/NotifierPromptProps.ts +0 -26
  217. package/src/mu/OptionGroup.tsx +0 -218
  218. package/src/mu/PList.tsx +0 -27
  219. package/src/mu/ProgressCount.tsx +0 -166
  220. package/src/mu/PullToRefreshUI.tsx +0 -21
  221. package/src/mu/RLink.tsx +0 -64
  222. package/src/mu/ResponsibleContainer.tsx +0 -394
  223. package/src/mu/ScrollTopFab.tsx +0 -34
  224. package/src/mu/ScrollerListEx.tsx +0 -387
  225. package/src/mu/SearchBar.tsx +0 -398
  226. package/src/mu/SearchField.tsx +0 -82
  227. package/src/mu/SearchOptionGroup.tsx +0 -25
  228. package/src/mu/SelectBool.tsx +0 -40
  229. package/src/mu/SelectEx.tsx +0 -285
  230. package/src/mu/Switch.tsx +0 -94
  231. package/src/mu/SwitchAnt.tsx +0 -95
  232. package/src/mu/TabBox.tsx +0 -118
  233. package/src/mu/TableEx.tsx +0 -561
  234. package/src/mu/TextFieldEx.tsx +0 -250
  235. package/src/mu/Tiplist.tsx +0 -304
  236. package/src/mu/TooltipClick.tsx +0 -84
  237. package/src/mu/UserAvatar.tsx +0 -64
  238. package/src/mu/UserAvatarEditor.tsx +0 -287
  239. package/src/mu/pages/CommonPage.tsx +0 -128
  240. package/src/mu/pages/CommonPageProps.ts +0 -71
  241. package/src/mu/pages/DataGridPage.tsx +0 -137
  242. package/src/mu/pages/DataGridPageProps.ts +0 -24
  243. package/src/mu/pages/EditPage.tsx +0 -114
  244. package/src/mu/pages/FixedListPage.tsx +0 -134
  245. package/src/mu/pages/ListPage.tsx +0 -86
  246. package/src/mu/pages/ListPageProps.ts +0 -11
  247. package/src/mu/pages/ResponsivePage.tsx +0 -68
  248. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  249. package/src/mu/pages/SearchPageProps.ts +0 -39
  250. package/src/mu/pages/TablePage.tsx +0 -119
  251. package/src/mu/pages/TablePageProps.ts +0 -11
  252. package/src/mu/pages/ViewPage.tsx +0 -285
  253. package/src/mu/texts/DateText.tsx +0 -74
  254. package/src/mu/texts/MoneyText.tsx +0 -49
  255. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,654 +0,0 @@
1
- import {
2
- NotificationAlign,
3
- NotificationMessageType,
4
- NotificationRenderProps,
5
- NotificationType
6
- } from '@etsoo/notificationbase';
7
- import { DataTypes } from '@etsoo/shared';
8
- import {
9
- Alert,
10
- AlertColor,
11
- AlertProps,
12
- AlertTitle,
13
- Backdrop,
14
- Box,
15
- Button,
16
- CircularProgress,
17
- CircularProgressProps,
18
- Dialog,
19
- DialogActions,
20
- DialogContent,
21
- DialogContentText,
22
- DialogTitle,
23
- Fade,
24
- Slider,
25
- Snackbar,
26
- styled,
27
- Switch,
28
- TextField,
29
- Typography
30
- } from '@mui/material';
31
- import { Error, Info, Help, Warning, Done } from '@mui/icons-material';
32
- import React from 'react';
33
- import { Labels } from '../app/Labels';
34
- import {
35
- INotificationBaseReact,
36
- INotificationReact,
37
- NotificationReact,
38
- NotifierReact
39
- } from '../notifier/Notifier';
40
- import { DraggablePaperComponent } from './DraggablePaperComponent';
41
- import { LoadingButton, LoadingButtonProps } from './LoadingButton';
42
-
43
- // Custom icon dialog title bar
44
- const IconDialogTitle = styled(DialogTitle)`
45
- ${({ theme }) => `
46
- cursor: move;
47
- display: flex;
48
- align-items: center;
49
- & .dialogTitle {
50
- font-weight: bold;
51
- font-size: 1.17em;
52
- padding-left: ${theme.spacing(1)};
53
- }
54
- `}
55
- `;
56
-
57
- /**
58
- * MU notification
59
- */
60
- export class NotificationMU extends NotificationReact {
61
- // On return
62
- // Dismiss first, then run callback
63
- private async returnValue(value: any) {
64
- if (this.onReturn) {
65
- const result = await this.onReturn(value);
66
- if (result === false) return;
67
- }
68
- this.dismiss();
69
- }
70
-
71
- // Create alert
72
- private createAlert(_props: NotificationRenderProps, className: string) {
73
- const labels = Labels.NotificationMU;
74
-
75
- const {
76
- inputs,
77
- fullScreen,
78
- fullWidth = true,
79
- maxWidth,
80
- okLabel = labels.alertOK,
81
- primaryButton
82
- } = this.inputProps ?? {};
83
-
84
- let title = this.title;
85
- let icon: React.ReactNode;
86
- if (this.type === NotificationMessageType.Success) {
87
- icon = <Done color="primary" />;
88
- title ??= labels.success;
89
- } else if (this.type === NotificationMessageType.Info) {
90
- icon = <Info />;
91
- title ??= labels.info;
92
- } else if (this.type === NotificationMessageType.Warning) {
93
- icon = <Warning color="secondary" />;
94
- title ??= labels.warning;
95
- } else {
96
- icon = <Error color="error" />;
97
- title ??= labels.alertTitle;
98
- }
99
-
100
- const setupProps: LoadingButtonProps = {
101
- color: 'primary'
102
- };
103
-
104
- // Setup callback
105
- if (this.renderSetup) this.renderSetup(setupProps);
106
-
107
- return (
108
- <Dialog
109
- key={this.id}
110
- open={this.open}
111
- PaperComponent={DraggablePaperComponent}
112
- className={className}
113
- fullWidth={fullWidth}
114
- maxWidth={maxWidth}
115
- fullScreen={fullScreen}
116
- >
117
- <IconDialogTitle className="draggable-dialog-title">
118
- {icon}
119
- <span className="dialogTitle">{title}</span>
120
- </IconDialogTitle>
121
- <DialogContent>
122
- <DialogContentText>{this.content}</DialogContentText>
123
- {inputs}
124
- </DialogContent>
125
- <DialogActions>
126
- <LoadingButton
127
- {...setupProps}
128
- onClick={async () => await this.returnValue(undefined)}
129
- autoFocus
130
- {...primaryButton}
131
- >
132
- {okLabel}
133
- </LoadingButton>
134
- </DialogActions>
135
- </Dialog>
136
- );
137
- }
138
-
139
- // Create confirm
140
- private createConfirm(_props: NotificationRenderProps, className: string) {
141
- const labels = Labels.NotificationMU;
142
- const title = this.title ?? labels.confirmTitle;
143
-
144
- const {
145
- okLabel = labels.confirmYes,
146
- cancelLabel = labels.confirmNo,
147
- cancelButton = true,
148
- inputs,
149
- fullScreen,
150
- fullWidth = true,
151
- maxWidth,
152
- primaryButton
153
- } = this.inputProps ?? {};
154
-
155
- return (
156
- <Dialog
157
- key={this.id}
158
- open={this.open}
159
- PaperComponent={DraggablePaperComponent}
160
- className={className}
161
- fullWidth={fullWidth}
162
- maxWidth={maxWidth}
163
- fullScreen={fullScreen}
164
- >
165
- <IconDialogTitle className="draggable-dialog-title">
166
- <Help color="action" />
167
- <span className="dialogTitle">{title}</span>
168
- </IconDialogTitle>
169
- <DialogContent>
170
- <DialogContentText>{this.content}</DialogContentText>
171
- {inputs}
172
- </DialogContent>
173
- <DialogActions>
174
- {cancelButton && (
175
- <LoadingButton
176
- color="secondary"
177
- onClick={async () => await this.returnValue(false)}
178
- >
179
- {cancelLabel}
180
- </LoadingButton>
181
- )}
182
- <LoadingButton
183
- color="primary"
184
- onClick={async () => await this.returnValue(true)}
185
- autoFocus
186
- {...primaryButton}
187
- >
188
- {okLabel}
189
- </LoadingButton>
190
- </DialogActions>
191
- </Dialog>
192
- );
193
- }
194
-
195
- private createMessageColor(): AlertColor {
196
- if (this.type === NotificationMessageType.Danger) return 'error';
197
- if (this.type === NotificationMessageType.Success) return 'success';
198
- if (this.type === NotificationMessageType.Warning) return 'warning';
199
- return 'info';
200
- }
201
-
202
- // Create message
203
- private createMessage(_props: NotificationRenderProps, className: string) {
204
- if (!this.open) return <React.Fragment key={this.id}></React.Fragment>;
205
-
206
- const setupProps: AlertProps = {
207
- severity: this.createMessageColor(),
208
- variant: 'filled'
209
- };
210
-
211
- // Setup callback
212
- if (this.renderSetup) this.renderSetup(setupProps);
213
-
214
- return (
215
- <Fade in={true} key={this.id}>
216
- <Alert
217
- {...setupProps}
218
- onClose={() => this.dismiss()} // dismiss will trigger the onReturn callback
219
- className={className}
220
- >
221
- {this.title && <AlertTitle>{this.title}</AlertTitle>}
222
- {this.content}
223
- </Alert>
224
- </Fade>
225
- );
226
- }
227
-
228
- // Create prompt
229
- private createPrompt(_props: NotificationRenderProps, className: string) {
230
- const labels = Labels.NotificationMU;
231
- const title = this.title ?? labels.promptTitle;
232
-
233
- const {
234
- cancelLabel = labels.promptCancel,
235
- okLabel = labels.promptOK,
236
- cancelButton = true,
237
- inputs,
238
- type,
239
- fullScreen,
240
- fullWidth = true,
241
- maxWidth,
242
- primaryButton,
243
- ...rest
244
- } = this.inputProps ?? {};
245
-
246
- const inputRef = React.createRef<HTMLInputElement>();
247
- const errorRef = React.createRef<HTMLSpanElement>();
248
-
249
- const setError = (error?: string) => {
250
- if (errorRef.current == null) return;
251
- errorRef.current.innerText = error ?? '';
252
- };
253
-
254
- const handleSubmit = async (
255
- event: React.MouseEvent<HTMLButtonElement>
256
- ) => {
257
- // Result
258
- let result:
259
- | boolean
260
- | string
261
- | void
262
- | PromiseLike<boolean | string | void> = undefined;
263
-
264
- const input = inputRef.current;
265
-
266
- if (this.onReturn) {
267
- // Inputs case, no HTMLForm set to value, set the current form
268
- if (inputs && value == null) value = event.currentTarget.form;
269
-
270
- if (input) {
271
- if (type === 'date') {
272
- const dateValue = input.valueAsDate;
273
- if (dateValue == null && input.required) {
274
- input.focus();
275
- return;
276
- }
277
- result = this.onReturn(dateValue);
278
- } else if (type === 'number') {
279
- const numberValue = input.valueAsNumber;
280
- if (isNaN(numberValue) && input.required) {
281
- input.focus();
282
- return;
283
- }
284
- result = this.onReturn(numberValue);
285
- } else if (type === 'switch') {
286
- const boolValue = input.value === 'true';
287
- result = this.onReturn(boolValue);
288
- } else {
289
- const textValue = input.value.trim();
290
- if (textValue === '' && input.required) {
291
- input.focus();
292
- return;
293
- }
294
- result = this.onReturn(textValue);
295
- }
296
- } else if (value != null) {
297
- result = this.onReturn(value);
298
- }
299
- }
300
-
301
- // Get the value
302
- // returns false to prevent default dismiss
303
- const v = await result;
304
- if (v === false) {
305
- input?.focus();
306
- return;
307
- }
308
- if (typeof v === 'string') {
309
- setError(v);
310
- input?.focus();
311
- return;
312
- }
313
-
314
- this.dismiss();
315
- };
316
-
317
- let localInputs: React.ReactNode;
318
- let value: any = undefined;
319
-
320
- if (inputs == null) {
321
- if (type === 'switch') {
322
- localInputs = (
323
- <Switch
324
- inputRef={inputRef}
325
- {...rest}
326
- value="true"
327
- autoFocus
328
- required
329
- />
330
- );
331
- } else if (type === 'slider') {
332
- localInputs = <Slider onChange={(_e, v) => (value = v)} />;
333
- } else {
334
- localInputs = (
335
- <TextField
336
- inputRef={inputRef}
337
- onChange={() => setError(undefined)}
338
- autoFocus
339
- margin="dense"
340
- fullWidth
341
- type={type}
342
- required
343
- {...rest}
344
- />
345
- );
346
- }
347
- } else {
348
- localInputs = inputs;
349
- }
350
-
351
- return (
352
- <Dialog
353
- key={this.id}
354
- open={this.open}
355
- PaperComponent={DraggablePaperComponent}
356
- className={className}
357
- fullWidth={fullWidth}
358
- maxWidth={maxWidth}
359
- fullScreen={fullScreen}
360
- >
361
- <form
362
- onSubmit={(event) => {
363
- event.preventDefault();
364
- (
365
- event.currentTarget.elements.namedItem(
366
- 'okButton'
367
- ) as HTMLButtonElement
368
- )?.click();
369
- return false;
370
- }}
371
- >
372
- <IconDialogTitle className="draggable-dialog-title">
373
- <Info color="primary" />
374
- <span className="dialogTitle">{title}</span>
375
- </IconDialogTitle>
376
- <DialogContent>
377
- <DialogContentText>{this.content}</DialogContentText>
378
- {localInputs}
379
- <Typography
380
- variant="caption"
381
- display="block"
382
- ref={errorRef}
383
- color={(theme) => theme.palette.error.main}
384
- />
385
- </DialogContent>
386
- <DialogActions>
387
- {cancelButton && (
388
- <Button
389
- color="secondary"
390
- onClick={() => {
391
- if (this.onReturn) this.onReturn(undefined);
392
- this.dismiss();
393
- }}
394
- >
395
- {cancelLabel}
396
- </Button>
397
- )}
398
- <LoadingButton
399
- color="primary"
400
- autoFocus
401
- onClick={handleSubmit}
402
- name="okButton"
403
- {...primaryButton}
404
- >
405
- {okLabel}
406
- </LoadingButton>
407
- </DialogActions>
408
- </form>
409
- </Dialog>
410
- );
411
- }
412
-
413
- // Create loading
414
- private createLoading(_props: NotificationRenderProps, className: string) {
415
- // Properties
416
- const setupProps: CircularProgressProps = { color: 'primary' };
417
-
418
- const labels = Labels.NotificationMU;
419
-
420
- // Input props
421
- const { maxWidth = 'xs' } = this.inputProps ?? {};
422
-
423
- // Content
424
- let content = this.content;
425
- if (content === '@') content = labels.loading.toString();
426
-
427
- // Setup callback
428
- if (this.renderSetup) this.renderSetup(setupProps);
429
-
430
- return (
431
- <Backdrop
432
- key={this.id}
433
- className={className}
434
- sx={{
435
- color: '#fff',
436
- zIndex: (theme) => theme.zIndex.modal + 1
437
- }}
438
- open={this.open}
439
- >
440
- <Box
441
- display="flex"
442
- flexDirection="column"
443
- flexWrap="nowrap"
444
- alignItems="center"
445
- sx={{
446
- '& > :not(style) + :not(style)': {
447
- marginTop: (theme) => theme.spacing(1)
448
- }
449
- }}
450
- >
451
- <CircularProgress {...setupProps} />
452
- {content && (
453
- <Box
454
- maxWidth={maxWidth === false ? undefined : maxWidth}
455
- >
456
- {content}
457
- </Box>
458
- )}
459
- </Box>
460
- </Backdrop>
461
- );
462
- }
463
-
464
- /**
465
- * Render method
466
- * @param props Props
467
- * @param className Style class name
468
- * @param classes Style classes
469
- */
470
- render(props: NotificationRenderProps, className: string) {
471
- // Loading bar
472
- if (this.type === NotificationType.Loading) {
473
- return this.createLoading(props, className);
474
- } else if (this.type === NotificationType.Confirm) {
475
- return this.createConfirm(props, className);
476
- } else if (this.type === NotificationType.Prompt) {
477
- return this.createPrompt(props, className);
478
- } else if (
479
- this.type === NotificationType.Error ||
480
- (this.modal && this.type in NotificationMessageType)
481
- ) {
482
- // Alert or modal message
483
- return this.createAlert(props, className);
484
- } else {
485
- return this.createMessage(props, className);
486
- }
487
- }
488
- }
489
-
490
- // Origin constructor generics
491
- interface origin {
492
- vertical: 'top' | 'bottom';
493
- horizontal: DataTypes.HAlign;
494
- }
495
-
496
- /**
497
- * Antd notifier
498
- */
499
- export class NotifierMU extends NotifierReact {
500
- /**
501
- * Create state and return provider
502
- * @param className Style class name
503
- * @returns Provider
504
- */
505
- static setup(className = 'notifier-mu') {
506
- // Create an instance
507
- const instance = new NotifierMU();
508
- const provider = instance.createProvider(className);
509
- NotifierReact.updateInstance(instance);
510
- return provider;
511
- }
512
-
513
- // Calculate origin from align property
514
- private static getOrigin(align: NotificationAlign): origin | undefined {
515
- if (align === NotificationAlign.TopLeft) {
516
- return {
517
- horizontal: 'left',
518
- vertical: 'top'
519
- };
520
- }
521
-
522
- if (align === NotificationAlign.TopCenter) {
523
- return {
524
- horizontal: 'center',
525
- vertical: 'top'
526
- };
527
- }
528
-
529
- if (align === NotificationAlign.TopRight) {
530
- return {
531
- horizontal: 'right',
532
- vertical: 'top'
533
- };
534
- }
535
-
536
- if (align === NotificationAlign.BottomLeft) {
537
- return {
538
- horizontal: 'left',
539
- vertical: 'bottom'
540
- };
541
- }
542
-
543
- if (align === NotificationAlign.BottomCenter) {
544
- return {
545
- horizontal: 'center',
546
- vertical: 'bottom'
547
- };
548
- }
549
-
550
- if (align === NotificationAlign.BottomRight) {
551
- return {
552
- horizontal: 'right',
553
- vertical: 'bottom'
554
- };
555
- }
556
-
557
- return {
558
- horizontal: 'center',
559
- vertical: 'top'
560
- };
561
- }
562
-
563
- /**
564
- * Create align container
565
- * @param align Align
566
- * @param children Children
567
- * @param options Other options
568
- */
569
- protected createContainer = (
570
- align: NotificationAlign,
571
- children: React.ReactNode[]
572
- ) => {
573
- // Each align group, class equal to something similar to 'align-topleft'
574
- const alignText = NotificationAlign[align].toLowerCase();
575
- let className = `align-${alignText}`;
576
-
577
- if (children.length === 0) {
578
- return <div key={`empty-${alignText}`} className={className} />;
579
- }
580
-
581
- if (align === NotificationAlign.Unknown) {
582
- // div container for style control
583
- return (
584
- <div key={`div-${alignText}`} className={className}>
585
- {children}
586
- </div>
587
- );
588
- }
589
-
590
- // Use SnackBar for layout
591
- return (
592
- <Snackbar
593
- anchorOrigin={NotifierMU.getOrigin(align)}
594
- className={className}
595
- key={`layout-${alignText}`}
596
- sx={
597
- align === NotificationAlign.Center
598
- ? { position: 'fixed', top: '50%!important' }
599
- : undefined
600
- }
601
- open
602
- >
603
- <Box
604
- display="flex"
605
- flexDirection="column"
606
- flexWrap="nowrap"
607
- key={`box-${alignText}`}
608
- sx={{
609
- '& > :not(style) + :not(style)': {
610
- marginTop: (theme) => theme.spacing(1)
611
- }
612
- }}
613
- >
614
- {children}
615
- </Box>
616
- </Snackbar>
617
- );
618
- };
619
-
620
- /**
621
- * Add raw definition
622
- * @param data Notification data definition
623
- * @param modal Show as modal
624
- */
625
- protected addRaw(
626
- data: INotificationBaseReact,
627
- modal?: boolean
628
- ): INotificationReact {
629
- // Destruct
630
- const {
631
- type,
632
- content,
633
- title,
634
- align,
635
- timespan = modal ? 0 : undefined,
636
- ...rest
637
- } = data;
638
-
639
- // Setup
640
- const n = new NotificationMU(type, content, title, align, timespan);
641
-
642
- // Assign other properties
643
- Object.assign(n, rest);
644
-
645
- // Is modal
646
- if (modal != null) n.modal = modal;
647
-
648
- // Add to the collection
649
- this.add(n);
650
-
651
- // Return
652
- return n;
653
- }
654
- }
@@ -1,26 +0,0 @@
1
- import { Breakpoint } from '@mui/material';
2
-
3
- /**
4
- * Notifier prompt props
5
- */
6
- export type NotifierPromptProps = Record<string, any> & {
7
- /**
8
- * Cancel label
9
- */
10
- cancelLabel?: string;
11
-
12
- /**
13
- * OK label
14
- */
15
- okLabel?: string;
16
-
17
- /**
18
- * Multiple inputs
19
- */
20
- inputs: React.ReactNode;
21
-
22
- /**
23
- * Single type
24
- */
25
- type?: string;
26
- };