@etsoo/react 1.5.80 → 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 (257) 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 +3 -3
  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 +3 -15
  16. package/src/{mu → components}/DnDList.tsx +11 -34
  17. package/src/components/GridMethodRef.ts +12 -0
  18. package/src/components/ScrollerGrid.tsx +3 -3
  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/ComboBox.tsx +0 -30
  25. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  26. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  27. package/__tests__/mu/SelectEx.tsx +0 -26
  28. package/lib/app/CommonApp.d.ts +0 -39
  29. package/lib/app/CommonApp.js +0 -149
  30. package/lib/app/IServiceAppSettings.d.ts +0 -11
  31. package/lib/app/IServiceAppSettings.js +0 -1
  32. package/lib/app/IServicePage.d.ts +0 -6
  33. package/lib/app/IServicePage.js +0 -1
  34. package/lib/app/IServiceUser.d.ts +0 -14
  35. package/lib/app/IServiceUser.js +0 -1
  36. package/lib/app/ISmartERPUser.d.ts +0 -14
  37. package/lib/app/ISmartERPUser.js +0 -1
  38. package/lib/app/Labels.d.ts +0 -65
  39. package/lib/app/Labels.js +0 -62
  40. package/lib/app/ReactApp.d.ts +0 -194
  41. package/lib/app/ReactApp.js +0 -298
  42. package/lib/app/ServiceApp.d.ts +0 -78
  43. package/lib/app/ServiceApp.js +0 -244
  44. package/lib/components/ShowDataComparison.d.ts +0 -20
  45. package/lib/components/ShowDataComparison.js +0 -60
  46. package/lib/mu/AuditDisplay.d.ts +0 -33
  47. package/lib/mu/AuditDisplay.js +0 -52
  48. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -64
  49. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  50. package/lib/mu/BackButton.d.ts +0 -13
  51. package/lib/mu/BackButton.js +0 -33
  52. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  53. package/lib/mu/BridgeCloseButton.js +0 -32
  54. package/lib/mu/ButtonLink.d.ts +0 -17
  55. package/lib/mu/ButtonLink.js +0 -19
  56. package/lib/mu/ComboBox.d.ts +0 -38
  57. package/lib/mu/ComboBox.js +0 -108
  58. package/lib/mu/CountdownButton.d.ts +0 -23
  59. package/lib/mu/CountdownButton.js +0 -81
  60. package/lib/mu/CustomFabProps.d.ts +0 -27
  61. package/lib/mu/CustomFabProps.js +0 -1
  62. package/lib/mu/DataGridEx.d.ts +0 -96
  63. package/lib/mu/DataGridEx.js +0 -331
  64. package/lib/mu/DataGridRenderers.d.ts +0 -22
  65. package/lib/mu/DataGridRenderers.js +0 -99
  66. package/lib/mu/DialogButton.d.ts +0 -54
  67. package/lib/mu/DialogButton.js +0 -45
  68. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  69. package/lib/mu/DraggablePaperComponent.js +0 -12
  70. package/lib/mu/EmailInput.d.ts +0 -11
  71. package/lib/mu/EmailInput.js +0 -15
  72. package/lib/mu/FabBox.d.ts +0 -21
  73. package/lib/mu/FabBox.js +0 -31
  74. package/lib/mu/FlexBox.d.ts +0 -14
  75. package/lib/mu/FlexBox.js +0 -18
  76. package/lib/mu/GridDataFormat.d.ts +0 -10
  77. package/lib/mu/GridDataFormat.js +0 -43
  78. package/lib/mu/GridMethodRef.d.ts +0 -11
  79. package/lib/mu/IconButtonLink.d.ts +0 -17
  80. package/lib/mu/IconButtonLink.js +0 -16
  81. package/lib/mu/InputField.d.ts +0 -21
  82. package/lib/mu/InputField.js +0 -39
  83. package/lib/mu/ItemList.d.ts +0 -56
  84. package/lib/mu/ItemList.js +0 -69
  85. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  86. package/lib/mu/ListItemRightIcon.js +0 -8
  87. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  88. package/lib/mu/ListMoreDisplay.js +0 -99
  89. package/lib/mu/LoadingButton.d.ts +0 -16
  90. package/lib/mu/LoadingButton.js +0 -41
  91. package/lib/mu/MUGlobal.d.ts +0 -102
  92. package/lib/mu/MUGlobal.js +0 -184
  93. package/lib/mu/MaskInput.d.ts +0 -34
  94. package/lib/mu/MaskInput.js +0 -43
  95. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  96. package/lib/mu/MobileListItemRenderer.js +0 -35
  97. package/lib/mu/MoreFab.d.ts +0 -45
  98. package/lib/mu/MoreFab.js +0 -95
  99. package/lib/mu/NotifierMU.d.ts +0 -47
  100. package/lib/mu/NotifierMU.js +0 -387
  101. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  102. package/lib/mu/NotifierPromptProps.js +0 -1
  103. package/lib/mu/OptionGroup.d.ts +0 -58
  104. package/lib/mu/OptionGroup.js +0 -81
  105. package/lib/mu/PList.d.ts +0 -15
  106. package/lib/mu/PList.js +0 -12
  107. package/lib/mu/ProgressCount.d.ts +0 -44
  108. package/lib/mu/ProgressCount.js +0 -79
  109. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  110. package/lib/mu/PullToRefreshUI.js +0 -18
  111. package/lib/mu/RLink.d.ts +0 -14
  112. package/lib/mu/RLink.js +0 -37
  113. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  114. package/lib/mu/ResponsibleContainer.js +0 -159
  115. package/lib/mu/ScrollTopFab.d.ts +0 -7
  116. package/lib/mu/ScrollTopFab.js +0 -25
  117. package/lib/mu/ScrollerListEx.d.ts +0 -81
  118. package/lib/mu/ScrollerListEx.js +0 -167
  119. package/lib/mu/SearchBar.d.ts +0 -29
  120. package/lib/mu/SearchBar.js +0 -262
  121. package/lib/mu/SearchField.d.ts +0 -21
  122. package/lib/mu/SearchField.js +0 -39
  123. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  124. package/lib/mu/SearchOptionGroup.js +0 -14
  125. package/lib/mu/SelectBool.d.ts +0 -13
  126. package/lib/mu/SelectBool.js +0 -22
  127. package/lib/mu/SelectEx.d.ts +0 -50
  128. package/lib/mu/SelectEx.js +0 -156
  129. package/lib/mu/Switch.d.ts +0 -29
  130. package/lib/mu/Switch.js +0 -34
  131. package/lib/mu/SwitchAnt.d.ts +0 -25
  132. package/lib/mu/SwitchAnt.js +0 -40
  133. package/lib/mu/TabBox.d.ts +0 -54
  134. package/lib/mu/TabBox.js +0 -31
  135. package/lib/mu/TableEx.d.ts +0 -66
  136. package/lib/mu/TableEx.js +0 -271
  137. package/lib/mu/TextFieldEx.d.ts +0 -101
  138. package/lib/mu/TextFieldEx.js +0 -127
  139. package/lib/mu/Tiplist.d.ts +0 -18
  140. package/lib/mu/Tiplist.js +0 -158
  141. package/lib/mu/TooltipClick.d.ts +0 -15
  142. package/lib/mu/TooltipClick.js +0 -40
  143. package/lib/mu/UserAvatar.d.ts +0 -24
  144. package/lib/mu/UserAvatar.js +0 -25
  145. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  146. package/lib/mu/UserAvatarEditor.js +0 -129
  147. package/lib/mu/pages/CommonPage.d.ts +0 -11
  148. package/lib/mu/pages/CommonPage.js +0 -60
  149. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  150. package/lib/mu/pages/CommonPageProps.js +0 -1
  151. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  152. package/lib/mu/pages/DataGridPage.js +0 -81
  153. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  154. package/lib/mu/pages/DataGridPageProps.js +0 -1
  155. package/lib/mu/pages/EditPage.d.ts +0 -33
  156. package/lib/mu/pages/EditPage.js +0 -29
  157. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  158. package/lib/mu/pages/FixedListPage.js +0 -72
  159. package/lib/mu/pages/ListPage.d.ts +0 -9
  160. package/lib/mu/pages/ListPage.js +0 -51
  161. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  162. package/lib/mu/pages/ListPageProps.js +0 -1
  163. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  164. package/lib/mu/pages/ResponsivePage.js +0 -45
  165. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  166. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  167. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  168. package/lib/mu/pages/SearchPageProps.js +0 -1
  169. package/lib/mu/pages/TablePage.d.ts +0 -9
  170. package/lib/mu/pages/TablePage.js +0 -71
  171. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  172. package/lib/mu/pages/TablePageProps.js +0 -1
  173. package/lib/mu/pages/ViewPage.d.ts +0 -66
  174. package/lib/mu/pages/ViewPage.js +0 -105
  175. package/lib/mu/texts/DateText.d.ts +0 -34
  176. package/lib/mu/texts/DateText.js +0 -25
  177. package/lib/mu/texts/MoneyText.d.ts +0 -21
  178. package/lib/mu/texts/MoneyText.js +0 -14
  179. package/lib/mu/texts/NumberText.d.ts +0 -25
  180. package/lib/mu/texts/NumberText.js +0 -14
  181. package/src/app/CommonApp.ts +0 -225
  182. package/src/app/IServiceAppSettings.ts +0 -13
  183. package/src/app/IServicePage.ts +0 -6
  184. package/src/app/IServiceUser.ts +0 -17
  185. package/src/app/ISmartERPUser.ts +0 -16
  186. package/src/app/Labels.ts +0 -77
  187. package/src/app/ReactApp.ts +0 -500
  188. package/src/app/ServiceApp.ts +0 -353
  189. package/src/components/ShowDataComparison.tsx +0 -108
  190. package/src/mu/AuditDisplay.tsx +0 -117
  191. package/src/mu/AutocompleteExtendedProps.ts +0 -83
  192. package/src/mu/BackButton.tsx +0 -55
  193. package/src/mu/BridgeCloseButton.tsx +0 -69
  194. package/src/mu/ButtonLink.tsx +0 -32
  195. package/src/mu/ComboBox.tsx +0 -251
  196. package/src/mu/CountdownButton.tsx +0 -119
  197. package/src/mu/CustomFabProps.ts +0 -32
  198. package/src/mu/DataGridEx.tsx +0 -712
  199. package/src/mu/DataGridRenderers.tsx +0 -140
  200. package/src/mu/DialogButton.tsx +0 -163
  201. package/src/mu/DraggablePaperComponent.tsx +0 -19
  202. package/src/mu/EmailInput.tsx +0 -24
  203. package/src/mu/FabBox.tsx +0 -51
  204. package/src/mu/FlexBox.tsx +0 -20
  205. package/src/mu/GridDataFormat.tsx +0 -77
  206. package/src/mu/GridMethodRef.ts +0 -12
  207. package/src/mu/IconButtonLink.tsx +0 -29
  208. package/src/mu/InputField.tsx +0 -82
  209. package/src/mu/ItemList.tsx +0 -204
  210. package/src/mu/ListItemRightIcon.tsx +0 -9
  211. package/src/mu/ListMoreDisplay.tsx +0 -205
  212. package/src/mu/LoadingButton.tsx +0 -75
  213. package/src/mu/MUGlobal.ts +0 -220
  214. package/src/mu/MaskInput.tsx +0 -107
  215. package/src/mu/MobileListItemRenderer.tsx +0 -79
  216. package/src/mu/MoreFab.tsx +0 -211
  217. package/src/mu/NotifierMU.tsx +0 -654
  218. package/src/mu/NotifierPromptProps.ts +0 -26
  219. package/src/mu/OptionGroup.tsx +0 -223
  220. package/src/mu/PList.tsx +0 -27
  221. package/src/mu/ProgressCount.tsx +0 -166
  222. package/src/mu/PullToRefreshUI.tsx +0 -21
  223. package/src/mu/RLink.tsx +0 -64
  224. package/src/mu/ResponsibleContainer.tsx +0 -394
  225. package/src/mu/ScrollTopFab.tsx +0 -34
  226. package/src/mu/ScrollerListEx.tsx +0 -387
  227. package/src/mu/SearchBar.tsx +0 -398
  228. package/src/mu/SearchField.tsx +0 -82
  229. package/src/mu/SearchOptionGroup.tsx +0 -31
  230. package/src/mu/SelectBool.tsx +0 -33
  231. package/src/mu/SelectEx.tsx +0 -290
  232. package/src/mu/Switch.tsx +0 -94
  233. package/src/mu/SwitchAnt.tsx +0 -95
  234. package/src/mu/TabBox.tsx +0 -118
  235. package/src/mu/TableEx.tsx +0 -560
  236. package/src/mu/TextFieldEx.tsx +0 -250
  237. package/src/mu/Tiplist.tsx +0 -304
  238. package/src/mu/TooltipClick.tsx +0 -84
  239. package/src/mu/UserAvatar.tsx +0 -64
  240. package/src/mu/UserAvatarEditor.tsx +0 -287
  241. package/src/mu/pages/CommonPage.tsx +0 -128
  242. package/src/mu/pages/CommonPageProps.ts +0 -71
  243. package/src/mu/pages/DataGridPage.tsx +0 -137
  244. package/src/mu/pages/DataGridPageProps.ts +0 -24
  245. package/src/mu/pages/EditPage.tsx +0 -114
  246. package/src/mu/pages/FixedListPage.tsx +0 -135
  247. package/src/mu/pages/ListPage.tsx +0 -87
  248. package/src/mu/pages/ListPageProps.ts +0 -12
  249. package/src/mu/pages/ResponsivePage.tsx +0 -68
  250. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  251. package/src/mu/pages/SearchPageProps.ts +0 -39
  252. package/src/mu/pages/TablePage.tsx +0 -120
  253. package/src/mu/pages/TablePageProps.ts +0 -12
  254. package/src/mu/pages/ViewPage.tsx +0 -285
  255. package/src/mu/texts/DateText.tsx +0 -74
  256. package/src/mu/texts/MoneyText.tsx +0 -49
  257. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,398 +0,0 @@
1
- import { Button, Drawer, IconButton, Stack, useTheme } from '@mui/material';
2
- import React from 'react';
3
- import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
4
- import { useDimensions } from '../uses/useDimensions';
5
- import { DomUtils } from '@etsoo/shared';
6
- import { Labels } from '../app/Labels';
7
- import { ReactUtils } from '../app/ReactUtils';
8
- import { useDelayedExecutor } from '..';
9
-
10
- /**
11
- * Search bar props
12
- */
13
- export interface SearchBarProps {
14
- /**
15
- * Style class name
16
- */
17
- className?: string;
18
-
19
- /**
20
- * Fields
21
- */
22
- fields: React.ReactElement[];
23
-
24
- /**
25
- * Inner height
26
- * @default 40
27
- */
28
- innerHeight?: number;
29
-
30
- /**
31
- * On submit callback
32
- */
33
- onSubmit: (data: FormData, reset: boolean) => void | PromiseLike<void>;
34
- }
35
-
36
- // Cached width attribute name
37
- const cachedWidthName: string = 'data-cached-width';
38
-
39
- // Reset form
40
- const resetForm = (form: HTMLFormElement) => {
41
- for (const input of form.elements) {
42
- // Ignore disabled inputs
43
- if ('disabled' in input && (input as any).disabled) continue;
44
-
45
- // All non hidden inputs
46
- if (input instanceof HTMLInputElement) {
47
- // Ignore hidden input
48
- if (input.type === 'hidden') continue;
49
-
50
- // Ignore readOnly without data-reset=true inputs
51
- if (!input.readOnly || input.dataset.reset === 'true') {
52
- ReactUtils.triggerChange(input, '', true);
53
- }
54
- continue;
55
- }
56
-
57
- // All selects
58
- if (input instanceof HTMLSelectElement) {
59
- if (input.options.length > 0 && input.options[0].value === '') {
60
- input.selectedIndex = 0;
61
- } else {
62
- input.selectedIndex = -1;
63
- }
64
- continue;
65
- }
66
- }
67
-
68
- // Trigger reset event
69
- const resetEvent = new Event('reset');
70
- form.dispatchEvent(resetEvent);
71
- };
72
-
73
- // Disable inputs avoid auto trigger change events for them
74
- const setChildState = (child: Element, enabled: boolean) => {
75
- const inputs = child.getElementsByTagName('input');
76
- for (const input of inputs) {
77
- input.disabled = !enabled;
78
- }
79
- };
80
-
81
- /**
82
- * Search bar
83
- * @param props Props
84
- * @returns Component
85
- */
86
- export function SearchBar(props: SearchBarProps) {
87
- // Destruct
88
- const { className, fields, innerHeight = 40, onSubmit } = props;
89
-
90
- // Labels
91
- const labels = Labels.CommonPage;
92
-
93
- // Spacing
94
- const theme = useTheme();
95
- const gap = parseFloat(theme.spacing(1));
96
-
97
- // Menu index
98
- const [index, updateIndex] = React.useState<number>();
99
-
100
- // Drawer open / close
101
- const [open, updateOpen] = React.useState(false);
102
-
103
- // State
104
- const state = React.useRef<{
105
- form?: HTMLFormElement;
106
- moreForm?: HTMLFormElement;
107
- lastMaxWidth: number;
108
- hasMore: boolean;
109
- }>({ hasMore: true, lastMaxWidth: 9999 }).current;
110
-
111
- // Watch container
112
- const { dimensions } = useDimensions(
113
- 1,
114
- (target, rect) => {
115
- // Same logic from resetButtonRef
116
- if (
117
- rect.width === state.lastMaxWidth ||
118
- (!state.hasMore && rect.width > state.lastMaxWidth)
119
- )
120
- return false;
121
-
122
- // Len
123
- const len = target.children.length;
124
- for (let i = 0; i < len; i++) {
125
- var classList = target.children[i].classList;
126
- classList.remove('showChild');
127
- }
128
- },
129
- 0
130
- );
131
-
132
- // Show or hide element
133
- const setElementVisible = (element: Element, visible: boolean) => {
134
- element.classList.remove(visible ? 'hiddenChild' : 'showChild');
135
- element.classList.add(visible ? 'showChild' : 'hiddenChild');
136
- };
137
-
138
- // Reset button ref
139
- const resetButtonRef = (instance: HTMLButtonElement) => {
140
- // Reset button
141
- const resetButton = instance;
142
- if (resetButton == null) return;
143
-
144
- // First
145
- const [_, container, containerRect] = dimensions[0];
146
- if (
147
- container == null ||
148
- containerRect == null ||
149
- containerRect.width < 10
150
- )
151
- return;
152
-
153
- // Container width
154
- let maxWidth = containerRect.width;
155
- if (
156
- maxWidth === state.lastMaxWidth ||
157
- (!state.hasMore && maxWidth > state.lastMaxWidth)
158
- ) {
159
- return;
160
- }
161
- state.lastMaxWidth = maxWidth;
162
-
163
- // More button
164
- const buttonMore = resetButton.previousElementSibling!;
165
-
166
- // Cached button width
167
- const cachedButtonWidth = container.getAttribute(cachedWidthName);
168
- if (cachedButtonWidth) {
169
- maxWidth -= Number.parseFloat(cachedButtonWidth);
170
- } else {
171
- // Reset button rect
172
- const resetButtonRect = resetButton.getBoundingClientRect();
173
-
174
- // More button rect
175
- const buttonMoreRect = buttonMore.getBoundingClientRect();
176
-
177
- // Total
178
- const totalButtonWidth =
179
- resetButtonRect.width + buttonMoreRect.width + 3 * gap;
180
-
181
- // Cache
182
- container.setAttribute(
183
- cachedWidthName,
184
- totalButtonWidth.toString()
185
- );
186
-
187
- maxWidth -= totalButtonWidth;
188
- }
189
-
190
- // Children
191
- const children = container.children;
192
-
193
- // Len
194
- const len = children.length;
195
-
196
- // Other elements
197
- const others = len - 2;
198
- let hasMore = false;
199
- let newIndex: number = others;
200
- for (let c: number = 0; c < others; c++) {
201
- const child = children[c];
202
- const cachedWidth = child.getAttribute(cachedWidthName);
203
- let childWidth: number;
204
- if (cachedWidth) {
205
- childWidth = Number.parseFloat(cachedWidth);
206
- } else {
207
- const childD = child.getBoundingClientRect();
208
- childWidth = childD.width + gap;
209
- child.setAttribute(cachedWidthName, childWidth.toString());
210
- }
211
-
212
- // No gap here, child width includes the gap
213
- if (childWidth <= maxWidth) {
214
- maxWidth -= childWidth;
215
- setChildState(child, true);
216
- setElementVisible(child, true);
217
- } else {
218
- setChildState(child, false);
219
- setElementVisible(child, false);
220
-
221
- if (!hasMore) {
222
- // Make sure coming logic to the block
223
- maxWidth = 0;
224
-
225
- // Keep the current index
226
- newIndex = c;
227
-
228
- // Indicates more
229
- hasMore = true;
230
- }
231
- }
232
- }
233
-
234
- // Show or hide more button
235
- state.hasMore = hasMore;
236
- setElementVisible(buttonMore, hasMore);
237
- setElementVisible(resetButton, true);
238
-
239
- // Update menu start index
240
- updateIndex(newIndex);
241
- };
242
-
243
- // More items creator
244
- const moreItems: React.ReactElement[] = [];
245
- if (index != null) {
246
- for (let i: number = index; i < fields.length; i++) {
247
- moreItems.push(
248
- <React.Fragment key={i}>{fields[i]}</React.Fragment>
249
- );
250
- }
251
- }
252
-
253
- // Handle main form
254
- const handleForm = (event: React.FormEvent<HTMLFormElement>) => {
255
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
256
-
257
- if (state.form == null) state.form = event.currentTarget;
258
-
259
- delayed.call();
260
- };
261
-
262
- // Handle more button click
263
- const handleMore = () => {
264
- updateOpen(!open);
265
- };
266
-
267
- // More form change
268
- const moreFormChange = (event: React.FormEvent<HTMLFormElement>) => {
269
- if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
270
-
271
- if (state.moreForm == null) state.moreForm = event.currentTarget;
272
-
273
- delayed.call();
274
- };
275
-
276
- // Submit at once
277
- const handleSubmitInstant = (reset: boolean = false) => {
278
- // Prepare data
279
- const data = new FormData(state.form);
280
- if (state.moreForm != null) {
281
- DomUtils.mergeFormData(data, new FormData(state.moreForm));
282
- }
283
-
284
- onSubmit(data, reset);
285
- };
286
-
287
- const delayed = useDelayedExecutor(handleSubmitInstant, 480);
288
-
289
- // Reset
290
- const handleReset = () => {
291
- // Clear form values
292
- if (state.form != null) resetForm(state.form);
293
- if (state.moreForm != null) resetForm(state.moreForm);
294
-
295
- // Resubmit
296
- handleSubmitInstant(true);
297
- };
298
-
299
- React.useEffect(() => {
300
- // Delayed way
301
- delayed.call(100);
302
-
303
- return () => {
304
- delayed.clear();
305
- };
306
- }, [className]);
307
-
308
- // Layout
309
- return (
310
- <React.Fragment>
311
- <form
312
- id="SearchBarForm"
313
- className={className}
314
- onChange={handleForm}
315
- ref={(form) => {
316
- if (form) state.form = form;
317
- }}
318
- >
319
- <Stack
320
- ref={dimensions[0][0]}
321
- justifyContent="center"
322
- alignItems="center"
323
- direction="row"
324
- spacing={1}
325
- height={innerHeight}
326
- sx={{
327
- '& > :not(style)': {
328
- flexBasis: 'auto',
329
- flexGrow: 0,
330
- flexShrink: 0,
331
- maxWidth: '180px',
332
- visibility: 'hidden'
333
- },
334
- '& > .hiddenChild': {
335
- display: 'none'
336
- },
337
- '& > .showChild': {
338
- display: 'block',
339
- visibility: 'visible'
340
- }
341
- }}
342
- >
343
- {fields.map((item, index) => (
344
- <React.Fragment key={index}>{item}</React.Fragment>
345
- ))}
346
-
347
- <IconButton
348
- aria-label="delete"
349
- size="medium"
350
- onClick={handleMore}
351
- >
352
- <MoreHorizIcon />
353
- </IconButton>
354
- <Button
355
- variant="contained"
356
- size="medium"
357
- ref={resetButtonRef}
358
- onClick={handleReset}
359
- >
360
- {labels.reset}
361
- </Button>
362
- </Stack>
363
- </form>
364
- {index != null && index < fields.length && (
365
- <Drawer
366
- anchor="right"
367
- sx={{ minWidth: '250px' }}
368
- ModalProps={{
369
- keepMounted: true // Better open performance on mobile.
370
- }}
371
- open={open}
372
- onClose={() => updateOpen(false)}
373
- >
374
- <form
375
- onChange={moreFormChange}
376
- ref={(form) => {
377
- if (form) state.moreForm = form;
378
- }}
379
- >
380
- <Stack
381
- direction="column"
382
- alignItems="stretch"
383
- spacing={2}
384
- padding={2}
385
- sx={{
386
- '& > :not(style)': {
387
- minWidth: '100px'
388
- }
389
- }}
390
- >
391
- {moreItems}
392
- </Stack>
393
- </form>
394
- </Drawer>
395
- )}
396
- </React.Fragment>
397
- );
398
- }
@@ -1,82 +0,0 @@
1
- import { TextField, TextFieldProps } from '@mui/material';
2
- import React from 'react';
3
- import { useDelayedExecutor } from '../uses/useDelayedExecutor';
4
- import { MUGlobal } from './MUGlobal';
5
-
6
- /**
7
- * Search field props
8
- */
9
- export type SearchFieldProps = TextFieldProps & {
10
- /**
11
- * Change delay (ms) to avoid repeatly dispatch onChange
12
- */
13
- changeDelay?: number;
14
-
15
- /**
16
- * Is the field read only?
17
- */
18
- readOnly?: boolean;
19
- };
20
-
21
- /**
22
- * Search field
23
- * @param props Props
24
- * @returns Component
25
- */
26
- export function SearchField(props: SearchFieldProps) {
27
- // Destruct
28
- const {
29
- changeDelay,
30
- InputLabelProps = {},
31
- InputProps = {},
32
- onChange,
33
- readOnly,
34
- size = MUGlobal.searchFieldSize,
35
- variant = MUGlobal.searchFieldVariant,
36
- ...rest
37
- } = props;
38
-
39
- // Shrink
40
- InputLabelProps.shrink = MUGlobal.searchFieldShrink;
41
-
42
- // Read only
43
- if (readOnly != null) InputProps.readOnly = readOnly;
44
-
45
- const isMounted = React.useRef(true);
46
- const delayed =
47
- onChange != null && changeDelay != null && changeDelay >= 1
48
- ? useDelayedExecutor(onChange, changeDelay)
49
- : undefined;
50
-
51
- const onChangeEx = (
52
- event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
53
- ) => {
54
- if (onChange == null) return;
55
-
56
- if (changeDelay == null || changeDelay < 1) {
57
- onChange(event);
58
- return;
59
- }
60
-
61
- delayed?.call(undefined, event);
62
- };
63
-
64
- React.useEffect(() => {
65
- return () => {
66
- isMounted.current = false;
67
- delayed?.clear();
68
- };
69
- }, []);
70
-
71
- // Layout
72
- return (
73
- <TextField
74
- InputLabelProps={InputLabelProps}
75
- InputProps={InputProps}
76
- onChange={onChangeEx}
77
- size={size}
78
- variant={variant}
79
- {...rest}
80
- />
81
- );
82
- }
@@ -1,31 +0,0 @@
1
- import {
2
- DataTypes,
3
- IdDefaultType,
4
- LabelDefaultType,
5
- ListType
6
- } from '@etsoo/shared';
7
- import React from 'react';
8
- import { MUGlobal } from './MUGlobal';
9
- import { OptionGroup, OptionGroupProps } from './OptionGroup';
10
-
11
- /**
12
- * Search OptionGroup
13
- * @param props Props
14
- * @returns Component
15
- */
16
- export function SearchOptionGroup<
17
- T extends object = ListType,
18
- D extends DataTypes.Keys<T> = IdDefaultType<T>,
19
- L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
20
- >(props: OptionGroupProps<T, D, L>) {
21
- // Destruct
22
- const {
23
- row = true,
24
- size = MUGlobal.searchFieldSize,
25
- sx = { '& .MuiFormLabel-root': { fontSize: '0.75em' } },
26
- ...rest
27
- } = props;
28
-
29
- // Layout
30
- return <OptionGroup<T, D, L> row={row} size={size} sx={sx} {...rest} />;
31
- }
@@ -1,33 +0,0 @@
1
- import { ListType1, Utils } from '@etsoo/shared';
2
- import React from 'react';
3
- import { globalApp } from '..';
4
- import { SelectEx, SelectExProps } from './SelectEx';
5
-
6
- /**
7
- * SelectBool props
8
- */
9
- export type SelectBoolProps = Omit<
10
- SelectExProps<ListType1>,
11
- 'options' | 'loadData'
12
- >;
13
-
14
- /**
15
- * SelectBool (yes/no)
16
- * @param props Props
17
- * @returns Component
18
- */
19
- export function SelectBool(props: SelectBoolProps) {
20
- // Destruct
21
- const { search = true, autoAddBlankItem = search, ...rest } = props;
22
-
23
- // Options
24
- const options: ListType1[] = [
25
- { id: 'false', label: globalApp.get('no')! },
26
- { id: 'true', label: globalApp.get('yes')! }
27
- ];
28
-
29
- if (autoAddBlankItem) Utils.addBlankItem(options);
30
-
31
- // Layout
32
- return <SelectEx<ListType1> options={options} search={search} {...rest} />;
33
- }