@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,387 +0,0 @@
1
- import { css } from '@emotion/css';
2
- import { DataTypes, IdDefaultType, Utils } from '@etsoo/shared';
3
- import { useTheme } from '@mui/material';
4
- import React from 'react';
5
- import { ListChildComponentProps } from 'react-window';
6
- import { ScrollerList, ScrollerListProps } from '../components/ScrollerList';
7
- import { MouseEventWithDataHandler, MUGlobal } from './MUGlobal';
8
-
9
- // Scroll bar size
10
- const scrollbarSize = 16;
11
-
12
- // Selected class name
13
- const selectedClassName = 'ScrollerListEx-Selected';
14
-
15
- const createGridStyle = (
16
- alternatingColors: [string?, string?],
17
- selectedColor: string
18
- ) => {
19
- return css({
20
- '& .ScrollerListEx-Selected': {
21
- backgroundColor: selectedColor
22
- },
23
- '& .ScrollerListEx-Row0:not(.ScrollerListEx-Selected)': {
24
- backgroundColor: alternatingColors[0]
25
- },
26
- '& .ScrollerListEx-Row1:not(.ScrollerListEx-Selected)': {
27
- backgroundColor: alternatingColors[1]
28
- },
29
- '@media (min-width: 800px)': {
30
- '::-webkit-scrollbar': {
31
- width: scrollbarSize,
32
- height: scrollbarSize,
33
- backgroundColor: '#f6f6f6'
34
- },
35
- '::-webkit-scrollbar-thumb': {
36
- backgroundColor: 'rgba(0,0,0,0.4)',
37
- borderRadius: '2px'
38
- },
39
- '::-webkit-scrollbar-track-piece:start': {
40
- background: 'transparent'
41
- },
42
- '::-webkit-scrollbar-track-piece:end': {
43
- background: 'transparent'
44
- }
45
- }
46
- });
47
- };
48
-
49
- // Default margin
50
- const defaultMargin = (margin: object, isNarrow?: boolean) => {
51
- const half = MUGlobal.half(margin);
52
-
53
- if (isNarrow == null) {
54
- const half = MUGlobal.half(margin);
55
- return {
56
- marginLeft: margin,
57
- marginRight: margin,
58
- marginTop: half,
59
- marginBottom: half
60
- };
61
- }
62
-
63
- if (isNarrow) {
64
- return {
65
- marginLeft: 0,
66
- marginRight: 0,
67
- marginTop: half,
68
- marginBottom: half
69
- };
70
- }
71
-
72
- return {
73
- marginLeft: half,
74
- marginRight: half,
75
- marginTop: half,
76
- marginBottom: half
77
- };
78
- };
79
-
80
- /**
81
- * Extended ScrollerList inner item renderer props
82
- */
83
- export interface ScrollerListExInnerItemRendererProps<T>
84
- extends ListChildComponentProps<T> {
85
- /**
86
- * Item selected
87
- */
88
- selected: boolean;
89
-
90
- /**
91
- * Item height
92
- */
93
- itemHeight: number;
94
-
95
- /**
96
- * Item space
97
- */
98
- space: number;
99
-
100
- /**
101
- * Default margins
102
- */
103
- margins: object;
104
- }
105
-
106
- /**
107
- * Extended ScrollerList ItemSize type
108
- * 1. Callback function
109
- * 2. Static sets
110
- * 3. Dynamic calculation
111
- */
112
- export type ScrollerListExItemSize =
113
- | ((index: number) => [number, number] | [number, number, object])
114
- | [number, number]
115
- | [number, object, boolean?];
116
-
117
- /**
118
- * Extended ScrollerList Props
119
- */
120
- export type ScrollerListExProps<
121
- T extends object,
122
- D extends DataTypes.Keys<T>
123
- > = Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> & {
124
- /**
125
- * Alternating colors for odd/even rows
126
- */
127
- alternatingColors?: [string?, string?];
128
-
129
- /**
130
- * Inner item renderer
131
- */
132
- innerItemRenderer: (
133
- props: ScrollerListExInnerItemRendererProps<T>
134
- ) => React.ReactNode;
135
-
136
- /**
137
- * Item renderer
138
- */
139
- itemRenderer?: (props: ListChildComponentProps<T>) => React.ReactElement;
140
-
141
- /**
142
- * Id field
143
- * Failed: D extends { id: DataTypes.IdType } ? { idField?: D } : { idField: D }
144
- */
145
- idField?: D;
146
-
147
- /**
148
- * Item size, a function indicates its a variable size list
149
- */
150
- itemSize: ScrollerListExItemSize;
151
-
152
- /**
153
- * Double click handler
154
- */
155
- onDoubleClick?: MouseEventWithDataHandler<T>;
156
-
157
- /**
158
- * Click handler
159
- */
160
- onClick?: MouseEventWithDataHandler<T>;
161
-
162
- /**
163
- * On items select change
164
- */
165
- onSelectChange?: (selectedItems: T[]) => void;
166
-
167
- /**
168
- * Selected color
169
- */
170
- selectedColor?: string;
171
- };
172
-
173
- interface defaultItemRendererProps<T> extends ListChildComponentProps<T> {
174
- /**
175
- * onMouseDown callback
176
- */
177
- onMouseDown: (div: HTMLDivElement, data: T) => void;
178
-
179
- /**
180
- * Inner item renderer
181
- */
182
- innerItemRenderer: (
183
- props: ScrollerListExInnerItemRendererProps<T>
184
- ) => React.ReactNode;
185
-
186
- /**
187
- * Item height
188
- */
189
- itemHeight: number;
190
-
191
- /**
192
- * Double click handler
193
- */
194
- onDoubleClick?: MouseEventWithDataHandler<T>;
195
-
196
- /**
197
- * Click handler
198
- */
199
- onClick?: MouseEventWithDataHandler<T>;
200
-
201
- /**
202
- * Item space
203
- */
204
- space: number;
205
-
206
- /**
207
- * Default margins
208
- */
209
- margins: object;
210
-
211
- /**
212
- * Item selected
213
- */
214
- selected: boolean;
215
- }
216
-
217
- // Default itemRenderer
218
- function defaultItemRenderer<T>({
219
- index,
220
- innerItemRenderer,
221
- data,
222
- onMouseDown,
223
- selected,
224
- style,
225
- itemHeight,
226
- onClick,
227
- onDoubleClick,
228
- space,
229
- margins
230
- }: defaultItemRendererProps<T>) {
231
- // Child
232
- const child = innerItemRenderer({
233
- index,
234
- data,
235
- style,
236
- selected,
237
- itemHeight,
238
- space,
239
- margins
240
- });
241
-
242
- let rowClass = `ScrollerListEx-Row${index % 2}`;
243
- if (selected) rowClass += ` ${selectedClassName}`;
244
-
245
- // Layout
246
- return (
247
- <div
248
- className={rowClass}
249
- style={style}
250
- onMouseDown={(event) => onMouseDown(event.currentTarget, data)}
251
- onClick={(event) => onClick && onClick(event, data)}
252
- onDoubleClick={(event) =>
253
- onDoubleClick && onDoubleClick(event, data)
254
- }
255
- >
256
- {child}
257
- </div>
258
- );
259
- }
260
-
261
- /**
262
- * Extended ScrollerList
263
- * @param props Props
264
- * @returns Component
265
- */
266
- export function ScrollerListEx<
267
- T extends object,
268
- D extends DataTypes.Keys<T> = IdDefaultType<T>
269
- >(props: ScrollerListExProps<T, D>) {
270
- // Selected item ref
271
- const selectedItem = React.useRef<[HTMLDivElement, T]>();
272
-
273
- const onMouseDown = (div: HTMLDivElement, data: T) => {
274
- // Destruct
275
- const [selectedDiv, selectedData] = selectedItem.current ?? [];
276
-
277
- if (selectedData != null && selectedData[idField] === data[idField])
278
- return;
279
-
280
- selectedDiv?.classList.remove(selectedClassName);
281
-
282
- div.classList.add(selectedClassName);
283
-
284
- selectedItem.current = [div, data];
285
-
286
- if (onSelectChange) onSelectChange([data]);
287
- };
288
-
289
- const isSelected = (data?: T) => {
290
- const [_, selectedData] = selectedItem.current ?? [];
291
- const selected =
292
- selectedData && data && selectedData[idField] === data[idField]
293
- ? true
294
- : false;
295
- return selected;
296
- };
297
-
298
- // Destruct
299
- const {
300
- alternatingColors = [undefined, undefined],
301
- className,
302
- idField = 'id' as D,
303
- innerItemRenderer,
304
- itemSize,
305
- itemKey = (index: number, data: T) =>
306
- DataTypes.getIdValue1(data, idField) ?? index,
307
- itemRenderer = (itemProps) => {
308
- const [itemHeight, space, margins] = calculateItemSize(
309
- itemProps.index
310
- );
311
- return defaultItemRenderer({
312
- itemHeight,
313
- innerItemRenderer,
314
- onMouseDown,
315
- onClick,
316
- onDoubleClick,
317
- space,
318
- margins,
319
- selected: isSelected(itemProps.data),
320
- ...itemProps
321
- });
322
- },
323
- onClick,
324
- onDoubleClick,
325
- onSelectChange,
326
- selectedColor = '#edf4fb',
327
- ...rest
328
- } = props;
329
-
330
- // Theme
331
- const theme = useTheme();
332
-
333
- // Cache calculation
334
- const itemSizeResult = React.useMemo(():
335
- | [number, number, object]
336
- | undefined => {
337
- if (typeof itemSize === 'function') return undefined;
338
- const [size, spaces, isNarrow] = itemSize;
339
- if (typeof spaces === 'number')
340
- return [
341
- size,
342
- spaces,
343
- defaultMargin(MUGlobal.pagePaddings, undefined)
344
- ];
345
-
346
- return [
347
- size,
348
- MUGlobal.getSpace(spaces, theme),
349
- defaultMargin(spaces, isNarrow)
350
- ];
351
- }, [itemSize]);
352
-
353
- // Calculate size
354
- const calculateItemSize = (index: number): [number, number, object] => {
355
- // Callback function
356
- if (typeof itemSize === 'function') {
357
- const result = itemSize(index);
358
- if (result.length == 2)
359
- return [...result, defaultMargin(MUGlobal.pagePaddings)];
360
- return result;
361
- }
362
-
363
- // Calculation
364
- return itemSizeResult!;
365
- };
366
-
367
- // Local item size
368
- const itemSizeLocal = (index: number) => {
369
- const [size, space] = calculateItemSize(index);
370
- return size + space;
371
- };
372
-
373
- // Layout
374
- return (
375
- <ScrollerList<T>
376
- className={Utils.mergeClasses(
377
- 'ScrollerListEx-Body',
378
- className,
379
- createGridStyle(alternatingColors, selectedColor)
380
- )}
381
- itemKey={itemKey}
382
- itemRenderer={itemRenderer}
383
- itemSize={itemSizeLocal}
384
- {...rest}
385
- />
386
- );
387
- }