@etsoo/react 1.4.16 → 1.4.20
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/lib/components/ScrollerList.js +3 -2
- package/lib/mu/ResponsibleContainer.js +29 -23
- package/lib/mu/TabBox.d.ts +1 -1
- package/lib/mu/TabBox.js +2 -1
- package/package.json +3 -3
- package/src/components/ScrollerList.tsx +3 -6
- package/src/mu/ResponsibleContainer.tsx +29 -23
- package/src/mu/TabBox.tsx +3 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { Utils } from '@etsoo/shared';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { FixedSizeList, VariableSizeList } from 'react-window';
|
|
3
4
|
import useCombinedRefs from '../uses/useCombinedRefs';
|
|
4
5
|
import { GridSizeGet } from './GridLoader';
|
|
5
6
|
// Calculate loadBatchSize
|
|
6
7
|
const calculateBatchSize = (height, itemSize) => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const size = Utils.getResult(itemSize, 0);
|
|
9
|
+
return 2 + Math.ceil(height / size);
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Scroller vertical list
|
|
@@ -7,7 +7,6 @@ import { DataGridEx, DataGridExCalColumns } from './DataGridEx';
|
|
|
7
7
|
import { ScrollerListEx } from './ScrollerListEx';
|
|
8
8
|
import { SearchBar } from './SearchBar';
|
|
9
9
|
export function ResponsibleContainer(props) {
|
|
10
|
-
var _a;
|
|
11
10
|
// Destruct
|
|
12
11
|
const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, listBoxSx, loadData, mRef, searchBoxSx, sizeReadyMiliseconds = 0, ...rest } = props;
|
|
13
12
|
// Refs
|
|
@@ -22,35 +21,43 @@ export function ResponsibleContainer(props) {
|
|
|
22
21
|
// Watch container
|
|
23
22
|
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
24
23
|
const rect = dimensions[0][2];
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const localLoadData = (props) => {
|
|
25
|
+
const data = GridDataGet(props, fieldTemplate);
|
|
26
|
+
return loadData(data);
|
|
27
|
+
};
|
|
28
|
+
const list = React.useMemo(() => {
|
|
29
|
+
// No rect
|
|
30
|
+
if (rect == null)
|
|
31
|
+
return;
|
|
32
|
+
// If height is the same
|
|
33
|
+
let heightLocal;
|
|
34
|
+
if (height != null) {
|
|
35
|
+
heightLocal = height;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Auto calculation
|
|
39
|
+
heightLocal =
|
|
40
|
+
window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
29
41
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
30
42
|
const boxPadding = parseFloat(style.paddingLeft);
|
|
31
43
|
if (!isNaN(boxPadding))
|
|
32
|
-
|
|
44
|
+
heightLocal -= 2 * boxPadding;
|
|
33
45
|
if (adjustHeight != null) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (gridHeight !== refs.current.height) {
|
|
37
|
-
refs.current.height = gridHeight;
|
|
46
|
+
heightLocal -= adjustHeight(heightLocal);
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return loadData(data);
|
|
44
|
-
};
|
|
45
|
-
const gridHeight = refs.current.height;
|
|
46
|
-
const list = React.useMemo(() => {
|
|
47
|
-
if (gridHeight == null)
|
|
49
|
+
console.log(rect, heightLocal, refs.current.height);
|
|
50
|
+
// Same height
|
|
51
|
+
if (heightLocal === refs.current.height)
|
|
48
52
|
return;
|
|
53
|
+
refs.current.height = heightLocal;
|
|
54
|
+
// Show DataGrid or List dependng on width
|
|
55
|
+
const showDataGrid = rect.width >= dataGridMinWidth;
|
|
49
56
|
if (showDataGrid) {
|
|
50
57
|
// Delete
|
|
51
58
|
delete rest.itemRenderer;
|
|
52
59
|
return (React.createElement(Box, { sx: listBoxSx == null ? undefined : listBoxSx(true) },
|
|
53
|
-
React.createElement(DataGridEx, { autoLoad: !hasFields, height:
|
|
60
|
+
React.createElement(DataGridEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, columns: columns, ...rest })));
|
|
54
61
|
}
|
|
55
62
|
// Delete
|
|
56
63
|
delete rest.checkable;
|
|
@@ -62,17 +69,16 @@ export function ResponsibleContainer(props) {
|
|
|
62
69
|
delete rest.hoverColor;
|
|
63
70
|
delete rest.selectable;
|
|
64
71
|
return (React.createElement(Box, { sx: listBoxSx == null ? undefined : listBoxSx(false) },
|
|
65
|
-
React.createElement(ScrollerListEx, { autoLoad: !hasFields, height:
|
|
66
|
-
}, [
|
|
72
|
+
React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, ...rest })));
|
|
73
|
+
}, [rect, height]);
|
|
67
74
|
// On submit callback
|
|
68
75
|
const onSubmit = (data, _reset) => {
|
|
69
|
-
console.log(data, rect, refs.current.ref, showDataGrid);
|
|
70
76
|
if (data == null || rect == null || refs.current.ref == null)
|
|
71
77
|
return;
|
|
72
78
|
refs.current.ref.reset({ data });
|
|
73
79
|
};
|
|
74
80
|
// Layout
|
|
75
|
-
return (React.createElement(Stack,
|
|
81
|
+
return (React.createElement(Stack, { ref: hasFields ? undefined : dimensions[0][0] },
|
|
76
82
|
hasFields && (React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx },
|
|
77
83
|
React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit }))),
|
|
78
84
|
list));
|
package/lib/mu/TabBox.d.ts
CHANGED
package/lib/mu/TabBox.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Utils } from '@etsoo/shared';
|
|
1
2
|
import { Box, Tab, Tabs } from '@mui/material';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
/**
|
|
@@ -20,5 +21,5 @@ export function TabBox(props) {
|
|
|
20
21
|
if (onChange)
|
|
21
22
|
onChange(event, newValue);
|
|
22
23
|
}, ...rest }, tabs.map(({ children, panel, ...tabRest }, index) => (React.createElement(Tab, { key: index, value: index, ...tabRest }))))),
|
|
23
|
-
tabs.map(({ children, panel }, index) => (React.createElement(Box, { key: index, hidden: value !== index, ...panel }, children)))));
|
|
24
|
+
tabs.map(({ children, panel }, index) => (React.createElement(Box, { key: index, hidden: value !== index, ...panel }, Utils.getResult(children, value === index))))));
|
|
24
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.20",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@emotion/react": "^11.7.1",
|
|
51
51
|
"@emotion/style": "^0.8.0",
|
|
52
52
|
"@emotion/styled": "^11.6.0",
|
|
53
|
-
"@etsoo/appscript": "^1.2.
|
|
53
|
+
"@etsoo/appscript": "^1.2.21",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.0",
|
|
55
|
-
"@etsoo/shared": "^1.1.
|
|
55
|
+
"@etsoo/shared": "^1.1.3",
|
|
56
56
|
"@mui/icons-material": "^5.2.5",
|
|
57
57
|
"@mui/material": "^5.2.7",
|
|
58
58
|
"@reach/router": "^1.3.4",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Utils } from '@etsoo/shared';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import {
|
|
3
4
|
Align,
|
|
@@ -88,12 +89,8 @@ const calculateBatchSize = (
|
|
|
88
89
|
height: number,
|
|
89
90
|
itemSize: ((index: number) => number) | number
|
|
90
91
|
) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Math.ceil(
|
|
94
|
-
height / (typeof itemSize === 'function' ? itemSize(0) : itemSize)
|
|
95
|
-
)
|
|
96
|
-
);
|
|
92
|
+
const size = Utils.getResult(itemSize, 0);
|
|
93
|
+
return 2 + Math.ceil(height / size);
|
|
97
94
|
};
|
|
98
95
|
|
|
99
96
|
/**
|
|
@@ -149,35 +149,42 @@ export function ResponsibleContainer<
|
|
|
149
149
|
// Watch container
|
|
150
150
|
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
151
151
|
const rect = dimensions[0][2];
|
|
152
|
-
const showDataGrid = (rect?.width ?? 0) >= dataGridMinWidth;
|
|
153
152
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
const localLoadData = (props: GridLoadDataProps) => {
|
|
154
|
+
const data = GridDataGet(props, fieldTemplate);
|
|
155
|
+
return loadData(data);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const list = React.useMemo(() => {
|
|
159
|
+
// No rect
|
|
160
|
+
if (rect == null) return;
|
|
161
|
+
|
|
162
|
+
// If height is the same
|
|
163
|
+
let heightLocal: number;
|
|
164
|
+
if (height != null) {
|
|
165
|
+
heightLocal = height;
|
|
166
|
+
} else {
|
|
167
|
+
// Auto calculation
|
|
168
|
+
heightLocal =
|
|
157
169
|
window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
158
170
|
|
|
159
171
|
const style = window.getComputedStyle(dimensions[0][1]!);
|
|
160
172
|
const boxPadding = parseFloat(style.paddingLeft);
|
|
161
|
-
if (!isNaN(boxPadding))
|
|
173
|
+
if (!isNaN(boxPadding)) heightLocal -= 2 * boxPadding;
|
|
162
174
|
|
|
163
175
|
if (adjustHeight != null) {
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (gridHeight !== refs.current.height) {
|
|
168
|
-
refs.current.height = gridHeight;
|
|
176
|
+
heightLocal -= adjustHeight(heightLocal);
|
|
169
177
|
}
|
|
170
178
|
}
|
|
171
|
-
}, [rect]);
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
const data = GridDataGet(props, fieldTemplate);
|
|
175
|
-
return loadData(data);
|
|
176
|
-
};
|
|
180
|
+
console.log(rect, heightLocal, refs.current.height);
|
|
177
181
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
// Same height
|
|
183
|
+
if (heightLocal === refs.current.height) return;
|
|
184
|
+
refs.current.height = heightLocal;
|
|
185
|
+
|
|
186
|
+
// Show DataGrid or List dependng on width
|
|
187
|
+
const showDataGrid = rect.width >= dataGridMinWidth;
|
|
181
188
|
|
|
182
189
|
if (showDataGrid) {
|
|
183
190
|
// Delete
|
|
@@ -187,7 +194,7 @@ export function ResponsibleContainer<
|
|
|
187
194
|
<Box sx={listBoxSx == null ? undefined : listBoxSx(true)}>
|
|
188
195
|
<DataGridEx<T>
|
|
189
196
|
autoLoad={!hasFields}
|
|
190
|
-
height={
|
|
197
|
+
height={heightLocal}
|
|
191
198
|
loadData={localLoadData}
|
|
192
199
|
mRef={mRefs}
|
|
193
200
|
columns={columns}
|
|
@@ -211,25 +218,24 @@ export function ResponsibleContainer<
|
|
|
211
218
|
<Box sx={listBoxSx == null ? undefined : listBoxSx(false)}>
|
|
212
219
|
<ScrollerListEx<T>
|
|
213
220
|
autoLoad={!hasFields}
|
|
214
|
-
height={
|
|
221
|
+
height={heightLocal}
|
|
215
222
|
loadData={localLoadData}
|
|
216
223
|
mRef={mRefs}
|
|
217
224
|
{...rest}
|
|
218
225
|
/>
|
|
219
226
|
</Box>
|
|
220
227
|
);
|
|
221
|
-
}, [
|
|
228
|
+
}, [rect, height]);
|
|
222
229
|
|
|
223
230
|
// On submit callback
|
|
224
231
|
const onSubmit = (data: FormData, _reset: boolean) => {
|
|
225
|
-
console.log(data, rect, refs.current.ref, showDataGrid);
|
|
226
232
|
if (data == null || rect == null || refs.current.ref == null) return;
|
|
227
233
|
refs.current.ref.reset({ data });
|
|
228
234
|
};
|
|
229
235
|
|
|
230
236
|
// Layout
|
|
231
237
|
return (
|
|
232
|
-
<Stack>
|
|
238
|
+
<Stack ref={hasFields ? undefined : dimensions[0][0]}>
|
|
233
239
|
{hasFields && (
|
|
234
240
|
<Box ref={dimensions[0][0]} sx={searchBoxSx}>
|
|
235
241
|
<SearchBar fields={fields} onSubmit={onSubmit} />
|
package/src/mu/TabBox.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Utils } from '@etsoo/shared';
|
|
1
2
|
import { Box, BoxProps, Tab, TabProps, Tabs, TabsProps } from '@mui/material';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
|
|
@@ -8,7 +9,7 @@ export interface TabBoxPanel extends Omit<TabProps, 'value' | 'children'> {
|
|
|
8
9
|
/**
|
|
9
10
|
* Children
|
|
10
11
|
*/
|
|
11
|
-
children?: React.ReactNode;
|
|
12
|
+
children?: ((visible: boolean) => React.ReactNode) | React.ReactNode;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Panel box props
|
|
@@ -76,7 +77,7 @@ export function TabBox(props: TabBoxPros) {
|
|
|
76
77
|
</Box>
|
|
77
78
|
{tabs.map(({ children, panel }, index) => (
|
|
78
79
|
<Box key={index} hidden={value !== index} {...panel}>
|
|
79
|
-
{children}
|
|
80
|
+
{Utils.getResult(children, value === index)}
|
|
80
81
|
</Box>
|
|
81
82
|
))}
|
|
82
83
|
</React.Fragment>
|