@etsoo/materialui 1.0.1

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 (250) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.json +38 -0
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/main.yml +48 -0
  5. package/.prettierignore +5 -0
  6. package/.prettierrc +6 -0
  7. package/LICENSE +21 -0
  8. package/README.md +16 -0
  9. package/__tests__/ComboBox.tsx +30 -0
  10. package/__tests__/MUGlobalTests.tsx +58 -0
  11. package/__tests__/NotifierMUTests.tsx +217 -0
  12. package/__tests__/SelectEx.tsx +26 -0
  13. package/__tests__/tsconfig.json +19 -0
  14. package/babel.config.json +11 -0
  15. package/lib/AuditDisplay.d.ts +33 -0
  16. package/lib/AuditDisplay.js +52 -0
  17. package/lib/AutocompleteExtendedProps.d.ts +64 -0
  18. package/lib/AutocompleteExtendedProps.js +1 -0
  19. package/lib/BackButton.d.ts +13 -0
  20. package/lib/BackButton.js +33 -0
  21. package/lib/BridgeCloseButton.d.ts +23 -0
  22. package/lib/BridgeCloseButton.js +32 -0
  23. package/lib/ButtonLink.d.ts +17 -0
  24. package/lib/ButtonLink.js +19 -0
  25. package/lib/ComboBox.d.ts +38 -0
  26. package/lib/ComboBox.js +108 -0
  27. package/lib/CountdownButton.d.ts +23 -0
  28. package/lib/CountdownButton.js +81 -0
  29. package/lib/CustomFabProps.d.ts +27 -0
  30. package/lib/CustomFabProps.js +1 -0
  31. package/lib/DataGridEx.d.ts +94 -0
  32. package/lib/DataGridEx.js +329 -0
  33. package/lib/DataGridRenderers.d.ts +22 -0
  34. package/lib/DataGridRenderers.js +99 -0
  35. package/lib/DialogButton.d.ts +54 -0
  36. package/lib/DialogButton.js +45 -0
  37. package/lib/DnDList.d.ts +87 -0
  38. package/lib/DnDList.js +153 -0
  39. package/lib/DraggablePaperComponent.d.ts +8 -0
  40. package/lib/DraggablePaperComponent.js +12 -0
  41. package/lib/EmailInput.d.ts +11 -0
  42. package/lib/EmailInput.js +15 -0
  43. package/lib/FabBox.d.ts +21 -0
  44. package/lib/FabBox.js +31 -0
  45. package/lib/FlexBox.d.ts +14 -0
  46. package/lib/FlexBox.js +18 -0
  47. package/lib/GridDataFormat.d.ts +10 -0
  48. package/lib/GridDataFormat.js +43 -0
  49. package/lib/IconButtonLink.d.ts +17 -0
  50. package/lib/IconButtonLink.js +16 -0
  51. package/lib/InputField.d.ts +21 -0
  52. package/lib/InputField.js +39 -0
  53. package/lib/ItemList.d.ts +56 -0
  54. package/lib/ItemList.js +69 -0
  55. package/lib/ListItemRightIcon.d.ts +4 -0
  56. package/lib/ListItemRightIcon.js +8 -0
  57. package/lib/ListMoreDisplay.d.ts +35 -0
  58. package/lib/ListMoreDisplay.js +99 -0
  59. package/lib/LoadingButton.d.ts +16 -0
  60. package/lib/LoadingButton.js +41 -0
  61. package/lib/MUGlobal.d.ts +102 -0
  62. package/lib/MUGlobal.js +184 -0
  63. package/lib/MaskInput.d.ts +34 -0
  64. package/lib/MaskInput.js +43 -0
  65. package/lib/MobileListItemRenderer.d.ts +17 -0
  66. package/lib/MobileListItemRenderer.js +35 -0
  67. package/lib/MoreFab.d.ts +45 -0
  68. package/lib/MoreFab.js +95 -0
  69. package/lib/NotifierMU.d.ts +47 -0
  70. package/lib/NotifierMU.js +387 -0
  71. package/lib/NotifierPromptProps.d.ts +22 -0
  72. package/lib/NotifierPromptProps.js +1 -0
  73. package/lib/OptionGroup.d.ts +58 -0
  74. package/lib/OptionGroup.js +81 -0
  75. package/lib/PList.d.ts +15 -0
  76. package/lib/PList.js +12 -0
  77. package/lib/ProgressCount.d.ts +44 -0
  78. package/lib/ProgressCount.js +79 -0
  79. package/lib/PullToRefreshUI.d.ts +9 -0
  80. package/lib/PullToRefreshUI.js +18 -0
  81. package/lib/RLink.d.ts +14 -0
  82. package/lib/RLink.js +37 -0
  83. package/lib/ResponsibleContainer.d.ts +87 -0
  84. package/lib/ResponsibleContainer.js +156 -0
  85. package/lib/ScrollTopFab.d.ts +7 -0
  86. package/lib/ScrollTopFab.js +25 -0
  87. package/lib/ScrollerListEx.d.ts +81 -0
  88. package/lib/ScrollerListEx.js +167 -0
  89. package/lib/SearchBar.d.ts +29 -0
  90. package/lib/SearchBar.js +260 -0
  91. package/lib/SearchField.d.ts +21 -0
  92. package/lib/SearchField.js +39 -0
  93. package/lib/SearchOptionGroup.d.ts +9 -0
  94. package/lib/SearchOptionGroup.js +14 -0
  95. package/lib/SelectBool.d.ts +13 -0
  96. package/lib/SelectBool.js +22 -0
  97. package/lib/SelectEx.d.ts +50 -0
  98. package/lib/SelectEx.js +156 -0
  99. package/lib/ShowDataComparison.d.ts +20 -0
  100. package/lib/ShowDataComparison.js +58 -0
  101. package/lib/Switch.d.ts +29 -0
  102. package/lib/Switch.js +34 -0
  103. package/lib/SwitchAnt.d.ts +25 -0
  104. package/lib/SwitchAnt.js +40 -0
  105. package/lib/TabBox.d.ts +54 -0
  106. package/lib/TabBox.js +31 -0
  107. package/lib/TableEx.d.ts +65 -0
  108. package/lib/TableEx.js +270 -0
  109. package/lib/TextFieldEx.d.ts +101 -0
  110. package/lib/TextFieldEx.js +126 -0
  111. package/lib/Tiplist.d.ts +18 -0
  112. package/lib/Tiplist.js +157 -0
  113. package/lib/TooltipClick.d.ts +15 -0
  114. package/lib/TooltipClick.js +40 -0
  115. package/lib/UserAvatar.d.ts +24 -0
  116. package/lib/UserAvatar.js +25 -0
  117. package/lib/UserAvatarEditor.d.ts +53 -0
  118. package/lib/UserAvatarEditor.js +129 -0
  119. package/lib/app/CommonApp.d.ts +38 -0
  120. package/lib/app/CommonApp.js +149 -0
  121. package/lib/app/IServiceAppSettings.d.ts +11 -0
  122. package/lib/app/IServiceAppSettings.js +1 -0
  123. package/lib/app/IServicePage.d.ts +6 -0
  124. package/lib/app/IServicePage.js +1 -0
  125. package/lib/app/IServiceUser.d.ts +14 -0
  126. package/lib/app/IServiceUser.js +1 -0
  127. package/lib/app/ISmartERPUser.d.ts +14 -0
  128. package/lib/app/ISmartERPUser.js +1 -0
  129. package/lib/app/Labels.d.ts +65 -0
  130. package/lib/app/Labels.js +62 -0
  131. package/lib/app/ReactApp.d.ts +195 -0
  132. package/lib/app/ReactApp.js +296 -0
  133. package/lib/app/ServiceApp.d.ts +78 -0
  134. package/lib/app/ServiceApp.js +244 -0
  135. package/lib/index.d.ts +74 -0
  136. package/lib/index.js +74 -0
  137. package/lib/pages/CommonPage.d.ts +11 -0
  138. package/lib/pages/CommonPage.js +60 -0
  139. package/lib/pages/CommonPageProps.d.ts +59 -0
  140. package/lib/pages/CommonPageProps.js +1 -0
  141. package/lib/pages/DataGridPage.d.ts +9 -0
  142. package/lib/pages/DataGridPage.js +79 -0
  143. package/lib/pages/DataGridPageProps.d.ts +17 -0
  144. package/lib/pages/DataGridPageProps.js +1 -0
  145. package/lib/pages/EditPage.d.ts +33 -0
  146. package/lib/pages/EditPage.js +29 -0
  147. package/lib/pages/FixedListPage.d.ts +15 -0
  148. package/lib/pages/FixedListPage.js +70 -0
  149. package/lib/pages/ListPage.d.ts +9 -0
  150. package/lib/pages/ListPage.js +50 -0
  151. package/lib/pages/ListPageProps.d.ts +7 -0
  152. package/lib/pages/ListPageProps.js +1 -0
  153. package/lib/pages/ResponsivePage.d.ts +9 -0
  154. package/lib/pages/ResponsivePage.js +45 -0
  155. package/lib/pages/ResponsivePageProps.d.ts +39 -0
  156. package/lib/pages/ResponsivePageProps.js +1 -0
  157. package/lib/pages/SearchPageProps.d.ts +30 -0
  158. package/lib/pages/SearchPageProps.js +1 -0
  159. package/lib/pages/TablePage.d.ts +9 -0
  160. package/lib/pages/TablePage.js +69 -0
  161. package/lib/pages/TablePageProps.d.ts +7 -0
  162. package/lib/pages/TablePageProps.js +1 -0
  163. package/lib/pages/ViewPage.d.ts +66 -0
  164. package/lib/pages/ViewPage.js +105 -0
  165. package/lib/texts/DateText.d.ts +34 -0
  166. package/lib/texts/DateText.js +25 -0
  167. package/lib/texts/MoneyText.d.ts +21 -0
  168. package/lib/texts/MoneyText.js +14 -0
  169. package/lib/texts/NumberText.d.ts +25 -0
  170. package/lib/texts/NumberText.js +14 -0
  171. package/package.json +97 -0
  172. package/src/AuditDisplay.tsx +114 -0
  173. package/src/AutocompleteExtendedProps.ts +83 -0
  174. package/src/BackButton.tsx +55 -0
  175. package/src/BridgeCloseButton.tsx +69 -0
  176. package/src/ButtonLink.tsx +32 -0
  177. package/src/ComboBox.tsx +251 -0
  178. package/src/CountdownButton.tsx +119 -0
  179. package/src/CustomFabProps.ts +32 -0
  180. package/src/DataGridEx.tsx +713 -0
  181. package/src/DataGridRenderers.tsx +140 -0
  182. package/src/DialogButton.tsx +163 -0
  183. package/src/DnDList.tsx +344 -0
  184. package/src/DraggablePaperComponent.tsx +19 -0
  185. package/src/EmailInput.tsx +24 -0
  186. package/src/FabBox.tsx +51 -0
  187. package/src/FlexBox.tsx +20 -0
  188. package/src/GridDataFormat.tsx +77 -0
  189. package/src/IconButtonLink.tsx +29 -0
  190. package/src/InputField.tsx +82 -0
  191. package/src/ItemList.tsx +204 -0
  192. package/src/ListItemRightIcon.tsx +9 -0
  193. package/src/ListMoreDisplay.tsx +205 -0
  194. package/src/LoadingButton.tsx +75 -0
  195. package/src/MUGlobal.ts +220 -0
  196. package/src/MaskInput.tsx +107 -0
  197. package/src/MobileListItemRenderer.tsx +79 -0
  198. package/src/MoreFab.tsx +211 -0
  199. package/src/NotifierMU.tsx +654 -0
  200. package/src/NotifierPromptProps.ts +24 -0
  201. package/src/OptionGroup.tsx +223 -0
  202. package/src/PList.tsx +27 -0
  203. package/src/ProgressCount.tsx +166 -0
  204. package/src/PullToRefreshUI.tsx +21 -0
  205. package/src/RLink.tsx +64 -0
  206. package/src/ResponsibleContainer.tsx +394 -0
  207. package/src/ScrollTopFab.tsx +34 -0
  208. package/src/ScrollerListEx.tsx +387 -0
  209. package/src/SearchBar.tsx +396 -0
  210. package/src/SearchField.tsx +82 -0
  211. package/src/SearchOptionGroup.tsx +31 -0
  212. package/src/SelectBool.tsx +33 -0
  213. package/src/SelectEx.tsx +290 -0
  214. package/src/ShowDataComparison.tsx +106 -0
  215. package/src/Switch.tsx +94 -0
  216. package/src/SwitchAnt.tsx +95 -0
  217. package/src/TabBox.tsx +118 -0
  218. package/src/TableEx.tsx +558 -0
  219. package/src/TextFieldEx.tsx +249 -0
  220. package/src/Tiplist.tsx +303 -0
  221. package/src/TooltipClick.tsx +84 -0
  222. package/src/UserAvatar.tsx +64 -0
  223. package/src/UserAvatarEditor.tsx +287 -0
  224. package/src/app/CommonApp.ts +223 -0
  225. package/src/app/IServiceAppSettings.ts +13 -0
  226. package/src/app/IServicePage.ts +6 -0
  227. package/src/app/IServiceUser.ts +17 -0
  228. package/src/app/ISmartERPUser.ts +16 -0
  229. package/src/app/Labels.ts +77 -0
  230. package/src/app/ReactApp.ts +504 -0
  231. package/src/app/ServiceApp.ts +352 -0
  232. package/src/index.ts +77 -0
  233. package/src/pages/CommonPage.tsx +128 -0
  234. package/src/pages/CommonPageProps.ts +70 -0
  235. package/src/pages/DataGridPage.tsx +140 -0
  236. package/src/pages/DataGridPageProps.ts +24 -0
  237. package/src/pages/EditPage.tsx +114 -0
  238. package/src/pages/FixedListPage.tsx +141 -0
  239. package/src/pages/ListPage.tsx +90 -0
  240. package/src/pages/ListPageProps.ts +12 -0
  241. package/src/pages/ResponsivePage.tsx +68 -0
  242. package/src/pages/ResponsivePageProps.ts +57 -0
  243. package/src/pages/SearchPageProps.ts +39 -0
  244. package/src/pages/TablePage.tsx +126 -0
  245. package/src/pages/TablePageProps.ts +12 -0
  246. package/src/pages/ViewPage.tsx +282 -0
  247. package/src/texts/DateText.tsx +74 -0
  248. package/src/texts/MoneyText.tsx +49 -0
  249. package/src/texts/NumberText.tsx +40 -0
  250. package/tsconfig.json +19 -0
@@ -0,0 +1,32 @@
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
+ }
@@ -0,0 +1,251 @@
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 '@etsoo/react';
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
+ }
@@ -0,0 +1,119 @@
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
+ });
@@ -0,0 +1,32 @@
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
+ }