@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,712 +0,0 @@
1
- import { css } from '@emotion/css';
2
- import { DataTypes, IdDefaultType, Utils } from '@etsoo/shared';
3
- import {
4
- Box,
5
- BoxProps,
6
- Checkbox,
7
- Paper,
8
- TableSortLabel,
9
- useTheme
10
- } from '@mui/material';
11
- import React from 'react';
12
- import {
13
- GridAlignGet,
14
- GridCellFormatterProps,
15
- GridCellRendererProps,
16
- GridColumn,
17
- GridHeaderCellRendererProps
18
- } from '../components/GridColumn';
19
- import { GridLoaderStates } from '../components/GridLoader';
20
- import {
21
- ScrollerGrid,
22
- ScrollerGridForwardRef,
23
- ScrollerGridItemRendererProps,
24
- ScrollerGridProps
25
- } from '../components/ScrollerGrid';
26
- import useCombinedRefs from '../uses/useCombinedRefs';
27
- import { DataGridRenderers } from './DataGridRenderers';
28
- import { MouseEventWithDataHandler } from './MUGlobal';
29
-
30
- /**
31
- * Footer item renderer props
32
- */
33
- export type DataGridExFooterItemRendererProps<T extends object> = {
34
- column: GridColumn<T>;
35
- index: number;
36
- states: GridLoaderStates<T>;
37
- cellProps: any;
38
- checkable: boolean;
39
- };
40
-
41
- /**
42
- * Extended DataGrid with VariableSizeGrid props
43
- */
44
- export type DataGridExProps<
45
- T extends object,
46
- D extends DataTypes.Keys<T>
47
- > = Omit<
48
- ScrollerGridProps<T, D>,
49
- 'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'
50
- > & {
51
- /**
52
- * Alternating colors for odd/even rows
53
- */
54
- alternatingColors?: [string?, string?];
55
-
56
- /**
57
- * Checkable to choose multiple items
58
- * @default false
59
- */
60
- checkable?: boolean;
61
-
62
- /**
63
- * Rows count to have the bottom border
64
- */
65
- borderRowsCount?: number;
66
-
67
- /**
68
- * Bottom height
69
- */
70
- bottomHeight?: number;
71
-
72
- /**
73
- * Columns
74
- */
75
- columns: GridColumn<T>[];
76
-
77
- /**
78
- * Footer item renderer
79
- */
80
- footerItemRenderer?: (
81
- rows: T[],
82
- props: DataGridExFooterItemRendererProps<T>
83
- ) => React.ReactNode;
84
-
85
- /**
86
- * Header height
87
- * @default 56
88
- */
89
- headerHeight?: number;
90
-
91
- /**
92
- * Hide the footer
93
- * @default false
94
- */
95
- hideFooter?: boolean;
96
-
97
- /**
98
- * Hover color
99
- */
100
- hoverColor?: string;
101
-
102
- /**
103
- * Double click handler
104
- */
105
- onDoubleClick?: MouseEventWithDataHandler<T>;
106
-
107
- /**
108
- * Click handler
109
- */
110
- onClick?: MouseEventWithDataHandler<T>;
111
-
112
- /**
113
- * Selectable to support hover over and out effect and row clickable
114
- * @default true
115
- */
116
- selectable?: boolean;
117
-
118
- /**
119
- * Selected color
120
- */
121
- selectedColor?: string;
122
-
123
- /**
124
- * Width
125
- */
126
- width?: number;
127
- };
128
-
129
- // Borders
130
- const boldBorder = '2px solid rgba(224, 224, 224, 1)';
131
- const thinBorder = '1px solid rgba(224, 224, 224, 1)';
132
-
133
- // Scroll bar size
134
- const scrollbarSize = 16;
135
-
136
- // Minimum width
137
- const minWidth = 120;
138
-
139
- const createGridStyle = (
140
- alternatingColors: [string?, string?],
141
- selectedColor: string,
142
- hoverColor: string
143
- ) => {
144
- return css({
145
- '.DataGridEx-Selected': {
146
- backgroundColor: selectedColor
147
- },
148
- '.DataGridEx-Hover:not(.DataGridEx-Selected)': {
149
- backgroundColor: hoverColor
150
- },
151
- '& .DataGridEx-Cell0:not(.DataGridEx-Hover):not(.DataGridEx-Selected)':
152
- {
153
- backgroundColor: alternatingColors[0]
154
- },
155
- '& .DataGridEx-Cell1:not(.DataGridEx-Hover):not(.DataGridEx-Selected)':
156
- {
157
- backgroundColor: alternatingColors[1]
158
- },
159
- '& .DataGridEx-Cell-Border': {
160
- borderBottom: thinBorder
161
- }
162
- });
163
- };
164
-
165
- const rowItems = (
166
- div: HTMLDivElement,
167
- callback: (div: HTMLDivElement) => void
168
- ) => {
169
- const row = div.dataset['row'];
170
- if (div.parentElement == null || row == null) return;
171
- doRowItems(div.parentElement, parseFloat(row), callback);
172
- };
173
-
174
- const doRowItems = (
175
- parent: HTMLElement,
176
- rowIndex: number,
177
- callback: (div: HTMLDivElement) => void
178
- ) => {
179
- if (parent == null || rowIndex == null) return;
180
-
181
- parent
182
- ?.querySelectorAll<HTMLDivElement>(`div[data-row="${rowIndex}"]`)
183
- .forEach((rowItem) => {
184
- callback(rowItem);
185
- });
186
- };
187
-
188
- /**
189
- * Extended datagrid columns calculation
190
- * @param columns
191
- * @returns Total width and unset items
192
- */
193
- export function DataGridExCalColumns<T>(columns: GridColumn<T>[]) {
194
- return columns.reduce<{ total: number; unset: number }>(
195
- (previousValue, currentItem) => {
196
- previousValue.total +=
197
- currentItem.width ?? currentItem.minWidth ?? minWidth;
198
- if (currentItem.width == null) previousValue.unset++;
199
- return previousValue;
200
- },
201
- {
202
- total: 0,
203
- unset: 0
204
- }
205
- );
206
- }
207
-
208
- /**
209
- * Extended DataGrid with VariableSizeGrid
210
- * @param props Props
211
- * @returns Component
212
- */
213
- export function DataGridEx<
214
- T extends object,
215
- D extends DataTypes.Keys<T> = IdDefaultType<T>
216
- >(props: DataGridExProps<T, D>) {
217
- // Theme
218
- const theme = useTheme();
219
-
220
- const defaultHeaderRenderer = (states: GridLoaderStates<T>) => {
221
- const { orderBy } = states;
222
- return (
223
- <Box
224
- className="DataGridEx-Header"
225
- display="flex"
226
- alignItems="center"
227
- borderBottom={boldBorder}
228
- fontWeight={500}
229
- minWidth={widthCalculator.total}
230
- height={headerHeight}
231
- >
232
- {columns.map((column, index) => {
233
- // Destruct
234
- const {
235
- align,
236
- field,
237
- header,
238
- headerCellRenderer,
239
- sortable,
240
- sortAsc = true,
241
- type
242
- } = column;
243
-
244
- // Header text
245
- const headerText = header ?? field;
246
-
247
- // Cell props
248
- const cellProps: BoxProps = {};
249
-
250
- // Sortable
251
- let sortLabel: React.ReactNode;
252
- if (headerCellRenderer) {
253
- sortLabel = headerCellRenderer({
254
- cellProps,
255
- column,
256
- columnIndex: checkable ? index - 1 : index, // Ignore the checkbox case,
257
- states
258
- });
259
- } else if (sortable && field != null) {
260
- const active = orderBy === field;
261
-
262
- sortLabel = (
263
- <TableSortLabel
264
- active={active}
265
- direction={sortAsc ? 'asc' : 'desc'}
266
- onClick={(_event) => {
267
- if (active) column.sortAsc = !sortAsc;
268
-
269
- handleSort(field, column.sortAsc);
270
- }}
271
- >
272
- {headerText}
273
- </TableSortLabel>
274
- );
275
- } else {
276
- sortLabel = headerText;
277
- }
278
-
279
- return (
280
- <Box
281
- key={field ?? index.toString()}
282
- textAlign={GridAlignGet(align, type)}
283
- width={columnWidth(index)}
284
- >
285
- <Box
286
- className="DataGridEx-Cell"
287
- onMouseEnter={handleMouseEnter}
288
- {...cellProps}
289
- >
290
- {sortLabel}
291
- </Box>
292
- </Box>
293
- );
294
- })}
295
- </Box>
296
- );
297
- };
298
-
299
- function defaultFooterRenderer(rows: T[], states: GridLoaderStates<T>) {
300
- return (
301
- <Box
302
- className="DataGridEx-Footer"
303
- display="flex"
304
- alignItems="center"
305
- borderTop={thinBorder}
306
- marginTop="1px"
307
- minWidth={widthCalculator.total}
308
- height={bottomHeight - 1}
309
- >
310
- {columns.map((column, index) => {
311
- // Destruct
312
- const { align, field, type } = column;
313
-
314
- // Cell props
315
- const cellProps: BoxProps = {};
316
-
317
- // Cell
318
- const cell = footerItemRenderer
319
- ? footerItemRenderer(rows, {
320
- column,
321
- index: checkable ? index - 1 : index, // Ignore the checkbox case
322
- states,
323
- cellProps,
324
- checkable
325
- })
326
- : undefined;
327
-
328
- return (
329
- <Box
330
- key={'bottom-' + (field ?? index.toString())}
331
- textAlign={GridAlignGet(align, type)}
332
- width={columnWidth(index)}
333
- >
334
- <Box
335
- className="DataGridEx-Cell"
336
- onMouseEnter={handleMouseEnter}
337
- {...cellProps}
338
- >
339
- {cell}
340
- </Box>
341
- </Box>
342
- );
343
- })}
344
- </Box>
345
- );
346
- }
347
-
348
- // Destruct
349
- const {
350
- alternatingColors = [theme.palette.grey[100], undefined],
351
- borderRowsCount,
352
- bottomHeight = 53,
353
- checkable = false,
354
- className,
355
- columns,
356
- defaultOrderBy,
357
- height,
358
- headerHeight = 56,
359
- headerRenderer = defaultHeaderRenderer,
360
- footerRenderer = defaultFooterRenderer,
361
- footerItemRenderer = DataGridRenderers.defaultFooterItemRenderer,
362
- hideFooter = false,
363
- hoverColor = '#f6f9fb',
364
- idField = 'id' as D,
365
- mRef = React.createRef(),
366
- onClick,
367
- onDoubleClick,
368
- selectable = true,
369
- selectedColor = '#edf4fb',
370
- width,
371
- ...rest
372
- } = props;
373
-
374
- if (checkable) {
375
- const cbColumn: GridColumn<T> = {
376
- field: 'selected' as any, // Avoid validation from data model
377
- header: '',
378
- sortable: false,
379
- width: 50,
380
- cellRenderer: ({
381
- cellProps,
382
- data,
383
- selected
384
- }: GridCellRendererProps<T, BoxProps>) => {
385
- cellProps.sx = {
386
- padding: '4px!important'
387
- };
388
-
389
- return (
390
- <Checkbox
391
- color="primary"
392
- checked={selected}
393
- onChange={(_event, checked) => {
394
- refs.current.ref?.selectItem(data, checked);
395
- }}
396
- />
397
- );
398
- },
399
- headerCellRenderer: ({
400
- cellProps,
401
- states
402
- }: GridHeaderCellRendererProps<T, BoxProps>) => {
403
- // 2 = border height
404
- const hpad = (headerHeight - 42) / 2;
405
- cellProps.sx = {
406
- padding: `${hpad}px 4px ${hpad - 1}px 4px!important`
407
- };
408
-
409
- return (
410
- <Checkbox
411
- color="primary"
412
- indeterminate={
413
- states.selectedItems.length > 0 &&
414
- states.selectedItems.length < states.loadedItems
415
- }
416
- checked={states.selectedItems.length > 0}
417
- onChange={(_event, checked) =>
418
- refs.current.ref?.selectAll(checked)
419
- }
420
- />
421
- );
422
- }
423
- };
424
-
425
- // Update to the latest version
426
- if (columns[0].field === 'selected') {
427
- columns[0] = cbColumn;
428
- } else {
429
- columns.unshift(cbColumn);
430
- }
431
- }
432
-
433
- const refs = React.useRef<{ ref?: ScrollerGridForwardRef }>({});
434
-
435
- const mRefLocal = useCombinedRefs(mRef, (ref: ScrollerGridForwardRef) => {
436
- if (ref == null) return;
437
- refs.current.ref = ref;
438
- });
439
-
440
- // New sort
441
- const handleSort = (field: string, asc?: boolean) => {
442
- reset({ orderBy: field, orderByAsc: asc });
443
- };
444
-
445
- // Reset
446
- const reset = (add: object) => {
447
- refs.current.ref?.reset(add);
448
- };
449
-
450
- // Show hover tooltip for trucated text
451
- const handleMouseEnter = (event: React.MouseEvent<HTMLDivElement>) => {
452
- const div = event.currentTarget;
453
- const { innerText, offsetWidth, scrollWidth } = div;
454
- if (offsetWidth < scrollWidth) {
455
- div.title = innerText;
456
- } else {
457
- div.title = '';
458
- }
459
- };
460
-
461
- // selectedRowIndex state
462
- const selectedRowIndex = React.useRef(-1);
463
-
464
- const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
465
- const div = event.currentTarget;
466
- const row = div.dataset['row'];
467
- if (div.parentElement == null || row == null) return;
468
-
469
- const rowIndex = parseFloat(row);
470
-
471
- // No change
472
- if (isNaN(rowIndex) || rowIndex === selectedRowIndex.current) return;
473
-
474
- if (selectedRowIndex.current != -1) {
475
- doRowItems(
476
- div.parentElement,
477
- selectedRowIndex.current,
478
- (preDiv) => {
479
- preDiv.classList.remove('DataGridEx-Selected');
480
- }
481
- );
482
- }
483
-
484
- rowItems(div, (currentDiv) => {
485
- currentDiv.classList.add('DataGridEx-Selected');
486
- });
487
-
488
- selectedRowIndex.current = rowIndex;
489
- };
490
-
491
- const handleMouseOver = (event: React.MouseEvent<HTMLDivElement>) => {
492
- rowItems(event.currentTarget, (div) => {
493
- div.classList.add('DataGridEx-Hover');
494
- });
495
- };
496
-
497
- const handleMouseOut = (event: React.MouseEvent<HTMLDivElement>) => {
498
- rowItems(event.currentTarget, (div) => {
499
- div.classList.remove('DataGridEx-Hover');
500
- });
501
- };
502
-
503
- /**
504
- * Item renderer
505
- */
506
- const itemRenderer = ({
507
- columnIndex,
508
- rowIndex,
509
- style,
510
- data,
511
- selectedItems
512
- }: ScrollerGridItemRendererProps<T>) => {
513
- // Column
514
- const {
515
- align,
516
- cellRenderer = DataGridRenderers.defaultCellRenderer,
517
- field,
518
- type,
519
- valueFormatter,
520
- renderProps
521
- } = columns[columnIndex];
522
-
523
- // Props
524
- const formatProps: GridCellFormatterProps<T> = {
525
- data,
526
- field,
527
- rowIndex,
528
- columnIndex
529
- };
530
-
531
- let rowClass = `DataGridEx-Cell${rowIndex % 2}`;
532
- if (
533
- borderRowsCount != null &&
534
- borderRowsCount > 0 &&
535
- (rowIndex + 1) % borderRowsCount === 0
536
- ) {
537
- rowClass += ` DataGridEx-Cell-Border`;
538
- }
539
-
540
- // Selected
541
- const selected =
542
- data != null &&
543
- (selectedRowIndex.current === rowIndex ||
544
- selectedItems.some(
545
- (selectedItem) =>
546
- selectedItem != null &&
547
- selectedItem[idField] === data[idField]
548
- ));
549
-
550
- if (selected) {
551
- rowClass += ` DataGridEx-Selected`;
552
- }
553
-
554
- const cellProps: BoxProps = {
555
- className: 'DataGridEx-Cell',
556
- textAlign: GridAlignGet(align, type)
557
- };
558
-
559
- const child = cellRenderer({
560
- data,
561
- field,
562
- formattedValue: valueFormatter
563
- ? valueFormatter(formatProps)
564
- : undefined,
565
- selected,
566
- type,
567
- rowIndex,
568
- columnIndex,
569
- cellProps,
570
- renderProps
571
- });
572
-
573
- return (
574
- <div
575
- className={rowClass}
576
- style={style}
577
- data-row={rowIndex}
578
- data-column={columnIndex}
579
- onMouseDown={
580
- selectable && !checkable ? handleMouseDown : undefined
581
- }
582
- onMouseOver={selectable ? handleMouseOver : undefined}
583
- onMouseOut={selectable ? handleMouseOut : undefined}
584
- onClick={(event) =>
585
- onClick && data != null && onClick(event, data)
586
- }
587
- onDoubleClick={(event) =>
588
- onDoubleClick && data != null && onDoubleClick(event, data)
589
- }
590
- >
591
- <Box {...cellProps} onMouseEnter={handleMouseEnter}>
592
- {child}
593
- </Box>
594
- </div>
595
- );
596
- };
597
-
598
- // Column width calculator
599
- const widthCalculator = React.useMemo(
600
- () => DataGridExCalColumns(columns),
601
- [columns]
602
- );
603
-
604
- // Column width
605
- const columnWidth = React.useCallback(
606
- (index: number) => {
607
- // Ignore null case
608
- if (width == null) return 0;
609
-
610
- // Column
611
- const column = columns[index];
612
- if (column.width != null) return column.width;
613
-
614
- // More space
615
- const leftWidth =
616
- width -
617
- widthCalculator.total -
618
- (width < 800 ? 0 : scrollbarSize);
619
-
620
- // Shared width
621
- const sharedWidth =
622
- leftWidth > 0 ? leftWidth / widthCalculator.unset : 0;
623
-
624
- return (column.minWidth || minWidth) + sharedWidth;
625
- },
626
- [columns, width]
627
- );
628
-
629
- // Table
630
- const table = React.useMemo(() => {
631
- const defaultOrderByAsc = defaultOrderBy
632
- ? columns.find((column) => column.field === defaultOrderBy)?.sortAsc
633
- : undefined;
634
-
635
- return (
636
- <ScrollerGrid<T, D>
637
- className={Utils.mergeClasses(
638
- 'DataGridEx-Body',
639
- 'DataGridEx-CustomBar',
640
- className,
641
- createGridStyle(
642
- alternatingColors,
643
- selectedColor,
644
- hoverColor
645
- )
646
- )}
647
- columnCount={columns.length}
648
- columnWidth={columnWidth}
649
- defaultOrderBy={defaultOrderBy}
650
- defaultOrderByAsc={defaultOrderByAsc}
651
- height={
652
- height -
653
- headerHeight -
654
- (hideFooter ? 0 : bottomHeight + 1) -
655
- scrollbarSize
656
- }
657
- headerRenderer={headerRenderer}
658
- idField={idField}
659
- itemRenderer={itemRenderer}
660
- footerRenderer={hideFooter ? undefined : footerRenderer}
661
- width={Math.max(width ?? 0, widthCalculator.total)}
662
- mRef={mRefLocal}
663
- {...rest}
664
- />
665
- );
666
- }, [width]);
667
-
668
- return (
669
- <Paper
670
- sx={{
671
- fontSize: '0.875rem',
672
- height,
673
- '& .DataGridEx-Cell': {
674
- padding: 2,
675
- whiteSpace: 'nowrap',
676
- overflow: 'hidden',
677
- textOverflow: 'ellipsis'
678
- },
679
- '& .DataGridEx-CustomBar': {
680
- '@media (min-width: 800px)': {
681
- '::-webkit-scrollbar': {
682
- width: scrollbarSize,
683
- height: scrollbarSize,
684
- backgroundColor: '#f6f6f6'
685
- },
686
- '::-webkit-scrollbar-thumb': {
687
- backgroundColor: 'rgba(0,0,0,0.4)',
688
- borderRadius: '2px'
689
- },
690
- '::-webkit-scrollbar-track-piece:start': {
691
- background: 'transparent'
692
- },
693
- '::-webkit-scrollbar-track-piece:end': {
694
- background: 'transparent'
695
- }
696
- }
697
- }
698
- }}
699
- >
700
- <div
701
- className="DataGridEx-CustomBar"
702
- style={{
703
- width,
704
- overflowX: 'auto',
705
- overflowY: 'hidden'
706
- }}
707
- >
708
- {table}
709
- </div>
710
- </Paper>
711
- );
712
- }