@etsoo/materialui 1.5.72 → 1.5.73
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.
- package/__tests__/{ResponsePage.tsx → ResponsivePage.tsx} +11 -5
- package/lib/cjs/DataGridEx.d.ts +1 -1
- package/lib/cjs/DataGridEx.js +2 -2
- package/lib/cjs/MobileListItemRenderer.d.ts +1 -1
- package/lib/cjs/MobileListItemRenderer.js +3 -4
- package/lib/cjs/ResponsibleContainer.d.ts +8 -7
- package/lib/cjs/ResponsibleContainer.js +14 -4
- package/lib/cjs/ScrollerListEx.d.ts +5 -20
- package/lib/cjs/ScrollerListEx.js +9 -58
- package/lib/cjs/pages/ResponsivePage.d.ts +8 -7
- package/lib/mjs/DataGridEx.d.ts +1 -1
- package/lib/mjs/DataGridEx.js +2 -2
- package/lib/mjs/MobileListItemRenderer.d.ts +1 -1
- package/lib/mjs/MobileListItemRenderer.js +3 -4
- package/lib/mjs/ResponsibleContainer.d.ts +8 -7
- package/lib/mjs/ResponsibleContainer.js +14 -4
- package/lib/mjs/ScrollerListEx.d.ts +5 -20
- package/lib/mjs/ScrollerListEx.js +9 -58
- package/lib/mjs/pages/ResponsivePage.d.ts +8 -7
- package/package.json +3 -3
- package/src/DataGridEx.tsx +4 -1
- package/src/MobileListItemRenderer.tsx +3 -3
- package/src/ResponsibleContainer.tsx +31 -19
- package/src/ScrollerListEx.tsx +60 -136
- package/src/pages/ResponsivePage.tsx +15 -12
|
@@ -4,7 +4,6 @@ import { ScrollerList } from "@etsoo/react";
|
|
|
4
4
|
import { Utils } from "@etsoo/shared";
|
|
5
5
|
import React from "react";
|
|
6
6
|
import { MUGlobal } from "./MUGlobal";
|
|
7
|
-
import { useTheme } from "@mui/material/styles";
|
|
8
7
|
import { GridUtils } from "./GridUtils";
|
|
9
8
|
import { useListCacheInitLoad } from "./uses/useListCacheInitLoad";
|
|
10
9
|
import Box from "@mui/material/Box";
|
|
@@ -42,28 +41,9 @@ const createGridStyle = (alternatingColors, selectedColor) => {
|
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
// Default
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const half = MUGlobal.half(margin);
|
|
49
|
-
if (horizon == null) {
|
|
50
|
-
const half = MUGlobal.half(margin);
|
|
51
|
-
return {
|
|
52
|
-
marginLeft: margin,
|
|
53
|
-
marginRight: margin,
|
|
54
|
-
marginTop: half,
|
|
55
|
-
marginBottom: half
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if ((typeof horizon === "number" && horizon >= 0) ||
|
|
59
|
-
(typeof horizon === "string" && /^-?\d+/.test(horizon))) {
|
|
60
|
-
return {
|
|
61
|
-
marginLeft: horizon,
|
|
62
|
-
marginRight: horizon,
|
|
63
|
-
marginTop: half,
|
|
64
|
-
marginBottom: half
|
|
65
|
-
};
|
|
66
|
-
}
|
|
44
|
+
// Default margins
|
|
45
|
+
const defaultMargins = () => {
|
|
46
|
+
const half = MUGlobal.half(MUGlobal.pagePaddings);
|
|
67
47
|
return {
|
|
68
48
|
marginLeft: half,
|
|
69
49
|
marginRight: half,
|
|
@@ -98,35 +78,11 @@ export function ScrollerListEx(props) {
|
|
|
98
78
|
return selected;
|
|
99
79
|
};
|
|
100
80
|
// Destruct
|
|
101
|
-
const { alternatingColors = [undefined, undefined], className, cacheKey, cacheMinutes = 15, idField = "id",
|
|
102
|
-
height: itemHeight,
|
|
81
|
+
const { alternatingColors = [undefined, undefined], className, cacheKey, cacheMinutes = 15, cellMargins = defaultMargins(), idField = "id", itemRenderer = ({ data, margins, style }) => (_jsx(Box, { component: "pre", sx: {
|
|
103
82
|
...margins
|
|
104
|
-
}, children: JSON.stringify(data) })), onClick, onDoubleClick, onUpdateRows, onSelectChange, selectedColor = "#edf4fb", ...rest } = props;
|
|
83
|
+
}, style: style, children: JSON.stringify(data) })), onClick, onDoubleClick, onUpdateRows, onSelectChange, rowHeight = 116, selectedColor = "#edf4fb", ...rest } = props;
|
|
105
84
|
// Init handler
|
|
106
85
|
const initHandler = useListCacheInitLoad(cacheKey, cacheMinutes);
|
|
107
|
-
// Theme
|
|
108
|
-
const theme = useTheme();
|
|
109
|
-
// Cache calculation
|
|
110
|
-
const itemSizeResult = React.useMemo(() => {
|
|
111
|
-
if (typeof itemSize === "function")
|
|
112
|
-
return undefined;
|
|
113
|
-
const [size, spaces, h] = itemSize;
|
|
114
|
-
if (typeof spaces === "number")
|
|
115
|
-
return [size, spaces, defaultMargin(MUGlobal.pagePaddings, undefined)];
|
|
116
|
-
return [size, MUGlobal.getSpace(spaces, theme), defaultMargin(spaces, h)];
|
|
117
|
-
}, [itemSize]);
|
|
118
|
-
// Calculate size
|
|
119
|
-
const calculateItemSize = (index) => {
|
|
120
|
-
// Callback function
|
|
121
|
-
if (typeof itemSize === "function") {
|
|
122
|
-
const result = itemSize(index);
|
|
123
|
-
if (result.length == 2)
|
|
124
|
-
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
// Calculation
|
|
128
|
-
return itemSizeResult;
|
|
129
|
-
};
|
|
130
86
|
const onUpdateRowsHandler = React.useCallback((rows, state) => {
|
|
131
87
|
GridUtils.getUpdateRowsHandler(cacheKey)?.(rows, state);
|
|
132
88
|
onUpdateRows?.(rows, state);
|
|
@@ -134,24 +90,19 @@ export function ScrollerListEx(props) {
|
|
|
134
90
|
// Layout
|
|
135
91
|
return (_jsx(ScrollerList, { className: Utils.mergeClasses("ScrollerListEx-Body", className, createGridStyle(alternatingColors, selectedColor)), idField: idField, onRowsRendered: cacheKey
|
|
136
92
|
? (visibleRows) => sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(visibleRows))
|
|
137
|
-
: undefined, onInitLoad: initHandler, onUpdateRows: onUpdateRowsHandler, rowComponent: (
|
|
93
|
+
: undefined, onInitLoad: initHandler, onUpdateRows: onUpdateRowsHandler, rowComponent: (cellProps) => {
|
|
94
|
+
const { index, style, items } = cellProps;
|
|
138
95
|
const data = items[index];
|
|
139
96
|
const selected = isSelected(data);
|
|
140
97
|
const rowClass = `ScrollerListEx-Row${index % 2}${selected ? ` ${selectedClassName}` : ""}`;
|
|
141
|
-
const [itemHeight, space, margins] = calculateItemSize(index);
|
|
142
98
|
// Child
|
|
143
99
|
const child = itemRenderer({
|
|
144
100
|
index,
|
|
145
101
|
data,
|
|
146
102
|
style,
|
|
147
103
|
selected,
|
|
148
|
-
|
|
149
|
-
space,
|
|
150
|
-
margins
|
|
104
|
+
margins: cellMargins
|
|
151
105
|
});
|
|
152
106
|
return (_jsx("div", { className: rowClass, style: style, onMouseDown: (event) => onMouseDown(event.currentTarget, data), onClick: (event) => onClick && onClick(event, data), onDoubleClick: (event) => onDoubleClick && onDoubleClick(event, data), children: child }));
|
|
153
|
-
}, rowHeight:
|
|
154
|
-
const [size, space] = calculateItemSize(index);
|
|
155
|
-
return size + space;
|
|
156
|
-
}, ...rest }));
|
|
107
|
+
}, rowHeight: rowHeight, ...rest }));
|
|
157
108
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { ResponsibleContainerProps } from "../ResponsibleContainer";
|
|
2
3
|
import type { DataGridPageProps } from "./DataGridPageProps";
|
|
3
|
-
import type {
|
|
4
|
+
import type { ScrollerListExProps } from "../ScrollerListEx";
|
|
4
5
|
import { GridMethodRef } from "@etsoo/react";
|
|
5
6
|
import type { OperationMessageHandlerAll } from "../messages/OperationMessageHandler";
|
|
6
7
|
/**
|
|
7
8
|
* Response page props
|
|
8
9
|
*/
|
|
9
|
-
export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
10
|
+
export type ResponsePageProps<T extends object, F> = Omit<DataGridPageProps<T, F>, "mRef" | "rowHeight"> & {
|
|
10
11
|
/**
|
|
11
12
|
*
|
|
12
13
|
* @param height Current height
|
|
@@ -22,14 +23,10 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
22
23
|
* Item renderer
|
|
23
24
|
*/
|
|
24
25
|
itemRenderer?: ScrollerListExProps<T>["itemRenderer"];
|
|
25
|
-
/**
|
|
26
|
-
* Item size, a function indicates its a variable size list
|
|
27
|
-
*/
|
|
28
|
-
itemSize: ScrollerListExItemSize;
|
|
29
26
|
/**
|
|
30
27
|
* Methods
|
|
31
28
|
*/
|
|
32
|
-
mRef?: React.
|
|
29
|
+
mRef?: React.RefObject<GridMethodRef<T> | undefined>;
|
|
33
30
|
/**
|
|
34
31
|
* Pull to refresh data
|
|
35
32
|
*/
|
|
@@ -42,6 +39,10 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
42
39
|
* Operation message handler
|
|
43
40
|
*/
|
|
44
41
|
operationMessageHandler?: OperationMessageHandlerAll;
|
|
42
|
+
/**
|
|
43
|
+
* Row height
|
|
44
|
+
*/
|
|
45
|
+
rowHeight?: ResponsibleContainerProps<T, F>["rowHeight"];
|
|
45
46
|
};
|
|
46
47
|
/**
|
|
47
48
|
* Fixed height list page
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.73",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"@emotion/styled": "^11.14.1",
|
|
43
43
|
"@etsoo/appscript": "^1.6.45",
|
|
44
44
|
"@etsoo/notificationbase": "^1.1.64",
|
|
45
|
-
"@etsoo/react": "^1.8.
|
|
45
|
+
"@etsoo/react": "^1.8.59",
|
|
46
46
|
"@etsoo/shared": "^1.2.76",
|
|
47
47
|
"@mui/icons-material": "^7.3.4",
|
|
48
48
|
"@mui/material": "^7.3.4",
|
|
49
|
-
"@mui/x-data-grid": "^8.
|
|
49
|
+
"@mui/x-data-grid": "^8.14.0",
|
|
50
50
|
"chart.js": "^4.5.0",
|
|
51
51
|
"chartjs-plugin-datalabels": "^2.2.0",
|
|
52
52
|
"dompurify": "^3.2.7",
|
package/src/DataGridEx.tsx
CHANGED
|
@@ -51,8 +51,9 @@ export type DataGridExProps<
|
|
|
51
51
|
| "onClick"
|
|
52
52
|
| "onDoubleClick"
|
|
53
53
|
| "onInitLoad"
|
|
54
|
+
| "rowHeight"
|
|
54
55
|
| "width"
|
|
55
|
-
> & {
|
|
56
|
+
> & Partial<Pick<ScrollerGridProps<T, P>, "rowHeight">> & {
|
|
56
57
|
/**
|
|
57
58
|
* Alternating colors for odd/even rows
|
|
58
59
|
*/
|
|
@@ -389,6 +390,7 @@ export function DataGridEx<T extends object>(props: DataGridExProps<T>) {
|
|
|
389
390
|
onDataChange,
|
|
390
391
|
onDoubleClick,
|
|
391
392
|
onUpdateRows,
|
|
393
|
+
rowHeight = 53,
|
|
392
394
|
selectable = true,
|
|
393
395
|
selectedColor = "#edf4fb",
|
|
394
396
|
width,
|
|
@@ -696,6 +698,7 @@ export function DataGridEx<T extends object>(props: DataGridExProps<T>) {
|
|
|
696
698
|
headerRenderer={headerRenderer}
|
|
697
699
|
idField={idField}
|
|
698
700
|
footerRenderer={hideFooter ? undefined : footerRenderer}
|
|
701
|
+
rowHeight={rowHeight}
|
|
699
702
|
width={Math.max(width ?? 0, widthCalculator.total)}
|
|
700
703
|
mRef={mRefLocal}
|
|
701
704
|
{...rest}
|
|
@@ -15,7 +15,7 @@ import { ScrollerListExItemRendererProps } from "./ScrollerListEx";
|
|
|
15
15
|
* @returns Component
|
|
16
16
|
*/
|
|
17
17
|
export function MobileListItemRenderer<T>(
|
|
18
|
-
{ data,
|
|
18
|
+
{ data, margins, style }: ScrollerListExItemRendererProps<T>,
|
|
19
19
|
renderer: (
|
|
20
20
|
data: T
|
|
21
21
|
) => [
|
|
@@ -35,9 +35,9 @@ export function MobileListItemRenderer<T>(
|
|
|
35
35
|
return (
|
|
36
36
|
<Card
|
|
37
37
|
sx={{
|
|
38
|
-
height: itemHeight,
|
|
39
38
|
...margins
|
|
40
39
|
}}
|
|
40
|
+
style={style}
|
|
41
41
|
>
|
|
42
42
|
<CardHeader
|
|
43
43
|
sx={{ paddingBottom: 0.5 }}
|
|
@@ -71,7 +71,7 @@ export function MobileListItemRenderer<T>(
|
|
|
71
71
|
sx={{
|
|
72
72
|
paddingTop: 0,
|
|
73
73
|
paddingBottom:
|
|
74
|
-
cardActions == null ? Reflect.get(margins, "marginBottom") : 0
|
|
74
|
+
cardActions == null ? Reflect.get(margins, "marginBottom") ?? 0 : 0
|
|
75
75
|
}}
|
|
76
76
|
>
|
|
77
77
|
{children}
|
|
@@ -13,11 +13,7 @@ import {
|
|
|
13
13
|
import { DataGridEx, DataGridExProps } from "./DataGridEx";
|
|
14
14
|
import { MUGlobal } from "./MUGlobal";
|
|
15
15
|
import { PullToRefreshUI } from "./PullToRefreshUI";
|
|
16
|
-
import {
|
|
17
|
-
ScrollerListEx,
|
|
18
|
-
ScrollerListExItemSize,
|
|
19
|
-
ScrollerListExProps
|
|
20
|
-
} from "./ScrollerListEx";
|
|
16
|
+
import { ScrollerListEx, ScrollerListExProps } from "./ScrollerListEx";
|
|
21
17
|
import { SearchBar } from "./SearchBar";
|
|
22
18
|
import { Labels } from "./app/Labels";
|
|
23
19
|
import { GridUtils } from "./GridUtils";
|
|
@@ -31,14 +27,7 @@ import Stack from "@mui/material/Stack";
|
|
|
31
27
|
*/
|
|
32
28
|
export type ResponsibleContainerProps<T extends object, F> = Omit<
|
|
33
29
|
DataGridExProps<T>,
|
|
34
|
-
| "
|
|
35
|
-
| "itemKey"
|
|
36
|
-
| "loadData"
|
|
37
|
-
| "mRef"
|
|
38
|
-
| "onScroll"
|
|
39
|
-
| "onItemsRendered"
|
|
40
|
-
| "onInitLoad"
|
|
41
|
-
| "onUpdateRows"
|
|
30
|
+
"height" | "loadData" | "mRef" | "onInitLoad" | "onUpdateRows" | "rowHeight"
|
|
42
31
|
> & {
|
|
43
32
|
/**
|
|
44
33
|
* Height will be deducted
|
|
@@ -91,11 +80,6 @@ export type ResponsibleContainerProps<T extends object, F> = Omit<
|
|
|
91
80
|
*/
|
|
92
81
|
itemRenderer?: ScrollerListExProps<T>["itemRenderer"];
|
|
93
82
|
|
|
94
|
-
/**
|
|
95
|
-
* Item size, a function indicates its a variable size list
|
|
96
|
-
*/
|
|
97
|
-
itemSize: ScrollerListExItemSize;
|
|
98
|
-
|
|
99
83
|
/**
|
|
100
84
|
* Load data callback
|
|
101
85
|
*/
|
|
@@ -107,7 +91,7 @@ export type ResponsibleContainerProps<T extends object, F> = Omit<
|
|
|
107
91
|
/**
|
|
108
92
|
* Methods
|
|
109
93
|
*/
|
|
110
|
-
mRef?: React.
|
|
94
|
+
mRef?: React.RefObject<GridMethodRef<T> | undefined>;
|
|
111
95
|
|
|
112
96
|
/**
|
|
113
97
|
* Element ready callback
|
|
@@ -129,6 +113,19 @@ export type ResponsibleContainerProps<T extends object, F> = Omit<
|
|
|
129
113
|
*/
|
|
130
114
|
quickAction?: (data: T) => void;
|
|
131
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Row height
|
|
118
|
+
* @param isGrid Is displaying as DataGrid
|
|
119
|
+
*/
|
|
120
|
+
rowHeight?:
|
|
121
|
+
| number
|
|
122
|
+
| [number, number]
|
|
123
|
+
| (<B extends boolean>(
|
|
124
|
+
isGrid: B
|
|
125
|
+
) => B extends true
|
|
126
|
+
? DataGridExProps<T>["rowHeight"]
|
|
127
|
+
: ScrollerListExProps<T>["rowHeight"]);
|
|
128
|
+
|
|
132
129
|
/**
|
|
133
130
|
* Size ready to read miliseconds span
|
|
134
131
|
*/
|
|
@@ -196,6 +193,7 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
196
193
|
paddings = MUGlobal.pagePaddings,
|
|
197
194
|
pullToRefresh = true,
|
|
198
195
|
quickAction,
|
|
196
|
+
rowHeight,
|
|
199
197
|
sizeReadyMiliseconds = 0,
|
|
200
198
|
searchBarHeight = 45.6,
|
|
201
199
|
searchBarBottom = 8,
|
|
@@ -239,6 +237,17 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
239
237
|
);
|
|
240
238
|
};
|
|
241
239
|
|
|
240
|
+
const getRowHeight = React.useCallback(
|
|
241
|
+
<B extends boolean>(isGrid: B) => {
|
|
242
|
+
if (rowHeight == null) return undefined;
|
|
243
|
+
else if (typeof rowHeight === "number")
|
|
244
|
+
return isGrid ? undefined : rowHeight;
|
|
245
|
+
else if (Array.isArray(rowHeight)) return rowHeight[isGrid ? 0 : 1];
|
|
246
|
+
else return rowHeight<B>(isGrid);
|
|
247
|
+
},
|
|
248
|
+
[rowHeight]
|
|
249
|
+
);
|
|
250
|
+
|
|
242
251
|
// Search data
|
|
243
252
|
const searchData = useSearchParamsWithCache(cacheKey);
|
|
244
253
|
|
|
@@ -321,6 +330,7 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
321
330
|
mRef={mRefs}
|
|
322
331
|
onDoubleClick={(_, data) => quickAction && quickAction(data)}
|
|
323
332
|
columns={columns}
|
|
333
|
+
rowHeight={getRowHeight(true)}
|
|
324
334
|
{...gridProps}
|
|
325
335
|
/>
|
|
326
336
|
</Box>
|
|
@@ -337,6 +347,7 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
337
347
|
hideFooter,
|
|
338
348
|
hoverColor,
|
|
339
349
|
selectable,
|
|
350
|
+
onCellsRendered,
|
|
340
351
|
...listProps
|
|
341
352
|
} = rest;
|
|
342
353
|
|
|
@@ -350,6 +361,7 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
350
361
|
onClick={(event, data) =>
|
|
351
362
|
quickAction && ReactUtils.isSafeClick(event) && quickAction(data)
|
|
352
363
|
}
|
|
364
|
+
rowHeight={getRowHeight(false)}
|
|
353
365
|
{...listProps}
|
|
354
366
|
/>
|
|
355
367
|
</Box>
|
package/src/ScrollerListEx.tsx
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import { DataTypes, Utils } from "@etsoo/shared";
|
|
8
8
|
import React from "react";
|
|
9
9
|
import { MouseEventWithDataHandler, MUGlobal } from "./MUGlobal";
|
|
10
|
-
import { useTheme } from "@mui/material/styles";
|
|
11
10
|
import { GridUtils } from "./GridUtils";
|
|
12
11
|
import { useListCacheInitLoad } from "./uses/useListCacheInitLoad";
|
|
13
12
|
import Box from "@mui/material/Box";
|
|
@@ -52,32 +51,9 @@ const createGridStyle = (
|
|
|
52
51
|
});
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
// Default
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const half = MUGlobal.half(margin);
|
|
59
|
-
|
|
60
|
-
if (horizon == null) {
|
|
61
|
-
const half = MUGlobal.half(margin);
|
|
62
|
-
return {
|
|
63
|
-
marginLeft: margin,
|
|
64
|
-
marginRight: margin,
|
|
65
|
-
marginTop: half,
|
|
66
|
-
marginBottom: half
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
(typeof horizon === "number" && horizon >= 0) ||
|
|
72
|
-
(typeof horizon === "string" && /^-?\d+/.test(horizon))
|
|
73
|
-
) {
|
|
74
|
-
return {
|
|
75
|
-
marginLeft: horizon,
|
|
76
|
-
marginRight: horizon,
|
|
77
|
-
marginTop: half,
|
|
78
|
-
marginBottom: half
|
|
79
|
-
};
|
|
80
|
-
}
|
|
54
|
+
// Default margins
|
|
55
|
+
const defaultMargins = () => {
|
|
56
|
+
const half = MUGlobal.half(MUGlobal.pagePaddings);
|
|
81
57
|
|
|
82
58
|
return {
|
|
83
59
|
marginLeft: half,
|
|
@@ -106,16 +82,6 @@ export type ScrollerListExItemRendererProps<T> = {
|
|
|
106
82
|
*/
|
|
107
83
|
style: React.CSSProperties;
|
|
108
84
|
|
|
109
|
-
/**
|
|
110
|
-
* Item height
|
|
111
|
-
*/
|
|
112
|
-
itemHeight: number;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Item space
|
|
116
|
-
*/
|
|
117
|
-
space: number;
|
|
118
|
-
|
|
119
85
|
/**
|
|
120
86
|
* Default margins
|
|
121
87
|
*/
|
|
@@ -127,69 +93,61 @@ export type ScrollerListExItemRendererProps<T> = {
|
|
|
127
93
|
selected: boolean;
|
|
128
94
|
};
|
|
129
95
|
|
|
130
|
-
/**
|
|
131
|
-
* Extended ScrollerList ItemSize type
|
|
132
|
-
* 1. Callback function
|
|
133
|
-
* 2. Static sets
|
|
134
|
-
* 3. Dynamic left & right margin calculation
|
|
135
|
-
*/
|
|
136
|
-
export type ScrollerListExItemSize =
|
|
137
|
-
| ((index: number) => [number, number] | [number, number, object])
|
|
138
|
-
| [number, number]
|
|
139
|
-
| [number, object, (number | string)?];
|
|
140
|
-
|
|
141
96
|
/**
|
|
142
97
|
* Extended ScrollerList Props
|
|
143
98
|
*/
|
|
144
99
|
export type ScrollerListExProps<T extends object> = Omit<
|
|
145
100
|
ScrollerListProps<T>,
|
|
146
101
|
"rowComponent" | "rowHeight" | "onClick" | "onDoubleClick" | "onInitLoad"
|
|
147
|
-
> &
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
102
|
+
> &
|
|
103
|
+
Partial<Pick<ScrollerListProps<T>, "rowHeight">> & {
|
|
104
|
+
/**
|
|
105
|
+
* Alternating colors for odd/even rows
|
|
106
|
+
*/
|
|
107
|
+
alternatingColors?: [string?, string?];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Cache key
|
|
111
|
+
*/
|
|
112
|
+
cacheKey?: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Cache minutes
|
|
116
|
+
*/
|
|
117
|
+
cacheMinutes?: number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Cell margins, default to half of MUGlobal.pagePaddings
|
|
121
|
+
*/
|
|
122
|
+
cellMargins?: object;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Item renderer
|
|
126
|
+
*/
|
|
127
|
+
itemRenderer?: (
|
|
128
|
+
props: ScrollerListExItemRendererProps<T>
|
|
129
|
+
) => React.ReactNode;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Double click handler
|
|
133
|
+
*/
|
|
134
|
+
onDoubleClick?: MouseEventWithDataHandler<T>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Click handler
|
|
138
|
+
*/
|
|
139
|
+
onClick?: MouseEventWithDataHandler<T>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* On items select change
|
|
143
|
+
*/
|
|
144
|
+
onSelectChange?: (selectedItems: T[]) => void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Selected color
|
|
148
|
+
*/
|
|
149
|
+
selectedColor?: string;
|
|
150
|
+
};
|
|
193
151
|
|
|
194
152
|
/**
|
|
195
153
|
* Extended ScrollerList
|
|
@@ -232,15 +190,15 @@ export function ScrollerListEx<T extends object>(
|
|
|
232
190
|
className,
|
|
233
191
|
cacheKey,
|
|
234
192
|
cacheMinutes = 15,
|
|
193
|
+
cellMargins = defaultMargins(),
|
|
235
194
|
idField = "id" as DataTypes.Keys<T>,
|
|
236
|
-
|
|
237
|
-
itemRenderer = ({ data, itemHeight, margins }) => (
|
|
195
|
+
itemRenderer = ({ data, margins, style }) => (
|
|
238
196
|
<Box
|
|
239
197
|
component="pre"
|
|
240
198
|
sx={{
|
|
241
|
-
height: itemHeight,
|
|
242
199
|
...margins
|
|
243
200
|
}}
|
|
201
|
+
style={style}
|
|
244
202
|
>
|
|
245
203
|
{JSON.stringify(data)}
|
|
246
204
|
</Box>
|
|
@@ -249,6 +207,7 @@ export function ScrollerListEx<T extends object>(
|
|
|
249
207
|
onDoubleClick,
|
|
250
208
|
onUpdateRows,
|
|
251
209
|
onSelectChange,
|
|
210
|
+
rowHeight = 116,
|
|
252
211
|
selectedColor = "#edf4fb",
|
|
253
212
|
...rest
|
|
254
213
|
} = props;
|
|
@@ -256,35 +215,6 @@ export function ScrollerListEx<T extends object>(
|
|
|
256
215
|
// Init handler
|
|
257
216
|
const initHandler = useListCacheInitLoad<T>(cacheKey, cacheMinutes);
|
|
258
217
|
|
|
259
|
-
// Theme
|
|
260
|
-
const theme = useTheme();
|
|
261
|
-
|
|
262
|
-
// Cache calculation
|
|
263
|
-
const itemSizeResult = React.useMemo(():
|
|
264
|
-
| [number, number, object]
|
|
265
|
-
| undefined => {
|
|
266
|
-
if (typeof itemSize === "function") return undefined;
|
|
267
|
-
const [size, spaces, h] = itemSize;
|
|
268
|
-
if (typeof spaces === "number")
|
|
269
|
-
return [size, spaces, defaultMargin(MUGlobal.pagePaddings, undefined)];
|
|
270
|
-
|
|
271
|
-
return [size, MUGlobal.getSpace(spaces, theme), defaultMargin(spaces, h)];
|
|
272
|
-
}, [itemSize]);
|
|
273
|
-
|
|
274
|
-
// Calculate size
|
|
275
|
-
const calculateItemSize = (index: number): [number, number, object] => {
|
|
276
|
-
// Callback function
|
|
277
|
-
if (typeof itemSize === "function") {
|
|
278
|
-
const result = itemSize(index);
|
|
279
|
-
if (result.length == 2)
|
|
280
|
-
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Calculation
|
|
285
|
-
return itemSizeResult!;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
218
|
const onUpdateRowsHandler = React.useCallback(
|
|
289
219
|
(rows: T[], state: GridLoaderStates<T>) => {
|
|
290
220
|
GridUtils.getUpdateRowsHandler<T>(cacheKey)?.(rows, state);
|
|
@@ -313,24 +243,21 @@ export function ScrollerListEx<T extends object>(
|
|
|
313
243
|
}
|
|
314
244
|
onInitLoad={initHandler}
|
|
315
245
|
onUpdateRows={onUpdateRowsHandler}
|
|
316
|
-
rowComponent={(
|
|
246
|
+
rowComponent={(cellProps) => {
|
|
247
|
+
const { index, style, items } = cellProps;
|
|
317
248
|
const data = items[index];
|
|
318
249
|
const selected = isSelected(data);
|
|
319
250
|
const rowClass = `ScrollerListEx-Row${index % 2}${
|
|
320
251
|
selected ? ` ${selectedClassName}` : ""
|
|
321
252
|
}`;
|
|
322
253
|
|
|
323
|
-
const [itemHeight, space, margins] = calculateItemSize(index);
|
|
324
|
-
|
|
325
254
|
// Child
|
|
326
255
|
const child = itemRenderer({
|
|
327
256
|
index,
|
|
328
257
|
data,
|
|
329
258
|
style,
|
|
330
259
|
selected,
|
|
331
|
-
|
|
332
|
-
space,
|
|
333
|
-
margins
|
|
260
|
+
margins: cellMargins
|
|
334
261
|
});
|
|
335
262
|
|
|
336
263
|
return (
|
|
@@ -347,10 +274,7 @@ export function ScrollerListEx<T extends object>(
|
|
|
347
274
|
</div>
|
|
348
275
|
);
|
|
349
276
|
}}
|
|
350
|
-
rowHeight={
|
|
351
|
-
const [size, space] = calculateItemSize(index);
|
|
352
|
-
return size + space;
|
|
353
|
-
}}
|
|
277
|
+
rowHeight={rowHeight}
|
|
354
278
|
{...rest}
|
|
355
279
|
/>
|
|
356
280
|
);
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MUGlobal } from "../MUGlobal";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ResponsibleContainer,
|
|
5
|
+
ResponsibleContainerProps
|
|
6
|
+
} from "../ResponsibleContainer";
|
|
4
7
|
import { CommonPage } from "./CommonPage";
|
|
5
8
|
import { OperationMessageContainer } from "../messages/OperationMessageContainer";
|
|
6
9
|
import type { DataGridPageProps } from "./DataGridPageProps";
|
|
7
|
-
import type {
|
|
8
|
-
ScrollerListExItemSize,
|
|
9
|
-
ScrollerListExProps
|
|
10
|
-
} from "../ScrollerListEx";
|
|
10
|
+
import type { ScrollerListExProps } from "../ScrollerListEx";
|
|
11
11
|
import { GridMethodRef } from "@etsoo/react";
|
|
12
12
|
import type { OperationMessageHandlerAll } from "../messages/OperationMessageHandler";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Response page props
|
|
16
16
|
*/
|
|
17
|
-
export type ResponsePageProps<T extends object, F> =
|
|
17
|
+
export type ResponsePageProps<T extends object, F> = Omit<
|
|
18
|
+
DataGridPageProps<T, F>,
|
|
19
|
+
"mRef" | "rowHeight"
|
|
20
|
+
> & {
|
|
18
21
|
/**
|
|
19
22
|
*
|
|
20
23
|
* @param height Current height
|
|
@@ -33,15 +36,10 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
33
36
|
*/
|
|
34
37
|
itemRenderer?: ScrollerListExProps<T>["itemRenderer"];
|
|
35
38
|
|
|
36
|
-
/**
|
|
37
|
-
* Item size, a function indicates its a variable size list
|
|
38
|
-
*/
|
|
39
|
-
itemSize: ScrollerListExItemSize;
|
|
40
|
-
|
|
41
39
|
/**
|
|
42
40
|
* Methods
|
|
43
41
|
*/
|
|
44
|
-
mRef?: React.
|
|
42
|
+
mRef?: React.RefObject<GridMethodRef<T> | undefined>;
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* Pull to refresh data
|
|
@@ -57,6 +55,11 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
|
|
|
57
55
|
* Operation message handler
|
|
58
56
|
*/
|
|
59
57
|
operationMessageHandler?: OperationMessageHandlerAll;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Row height
|
|
61
|
+
*/
|
|
62
|
+
rowHeight?: ResponsibleContainerProps<T, F>["rowHeight"];
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
/**
|