@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,290 +0,0 @@
1
- import {
2
- Checkbox,
3
- FormControl,
4
- InputLabel,
5
- ListItemText,
6
- MenuItem,
7
- OutlinedInput,
8
- Select,
9
- SelectChangeEvent,
10
- SelectProps
11
- } from '@mui/material';
12
- import React from 'react';
13
- import { MUGlobal } from './MUGlobal';
14
- import { ListItemRightIcon } from './ListItemRightIcon';
15
- import {
16
- DataTypes,
17
- IdDefaultType,
18
- LabelDefaultType,
19
- ListType,
20
- Utils
21
- } from '@etsoo/shared';
22
- import { ReactUtils } from '../app/ReactUtils';
23
-
24
- /**
25
- * Extended select component props
26
- */
27
- export type SelectExProps<
28
- T extends object,
29
- D extends DataTypes.Keys<T> = IdDefaultType<T>,
30
- L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
31
- > = Omit<SelectProps, 'labelId' | 'input' | 'native'> & {
32
- /**
33
- * Auto add blank item
34
- */
35
- autoAddBlankItem?: boolean;
36
-
37
- /**
38
- * Id field
39
- */
40
- idField?: D;
41
-
42
- /**
43
- * Item icon renderer
44
- */
45
- itemIconRenderer?: (id: unknown) => React.ReactNode;
46
-
47
- /**
48
- * Label field
49
- */
50
- labelField?: L | ((option: T) => string);
51
-
52
- /**
53
- * Load data callback
54
- */
55
- loadData?: () => PromiseLike<T[] | null | undefined>;
56
-
57
- /**
58
- * Item click handler
59
- */
60
- onItemClick?: (event: React.MouseEvent, id: unknown) => void;
61
-
62
- /**
63
- * On load data handler
64
- */
65
- onLoadData?: (options: T[]) => void;
66
-
67
- /**
68
- * Array of options.
69
- */
70
- options?: ReadonlyArray<T>;
71
-
72
- /**
73
- * Is search case?
74
- */
75
- search?: boolean;
76
- };
77
-
78
- /**
79
- * Extended select component
80
- * @param props Props
81
- * @returns Component
82
- */
83
- export function SelectEx<
84
- T extends object = ListType,
85
- D extends DataTypes.Keys<T> = IdDefaultType<T>,
86
- L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
87
- >(props: SelectExProps<T, D, L>) {
88
- // Destruct
89
- const {
90
- defaultValue,
91
- idField = 'id' as D,
92
- itemIconRenderer,
93
- label,
94
- labelField = 'label' as L,
95
- loadData,
96
- onItemClick,
97
- onLoadData,
98
- multiple = false,
99
- name,
100
- options = [],
101
- search = false,
102
- autoAddBlankItem = search,
103
- value,
104
- onChange,
105
- fullWidth,
106
- ...rest
107
- } = props;
108
-
109
- // Options state
110
- const [localOptions, setOptions] = React.useState(options);
111
- const isMounted = React.useRef(true);
112
-
113
- // When options change
114
- // [options] will cause infinite loop
115
- const propertyWay = loadData == null;
116
- React.useEffect(() => {
117
- if (propertyWay && options != null) setOptions(options);
118
- }, [JSON.stringify(options), propertyWay]);
119
-
120
- // Local value
121
- const valueSource = defaultValue ?? value ?? '';
122
- let localValue: unknown | unknown[];
123
- if (multiple) {
124
- if (Array.isArray(valueSource)) localValue = valueSource;
125
- else localValue = [valueSource];
126
- } else {
127
- localValue = valueSource;
128
- }
129
-
130
- // Value state
131
- const [valueState, setValueState] = React.useState<unknown>();
132
-
133
- React.useEffect(() => {
134
- if (localValue != null) setValueState(localValue);
135
- }, [localValue]);
136
-
137
- // Label id
138
- const labelId = `selectex-label-${name}`;
139
-
140
- // Item checked or not
141
- const itemChecked = (id: unknown) => {
142
- if (Array.isArray(valueState)) return valueState.indexOf(id) !== -1;
143
- return valueState === id;
144
- };
145
-
146
- // Change handler
147
- const handleChange = (event: SelectChangeEvent<unknown>) => {
148
- const value = event.target.value;
149
- if (multiple && !Array.isArray(value)) setItemValue([value]);
150
- else setItemValue(value);
151
- };
152
-
153
- // Set item
154
- const setItemValue = (id: unknown) => {
155
- if (id != valueState) {
156
- setValueState(id);
157
-
158
- const input = divRef.current?.querySelector('input');
159
- if (input) {
160
- // Different value, trigger change event
161
- ReactUtils.triggerChange(input, id as string, false);
162
- }
163
- }
164
- };
165
-
166
- // Get option id
167
- const getId = (option: T) => {
168
- return option[idField] as unknown as React.Key;
169
- };
170
-
171
- // Get option label
172
- const getLabel = (option: T) => {
173
- return typeof labelField === 'function'
174
- ? labelField(option)
175
- : new String(option[labelField]);
176
- };
177
-
178
- // Refs
179
- const divRef = React.useRef<HTMLDivElement>();
180
-
181
- // When value change
182
- React.useEffect(() => {
183
- if (loadData) {
184
- loadData().then((result) => {
185
- if (result == null || !isMounted.current) return;
186
- if (onLoadData) onLoadData(result);
187
- if (autoAddBlankItem) {
188
- Utils.addBlankItem(result, idField, labelField);
189
- }
190
- setOptions(result);
191
- });
192
- }
193
- }, [localValue]);
194
-
195
- // When layout ready
196
- React.useEffect(() => {
197
- const input = divRef.current?.querySelector('input');
198
- const inputChange = (event: Event) => {
199
- // Reset case
200
- if (event.cancelable) setValueState(multiple ? [] : '');
201
- };
202
- input?.addEventListener('change', inputChange);
203
-
204
- return () => {
205
- isMounted.current = false;
206
- input?.removeEventListener('change', inputChange);
207
- };
208
- }, []);
209
-
210
- // Layout
211
- return (
212
- <FormControl
213
- size={search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize}
214
- fullWidth={fullWidth}
215
- >
216
- <InputLabel
217
- id={labelId}
218
- shrink={
219
- search
220
- ? MUGlobal.searchFieldShrink
221
- : MUGlobal.inputFieldShrink
222
- }
223
- >
224
- {label}
225
- </InputLabel>
226
- <Select
227
- ref={divRef}
228
- value={
229
- localOptions.some((option) => itemChecked(getId(option)))
230
- ? valueState ?? ''
231
- : ''
232
- }
233
- input={<OutlinedInput notched label={label} />}
234
- labelId={labelId}
235
- name={name}
236
- multiple={multiple}
237
- onChange={(event, child) => {
238
- if (onChange) onChange(event, child);
239
- if (multiple) handleChange(event);
240
- }}
241
- renderValue={(selected) => {
242
- // The text shows up
243
- return localOptions
244
- .filter((option) => {
245
- const id = getId(option);
246
- return Array.isArray(selected)
247
- ? selected.indexOf(id) !== -1
248
- : selected === id;
249
- })
250
- .map((option) => getLabel(option))
251
- .join(', ');
252
- }}
253
- sx={{ minWidth: '150px' }}
254
- fullWidth={fullWidth}
255
- {...rest}
256
- >
257
- {localOptions.map((option) => {
258
- // Option id
259
- const id = getId(option);
260
-
261
- // Option label
262
- const label = getLabel(option);
263
-
264
- // Option
265
- return (
266
- <MenuItem
267
- key={id}
268
- value={id}
269
- onClick={(event) => {
270
- if (onItemClick) {
271
- onItemClick(event, id);
272
- if (event.defaultPrevented) return;
273
- }
274
- if (!multiple) setItemValue(id);
275
- }}
276
- >
277
- {multiple && <Checkbox checked={itemChecked(id)} />}
278
- <ListItemText primary={label} />
279
- {itemIconRenderer && (
280
- <ListItemRightIcon>
281
- {itemIconRenderer(id)}
282
- </ListItemRightIcon>
283
- )}
284
- </MenuItem>
285
- );
286
- })}
287
- </Select>
288
- </FormControl>
289
- );
290
- }
package/src/mu/Switch.tsx DELETED
@@ -1,94 +0,0 @@
1
- import React from 'react';
2
- import { FormControlLabel, FormControlLabelProps } from '@mui/material';
3
- import MuiCheckbox from '@mui/material/Checkbox';
4
- import MuiSwitch from '@mui/material/Switch';
5
-
6
- /**
7
- * Switch props
8
- */
9
- export interface SwitchProps extends Omit<FormControlLabelProps, 'control'> {
10
- /**
11
- * Value, default 'on'
12
- */
13
- value?: string;
14
-
15
- /**
16
- * Is the field read only?
17
- */
18
- readOnly?: boolean;
19
-
20
- /**
21
- * Size
22
- */
23
- size?: 'small' | 'medium';
24
-
25
- /**
26
- * Display as Checkbox
27
- */
28
- checkbox?: boolean;
29
- }
30
-
31
- /**
32
- * Switch
33
- * @param props Props
34
- * @returns Component
35
- */
36
- export function Switch(props: SwitchProps) {
37
- // Destruct
38
- const {
39
- checked,
40
- defaultChecked,
41
- defaultValue,
42
- onChange,
43
- readOnly,
44
- size,
45
- checkbox = false,
46
- value = 'true',
47
- ...rest
48
- } = props;
49
-
50
- // Checked state
51
- const [controlChecked, setControlChecked] = React.useState(
52
- checked ?? defaultChecked ?? defaultValue == value
53
- );
54
-
55
- React.useEffect(() => {
56
- if (checked) setControlChecked(checked);
57
- }, [checked]);
58
-
59
- // Handle change
60
- const handleChange = (
61
- event: React.ChangeEvent<HTMLInputElement>,
62
- checked: boolean
63
- ) => {
64
- if (onChange) onChange(event, checked);
65
- setControlChecked(checked);
66
- };
67
-
68
- // Control
69
- const control = checkbox ? (
70
- <MuiCheckbox
71
- readOnly={readOnly}
72
- checked={controlChecked}
73
- onChange={handleChange}
74
- size={size}
75
- value={value}
76
- />
77
- ) : (
78
- <MuiSwitch
79
- readOnly={readOnly}
80
- checked={controlChecked}
81
- onChange={handleChange}
82
- size={size}
83
- value={value}
84
- />
85
- );
86
-
87
- // Default state
88
- React.useEffect(() => {
89
- setControlChecked(controlChecked);
90
- }, [controlChecked]);
91
-
92
- // Layout
93
- return <FormControlLabel control={control} {...rest} />;
94
- }
@@ -1,95 +0,0 @@
1
- import { Stack, Typography } from '@mui/material';
2
- import Switch, { SwitchProps } from '@mui/material/Switch';
3
- import React from 'react';
4
-
5
- /**
6
- * Ant style switch props
7
- */
8
- export interface SwitchAntProps extends SwitchProps {
9
- /**
10
- *
11
- */
12
- activeColor?: string;
13
-
14
- /**
15
- * Start label
16
- */
17
- startLabel: string;
18
-
19
- /**
20
- * End label
21
- */
22
- endLabel: string;
23
- }
24
-
25
- /**
26
- * Ant style switch
27
- * @param props Props
28
- * @returns Component
29
- */
30
- export function SwitchAnt(props: SwitchAntProps) {
31
- // Destruct
32
- const {
33
- activeColor,
34
- checked,
35
- defaultChecked,
36
- defaultValue,
37
- endLabel,
38
- startLabel,
39
- onChange,
40
- value = 'true',
41
- ...rest
42
- } = props;
43
-
44
- // Checked state
45
- const [controlChecked, setControlChecked] = React.useState(
46
- checked ?? defaultChecked ?? defaultValue == value
47
- );
48
-
49
- React.useEffect(() => {
50
- if (checked) setControlChecked(checked);
51
- }, [checked]);
52
-
53
- // On change
54
- const onChangeLocal = (
55
- event: React.ChangeEvent<HTMLInputElement>,
56
- checked: boolean
57
- ) => {
58
- if (onChange) onChange(event, checked);
59
- setControlChecked(checked);
60
- };
61
-
62
- // Layout
63
- return (
64
- <Stack direction="row" spacing={1} alignItems="center">
65
- <Typography
66
- onClick={() => setControlChecked(false)}
67
- sx={{
68
- cursor: 'pointer',
69
- color: controlChecked
70
- ? undefined
71
- : (theme) => activeColor ?? theme.palette.warning.main
72
- }}
73
- >
74
- {startLabel}
75
- </Typography>
76
- <Switch
77
- checked={controlChecked}
78
- value={value}
79
- onChange={onChangeLocal}
80
- {...rest}
81
- />
82
- <Typography
83
- onClick={() => setControlChecked(true)}
84
- sx={{
85
- cursor: 'pointer',
86
- color: controlChecked
87
- ? (theme) => activeColor ?? theme.palette.warning.main
88
- : undefined
89
- }}
90
- >
91
- {endLabel}
92
- </Typography>
93
- </Stack>
94
- );
95
- }
package/src/mu/TabBox.tsx DELETED
@@ -1,118 +0,0 @@
1
- import { Utils } from '@etsoo/shared';
2
- import { Box, BoxProps, Tab, TabProps, Tabs, TabsProps } from '@mui/material';
3
- import React from 'react';
4
- import { Link } from 'react-router-dom';
5
-
6
- /**
7
- * Tab with box panel props
8
- */
9
- export interface TabBoxPanel extends Omit<TabProps, 'value' | 'children'> {
10
- /**
11
- * Children
12
- */
13
- children?: ((visible: boolean) => React.ReactNode) | React.ReactNode;
14
-
15
- /**
16
- * Panel box props
17
- */
18
- panel?: Omit<BoxProps, 'hidden'>;
19
-
20
- /**
21
- * To URL
22
- */
23
- to?: string;
24
- }
25
-
26
- /**
27
- * Tabs with box props
28
- */
29
- export interface TabBoxPros extends BoxProps {
30
- /**
31
- * Container props
32
- */
33
- container?: Omit<TabsProps, 'value'>;
34
-
35
- /**
36
- * Default selected index
37
- */
38
- defaultIndex?: number;
39
-
40
- /**
41
- * Current index
42
- */
43
- index?: number;
44
-
45
- /**
46
- * Add a hidden input and its name
47
- */
48
- inputName?: string;
49
-
50
- /**
51
- * Root props
52
- */
53
- root?: BoxProps;
54
-
55
- /**
56
- * Tabs
57
- */
58
- tabs: TabBoxPanel[];
59
- }
60
-
61
- /**
62
- * Tabs with box
63
- * @param props Props
64
- * @returns Component
65
- */
66
- export function TabBox(props: TabBoxPros) {
67
- // Destruct
68
- const {
69
- index,
70
- inputName,
71
- root,
72
- container = {},
73
- defaultIndex = 0,
74
- tabs
75
- } = props;
76
- const { onChange, ...rest } = container;
77
-
78
- // State
79
- const [value, setValue] = React.useState(defaultIndex);
80
-
81
- React.useEffect(() => {
82
- if (index == null) return;
83
- setValue(index);
84
- }, [index]);
85
-
86
- // Layout
87
- return (
88
- <React.Fragment>
89
- {inputName && (
90
- <input type="hidden" name={inputName} value={value} />
91
- )}
92
- <Box {...root}>
93
- <Tabs
94
- value={value}
95
- onChange={(event, newValue) => {
96
- setValue(newValue);
97
- if (onChange) onChange(event, newValue);
98
- }}
99
- {...rest}
100
- >
101
- {tabs.map(({ children, panel, ...tabRest }, index) => (
102
- <Tab
103
- key={index}
104
- value={index}
105
- LinkComponent={tabRest.to ? Link : undefined}
106
- {...tabRest}
107
- />
108
- ))}
109
- </Tabs>
110
- </Box>
111
- {tabs.map(({ children, panel }, index) => (
112
- <Box key={index} hidden={value !== index} {...panel}>
113
- {Utils.getResult(children, value === index)}
114
- </Box>
115
- ))}
116
- </React.Fragment>
117
- );
118
- }