@etsoo/react 1.5.79 → 1.5.82

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 +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 +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 +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/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 -64
  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 -38
  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 -56
  82. package/lib/mu/ItemList.js +0 -69
  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 -58
  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 -13
  124. package/lib/mu/SelectBool.js +0 -22
  125. package/lib/mu/SelectEx.d.ts +0 -50
  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 -66
  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 -83
  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 -251
  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 -204
  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 -223
  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 -31
  228. package/src/mu/SelectBool.tsx +0 -33
  229. package/src/mu/SelectEx.tsx +0 -290
  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 -560
  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 -135
  245. package/src/mu/pages/ListPage.tsx +0 -87
  246. package/src/mu/pages/ListPageProps.ts +0 -12
  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 -120
  251. package/src/mu/pages/TablePageProps.ts +0 -12
  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,69 +0,0 @@
1
- import { BridgeUtils, IBridgeHost } from '@etsoo/appscript';
2
- import CloseIcon from '@mui/icons-material/Close';
3
- import { Box, BoxProps, IconButton, IconButtonProps } from '@mui/material';
4
- import React from 'react';
5
- import { globalApp } from '../app/ReactApp';
6
-
7
- /**
8
- * Bridge close button props
9
- */
10
- export interface BridgeCloseButtonProps extends IconButtonProps {
11
- /**
12
- * Box props
13
- */
14
- boxProps?: BoxProps;
15
-
16
- /**
17
- * Validate the host
18
- * @param host Host
19
- */
20
- validate?(host: IBridgeHost): boolean;
21
- }
22
-
23
- /**
24
- * Bridge close button
25
- * @param props Props
26
- * @returns Component
27
- */
28
- export function BridgeCloseButton(props: BridgeCloseButtonProps) {
29
- // Destruct
30
- const {
31
- boxProps,
32
- onClick,
33
- title = typeof globalApp === 'undefined'
34
- ? 'Close'
35
- : globalApp.get('close'),
36
- validate,
37
- ...rest
38
- } = props;
39
-
40
- // Host
41
- const host = BridgeUtils.host;
42
-
43
- if (
44
- host == null ||
45
- !host.closable() ||
46
- (validate && validate(host) === false)
47
- ) {
48
- return <React.Fragment />;
49
- }
50
-
51
- // Click handler
52
- const onClickLocal = (event: React.MouseEvent<HTMLButtonElement>) => {
53
- if (onClick) onClick(event);
54
- host.exit();
55
- };
56
-
57
- return (
58
- <Box {...boxProps}>
59
- <IconButton
60
- aria-label="close"
61
- onClick={onClickLocal}
62
- title={title}
63
- {...rest}
64
- >
65
- <CloseIcon />
66
- </IconButton>
67
- </Box>
68
- );
69
- }
@@ -1,32 +0,0 @@
1
- import { Button, ButtonProps } from '@mui/material';
2
- import React from 'react';
3
- import { useNavigate } from 'react-router-dom';
4
- /**
5
- * ButtonLink props
6
- */
7
- export type ButtonLinkProps = Omit<ButtonProps, 'href' | 'onClick'> & {
8
- /**
9
- * To href
10
- */
11
- href: string;
12
- };
13
-
14
- /**
15
- * ButtonLink
16
- * @param props Props
17
- * @returns Component
18
- */
19
- export function ButtonLink(props: ButtonLinkProps) {
20
- // Destruct
21
- const { href, ...rest } = props;
22
-
23
- // Navigate
24
- const navigate = useNavigate();
25
-
26
- const onClick = href.includes('://')
27
- ? () => window.open(href, '_blank')
28
- : () => navigate(href);
29
-
30
- // Layout
31
- return <Button {...rest} onClick={onClick} />;
32
- }
@@ -1,251 +0,0 @@
1
- import {
2
- DataTypes,
3
- IdDefaultType,
4
- Keyboard,
5
- LabelDefaultType,
6
- ListType
7
- } from '@etsoo/shared';
8
- import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
9
- import React from 'react';
10
- import { Utils as SharedUtils } from '@etsoo/shared';
11
- import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
12
- import { InputField } from './InputField';
13
- import { SearchField } from './SearchField';
14
- import { ReactUtils } from '../app/ReactUtils';
15
-
16
- /**
17
- * ComboBox props
18
- */
19
- export type ComboBoxProps<
20
- T extends object,
21
- D extends DataTypes.Keys<T>,
22
- L extends DataTypes.Keys<T, string>
23
- > = AutocompleteExtendedProps<T, D> & {
24
- /**
25
- * Auto add blank item
26
- */
27
- autoAddBlankItem?: boolean;
28
-
29
- /**
30
- * Data readonly
31
- */
32
- dataReadonly?: boolean;
33
-
34
- /**
35
- * Label field
36
- */
37
- labelField?: L;
38
-
39
- /**
40
- * Load data callback
41
- */
42
- loadData?: () => PromiseLike<T[] | null | undefined>;
43
-
44
- /**
45
- * On load data handler
46
- */
47
- onLoadData?: (options: T[]) => void;
48
-
49
- /**
50
- * Array of options.
51
- */
52
- options?: ReadonlyArray<T>;
53
- };
54
-
55
- /**
56
- * ComboBox
57
- * @param props Props
58
- * @returns Component
59
- */
60
- export function ComboBox<
61
- T extends object = ListType,
62
- D extends DataTypes.Keys<T> = IdDefaultType<T>,
63
- L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
64
- >(props: ComboBoxProps<T, D, L>) {
65
- // Destruct
66
- const {
67
- search = false,
68
- autoAddBlankItem = search,
69
- idField = 'id' as D,
70
- idValue,
71
- inputError,
72
- inputHelperText,
73
- inputMargin,
74
- inputOnChange,
75
- inputRequired,
76
- inputVariant,
77
- defaultValue,
78
- label,
79
- labelField = 'label' as L,
80
- loadData,
81
- onLoadData,
82
- name,
83
- inputAutoComplete = 'off',
84
- options,
85
- dataReadonly = true,
86
- readOnly,
87
- onChange,
88
- openOnFocus = true,
89
- value,
90
- getOptionLabel = (option: T) => `${option[labelField]}`,
91
- sx = { minWidth: '150px' },
92
- ...rest
93
- } = props;
94
-
95
- // Value input ref
96
- const inputRef = React.createRef<HTMLInputElement>();
97
-
98
- // Options state
99
- const [localOptions, setOptions] = React.useState(options ?? []);
100
- const isMounted = React.useRef(true);
101
-
102
- // When options change
103
- // [options] will cause infinite loop
104
- const propertyWay = loadData == null;
105
- React.useEffect(() => {
106
- if (propertyWay && options != null) setOptions(options);
107
- }, [JSON.stringify(options), propertyWay]);
108
-
109
- // Local default value
110
- let localValue =
111
- idValue != null
112
- ? localOptions.find((o) => o[idField] === idValue)
113
- : defaultValue ?? value;
114
-
115
- if (localValue === undefined) localValue = null;
116
-
117
- // State
118
- // null for controlled
119
- const [stateValue, setStateValue] = React.useState<T | null>(null);
120
-
121
- // Current id value
122
- // One time calculation for input's default value (uncontrolled)
123
- const localIdValue = stateValue && stateValue[idField];
124
-
125
- React.useEffect(() => {
126
- if (localValue != null) setStateValue(localValue);
127
- }, [localValue]);
128
-
129
- // Add readOnly
130
- const addReadOnly = (params: AutocompleteRenderInputParams) => {
131
- if (readOnly != null) {
132
- Object.assign(params, { readOnly });
133
-
134
- if (readOnly) {
135
- Object.assign(params.inputProps, { 'data-reset': true });
136
- }
137
- }
138
-
139
- if (dataReadonly) {
140
- params.inputProps.onKeyDown = (event) => {
141
- if (Keyboard.isTypingContent(event.key)) {
142
- event.preventDefault();
143
- }
144
- };
145
- }
146
-
147
- // https://stackoverflow.com/questions/15738259/disabling-chrome-autofill
148
- // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html
149
- Object.assign(params.inputProps, { autoComplete: inputAutoComplete });
150
-
151
- return params;
152
- };
153
-
154
- const setInputValue = (value: T | null) => {
155
- // Set state
156
- setStateValue(value);
157
-
158
- // Input value
159
- const input = inputRef.current;
160
- if (input) {
161
- // Update value
162
- const newValue = value != null ? `${value[idField]}` : '';
163
-
164
- if (newValue !== input.value) {
165
- // Different value, trigger change event
166
- ReactUtils.triggerChange(input, newValue, false);
167
- }
168
- }
169
- };
170
-
171
- // When value change
172
- React.useEffect(() => {
173
- if (loadData) {
174
- loadData().then((result) => {
175
- if (result == null || !isMounted.current) return;
176
- if (onLoadData) onLoadData(result);
177
- if (autoAddBlankItem) {
178
- SharedUtils.addBlankItem(result, idField, labelField);
179
- }
180
- setOptions(result);
181
- });
182
- }
183
- }, [localValue]);
184
-
185
- React.useEffect(() => {
186
- return () => {
187
- isMounted.current = false;
188
- };
189
- }, []);
190
-
191
- // Layout
192
- return (
193
- <div>
194
- <input
195
- ref={inputRef}
196
- data-reset="true"
197
- type="text"
198
- style={{ display: 'none' }}
199
- name={name}
200
- value={`${localIdValue ?? ''}`}
201
- readOnly
202
- onChange={inputOnChange}
203
- />
204
- {/* Previous input will reset first with "disableClearable = false", next input trigger change works */}
205
- <Autocomplete<T, undefined, false, false>
206
- value={stateValue}
207
- getOptionLabel={getOptionLabel}
208
- isOptionEqualToValue={(option: T, value: T) =>
209
- option[idField] === value[idField]
210
- }
211
- onChange={(event, value, reason, details) => {
212
- // Set value
213
- setInputValue(value);
214
-
215
- // Custom
216
- if (onChange != null)
217
- onChange(event, value, reason, details);
218
- }}
219
- openOnFocus={openOnFocus}
220
- sx={sx}
221
- renderInput={(params) =>
222
- search ? (
223
- <SearchField
224
- {...addReadOnly(params)}
225
- label={label}
226
- name={name + 'Input'}
227
- margin={inputMargin}
228
- variant={inputVariant}
229
- required={inputRequired}
230
- error={inputError}
231
- helperText={inputHelperText}
232
- />
233
- ) : (
234
- <InputField
235
- {...addReadOnly(params)}
236
- label={label}
237
- name={name + 'Input'}
238
- margin={inputMargin}
239
- variant={inputVariant}
240
- required={inputRequired}
241
- error={inputError}
242
- helperText={inputHelperText}
243
- />
244
- )
245
- }
246
- options={localOptions}
247
- {...rest}
248
- />
249
- </div>
250
- );
251
- }
@@ -1,119 +0,0 @@
1
- import { Button, ButtonProps, CircularProgress } from '@mui/material';
2
- import React from 'react';
3
-
4
- /**
5
- * Countdown button action
6
- */
7
- export interface CountdownButtonAction {
8
- (): Promise<number>;
9
- }
10
-
11
- /**
12
- * Countdown button props
13
- */
14
- export type CountdownButtonProps = Omit<ButtonProps, 'endIcon' | 'disabled'> & {
15
- /**
16
- * Action, required
17
- */
18
- onAction: CountdownButtonAction;
19
- };
20
-
21
- /**
22
- * Countdown button
23
- * @param props Props
24
- * @returns Button
25
- */
26
- export const CountdownButton = React.forwardRef<
27
- HTMLButtonElement,
28
- CountdownButtonProps
29
- >((props, ref) => {
30
- // Destructure
31
- const { onAction, onClick, ...rest } = props;
32
-
33
- // State
34
- // 0 - normal
35
- // 1 - loading
36
- // 2 - countdown
37
- const [state, updateState] = React.useState(0);
38
-
39
- // Ignore seconds
40
- const seconds = 2;
41
-
42
- // Countdown length
43
- const [shared] = React.useState({ maxLength: 0 });
44
-
45
- const isMounted = React.useRef(true);
46
-
47
- // endIcon
48
- let endIcon: React.ReactNode;
49
- if (state === 0) {
50
- endIcon = undefined;
51
- } else if (state === 1) {
52
- endIcon = <CircularProgress size={12} />;
53
- } else {
54
- const countdown = (state - seconds)
55
- .toString()
56
- .padStart(shared.maxLength, '0');
57
- endIcon = <span style={{ fontSize: 'smaller' }}>{countdown}</span>;
58
- }
59
-
60
- // Disabled?
61
- const disabled = state > 0;
62
-
63
- // Action
64
- const doAction = (result: number) => {
65
- // Seconds to wait, 120
66
- if (result > seconds) {
67
- // Here 122
68
- result += seconds;
69
- updateState(result);
70
-
71
- // Update max length
72
- shared.maxLength = result.toString().length;
73
-
74
- const seed = setInterval(() => {
75
- // Mounted?
76
- if (!isMounted.current) return;
77
-
78
- // Last 1 second and then complete
79
- if (result > seconds + 1) {
80
- result--;
81
- updateState(result);
82
- } else {
83
- clearInterval(seed);
84
- updateState(0);
85
- }
86
- }, 1000);
87
- } else {
88
- updateState(0);
89
- }
90
- };
91
-
92
- // Local click
93
- const localClick = (event: React.MouseEvent<HTMLButtonElement>) => {
94
- // Show loading
95
- updateState(1);
96
-
97
- // Callback
98
- if (onClick != null) onClick(event);
99
-
100
- // Return any countdown
101
- onAction().then(doAction);
102
- };
103
-
104
- React.useEffect(() => {
105
- return () => {
106
- isMounted.current = false;
107
- };
108
- }, []);
109
-
110
- return (
111
- <Button
112
- disabled={disabled}
113
- endIcon={endIcon}
114
- onClick={localClick}
115
- ref={ref}
116
- {...rest}
117
- />
118
- );
119
- });
@@ -1,32 +0,0 @@
1
- import { FabPropsColorOverrides, PropTypes } from '@mui/material';
2
- import { OverridableStringUnion } from '@mui/types';
3
-
4
- /**
5
- * Custom fab size
6
- */
7
- export type CustomFabSize = 'small' | 'medium' | 'large';
8
-
9
- /**
10
- * Custom fab props
11
- */
12
- export interface CustomFabProps {
13
- /**
14
- * Color
15
- */
16
- color?: OverridableStringUnion<PropTypes.Color, FabPropsColorOverrides>;
17
-
18
- /**
19
- * Fab size
20
- */
21
- size?: CustomFabSize;
22
-
23
- /**
24
- * Scroll target
25
- */
26
- target?: any;
27
-
28
- /**
29
- * Fab title
30
- */
31
- title?: string;
32
- }