@etsoo/react 1.4.24 → 1.4.28
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 -1
- package/lib/mu/ResponsibleContainer.d.ts +9 -1
- package/lib/mu/ResponsibleContainer.js +42 -14
- package/lib/mu/SearchBar.js +34 -26
- package/lib/mu/pages/CommonPage.d.ts +0 -4
- package/lib/mu/pages/CommonPage.js +2 -11
- package/lib/mu/pages/CommonPageProps.d.ts +0 -4
- package/lib/mu/pages/DataGridPage.js +4 -7
- package/lib/mu/pages/FixedListPage.js +3 -6
- package/lib/mu/pages/ListPage.js +2 -2
- package/lib/mu/pages/ResponsivePage.js +33 -119
- package/lib/mu/pages/ResponsivePageProps.d.ts +4 -0
- package/lib/mu/pages/TablePage.js +4 -3
- package/lib/uses/useWindowSize.d.ts +6 -5
- package/lib/uses/useWindowSize.js +22 -16
- package/package.json +1 -1
- package/src/components/ScrollerList.tsx +4 -1
- package/src/mu/ResponsibleContainer.tsx +76 -17
- package/src/mu/SearchBar.tsx +35 -23
- package/src/mu/pages/CommonPage.tsx +0 -21
- package/src/mu/pages/CommonPageProps.ts +0 -5
- package/src/mu/pages/DataGridPage.tsx +3 -11
- package/src/mu/pages/FixedListPage.tsx +2 -7
- package/src/mu/pages/ListPage.tsx +2 -10
- package/src/mu/pages/ResponsivePage.tsx +37 -192
- package/src/mu/pages/ResponsivePageProps.ts +5 -0
- package/src/mu/pages/TablePage.tsx +5 -11
- package/src/uses/useWindowSize.ts +32 -19
|
@@ -15,7 +15,7 @@ const calculateBatchSize = (height, itemSize) => {
|
|
|
15
15
|
*/
|
|
16
16
|
export const ScrollerList = (props) => {
|
|
17
17
|
// Destruct
|
|
18
|
-
const { autoLoad = true, defaultOrderBy, defaultOrderByAsc, height =
|
|
18
|
+
const { autoLoad = true, defaultOrderBy, defaultOrderByAsc, height = document.documentElement.clientHeight, width = '100%', mRef, oRef, style = {}, itemRenderer, itemSize, loadBatchSize = calculateBatchSize(height, itemSize), loadData, threshold = GridSizeGet(loadBatchSize, height) / 2, onItemsRendered, ...rest } = props;
|
|
19
19
|
// Style
|
|
20
20
|
Object.assign(style, {
|
|
21
21
|
width: '100%',
|
|
@@ -120,6 +120,8 @@ export const ScrollerList = (props) => {
|
|
|
120
120
|
...add
|
|
121
121
|
};
|
|
122
122
|
Object.assign(state, resetState);
|
|
123
|
+
// Reset
|
|
124
|
+
setRows([]);
|
|
123
125
|
},
|
|
124
126
|
scrollTo(scrollOffset) {
|
|
125
127
|
refMethods.scrollTo(scrollOffset);
|
|
@@ -20,6 +20,10 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
20
20
|
* Columns
|
|
21
21
|
*/
|
|
22
22
|
columns: GridColumn<T>[];
|
|
23
|
+
/**
|
|
24
|
+
* Container box SX (dataGrid determines the case)
|
|
25
|
+
*/
|
|
26
|
+
containerBoxSx?: (dataGrid: boolean) => SxProps<Theme>;
|
|
23
27
|
/**
|
|
24
28
|
* Min width to show Datagrid
|
|
25
29
|
*/
|
|
@@ -51,7 +55,7 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
51
55
|
/**
|
|
52
56
|
* Listbox SX (dataGrid determines the case)
|
|
53
57
|
*/
|
|
54
|
-
listBoxSx?: (dataGrid: boolean) => SxProps<Theme>;
|
|
58
|
+
listBoxSx?: (dataGrid: boolean, height: number) => SxProps<Theme>;
|
|
55
59
|
/**
|
|
56
60
|
* Load data callback
|
|
57
61
|
*/
|
|
@@ -60,6 +64,10 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
60
64
|
* Methods
|
|
61
65
|
*/
|
|
62
66
|
mRef?: React.MutableRefObject<GridMethodRef | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* Element ready callback
|
|
69
|
+
*/
|
|
70
|
+
elementReady?: (element: HTMLElement, isDataGrid: boolean) => void;
|
|
63
71
|
/**
|
|
64
72
|
* Paddings
|
|
65
73
|
*/
|
|
@@ -9,6 +9,15 @@ import { MUGlobal } from './MUGlobal';
|
|
|
9
9
|
import { PullToRefreshUI } from './PullToRefreshUI';
|
|
10
10
|
import { ScrollerListEx } from './ScrollerListEx';
|
|
11
11
|
import { SearchBar } from './SearchBar';
|
|
12
|
+
function getDefaultSearchBoxSx(paddings) {
|
|
13
|
+
const half = MUGlobal.half(paddings);
|
|
14
|
+
return {
|
|
15
|
+
paddingLeft: (theme) => theme.spacing(0.5),
|
|
16
|
+
paddingRight: (theme) => theme.spacing(0.5),
|
|
17
|
+
paddingTop: half,
|
|
18
|
+
marginBottom: half
|
|
19
|
+
};
|
|
20
|
+
}
|
|
12
21
|
/**
|
|
13
22
|
* Responsible container
|
|
14
23
|
* @param props Props
|
|
@@ -16,7 +25,7 @@ import { SearchBar } from './SearchBar';
|
|
|
16
25
|
*/
|
|
17
26
|
export function ResponsibleContainer(props) {
|
|
18
27
|
// Destruct
|
|
19
|
-
const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, listBoxSx, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, searchBoxSx =
|
|
28
|
+
const { adjustHeight, columns, containerBoxSx, dataGridMinWidth = DataGridExCalColumns(columns).total, elementReady, fields, fieldTemplate, height, listBoxSx, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, searchBoxSx = getDefaultSearchBoxSx(paddings), sizeReadyMiliseconds = 0, ...rest } = props;
|
|
20
29
|
// Labels
|
|
21
30
|
const labels = Labels.CommonPage;
|
|
22
31
|
// Refs
|
|
@@ -55,6 +64,7 @@ export function ResponsibleContainer(props) {
|
|
|
55
64
|
// Last rect
|
|
56
65
|
const lastRect = state.rect;
|
|
57
66
|
// 32 = scroll bar width
|
|
67
|
+
console.log(lastRect, rect);
|
|
58
68
|
if (lastRect != null &&
|
|
59
69
|
state.mounted !== true &&
|
|
60
70
|
Math.abs(rect.width - lastRect.width) <= 32 &&
|
|
@@ -70,7 +80,7 @@ export function ResponsibleContainer(props) {
|
|
|
70
80
|
const [list, showDataGrid] = (() => {
|
|
71
81
|
// No layout
|
|
72
82
|
if (rect == null)
|
|
73
|
-
return [null,
|
|
83
|
+
return [null, undefined];
|
|
74
84
|
// Width
|
|
75
85
|
const width = rect.width;
|
|
76
86
|
// Show DataGrid or List dependng on width
|
|
@@ -82,7 +92,9 @@ export function ResponsibleContainer(props) {
|
|
|
82
92
|
}
|
|
83
93
|
else {
|
|
84
94
|
// Auto calculation
|
|
85
|
-
heightLocal =
|
|
95
|
+
heightLocal =
|
|
96
|
+
document.documentElement.clientHeight -
|
|
97
|
+
Math.round(rect.bottom + 1);
|
|
86
98
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
87
99
|
const boxMargin = parseFloat(style.marginBottom);
|
|
88
100
|
if (!isNaN(boxMargin))
|
|
@@ -95,8 +107,13 @@ export function ResponsibleContainer(props) {
|
|
|
95
107
|
// Delete
|
|
96
108
|
delete rest.itemRenderer;
|
|
97
109
|
return [
|
|
98
|
-
React.createElement(Box, { sx: listBoxSx == null
|
|
99
|
-
|
|
110
|
+
React.createElement(Box, { sx: listBoxSx == null
|
|
111
|
+
? undefined
|
|
112
|
+
: listBoxSx(true, heightLocal) },
|
|
113
|
+
React.createElement(DataGridEx, { autoLoad: !hasFields, height: heightLocal, width: rect.width, loadData: localLoadData, mRef: mRefs, outerRef: (element) => {
|
|
114
|
+
if (element != null && elementReady)
|
|
115
|
+
elementReady(element, true);
|
|
116
|
+
}, columns: columns, ...rest })),
|
|
100
117
|
true
|
|
101
118
|
];
|
|
102
119
|
}
|
|
@@ -110,22 +127,33 @@ export function ResponsibleContainer(props) {
|
|
|
110
127
|
delete rest.hoverColor;
|
|
111
128
|
delete rest.selectable;
|
|
112
129
|
return [
|
|
113
|
-
React.createElement(Box, { sx: listBoxSx == null
|
|
114
|
-
|
|
130
|
+
React.createElement(Box, { sx: listBoxSx == null
|
|
131
|
+
? undefined
|
|
132
|
+
: listBoxSx(false, heightLocal) },
|
|
133
|
+
React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, oRef: (element) => {
|
|
134
|
+
if (element != null && elementReady)
|
|
135
|
+
elementReady(element, false);
|
|
136
|
+
}, ...rest })),
|
|
115
137
|
false
|
|
116
138
|
];
|
|
117
139
|
})();
|
|
140
|
+
const searchBar = React.useMemo(() => {
|
|
141
|
+
if (!hasFields || showDataGrid == null)
|
|
142
|
+
return;
|
|
143
|
+
return (React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit, className: `searchBar${showDataGrid ? 'Grid' : 'List'}` }));
|
|
144
|
+
}, [showDataGrid, hasFields]);
|
|
118
145
|
// Pull container
|
|
119
|
-
const pullContainer =
|
|
120
|
-
?
|
|
146
|
+
const pullContainer = showDataGrid == null
|
|
147
|
+
? undefined
|
|
148
|
+
: showDataGrid
|
|
121
149
|
? '.DataGridEx-Body'
|
|
122
|
-
: '.ScrollerListEx-Body'
|
|
123
|
-
: undefined;
|
|
150
|
+
: '.ScrollerListEx-Body';
|
|
124
151
|
// Layout
|
|
125
|
-
return (React.createElement(
|
|
152
|
+
return (React.createElement(Box, { sx: containerBoxSx == null || showDataGrid == null
|
|
153
|
+
? undefined
|
|
154
|
+
: containerBoxSx(showDataGrid) },
|
|
126
155
|
React.createElement(Stack, null,
|
|
127
|
-
React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx },
|
|
128
|
-
list),
|
|
156
|
+
React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx }, searchBar)),
|
|
129
157
|
pullToRefresh && pullContainer && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: () => { var _a; return (_a = state.ref) === null || _a === void 0 ? void 0 : _a.reset(); }, shouldPullToRefresh: () => {
|
|
130
158
|
const container = document.querySelector(pullContainer);
|
|
131
159
|
return !(container === null || container === void 0 ? void 0 : container.scrollTop);
|
package/lib/mu/SearchBar.js
CHANGED
|
@@ -52,6 +52,7 @@ const setChildState = (child, enabled) => {
|
|
|
52
52
|
* @returns Component
|
|
53
53
|
*/
|
|
54
54
|
export function SearchBar(props) {
|
|
55
|
+
var _a;
|
|
55
56
|
// Destruct
|
|
56
57
|
const { className, fields, innerHeight = 40, onSubmit } = props;
|
|
57
58
|
// Labels
|
|
@@ -63,12 +64,16 @@ export function SearchBar(props) {
|
|
|
63
64
|
const [index, updateIndex] = React.useState();
|
|
64
65
|
// Drawer open / close
|
|
65
66
|
const [open, updateOpen] = React.useState(false);
|
|
66
|
-
//
|
|
67
|
-
const
|
|
67
|
+
// State
|
|
68
|
+
const state = React.useRef({}).current;
|
|
69
|
+
const lastMaxWidth = (_a = state.lastMaxWidth) !== null && _a !== void 0 ? _a : 9999;
|
|
68
70
|
// Watch container
|
|
69
71
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
70
72
|
// Same logic from resetButtonRef
|
|
71
|
-
if (rect.width ===
|
|
73
|
+
if (rect.width === lastMaxWidth ||
|
|
74
|
+
(index != null &&
|
|
75
|
+
index >= fields.length &&
|
|
76
|
+
rect.width > lastMaxWidth))
|
|
72
77
|
return false;
|
|
73
78
|
// Len
|
|
74
79
|
const len = target.children.length;
|
|
@@ -96,10 +101,11 @@ export function SearchBar(props) {
|
|
|
96
101
|
return;
|
|
97
102
|
// Container width
|
|
98
103
|
let maxWidth = containerRect.width;
|
|
99
|
-
if (maxWidth ===
|
|
104
|
+
if (maxWidth === lastMaxWidth ||
|
|
105
|
+
(index != null && index >= fields.length && maxWidth > lastMaxWidth)) {
|
|
100
106
|
return;
|
|
101
107
|
}
|
|
102
|
-
|
|
108
|
+
state.lastMaxWidth = maxWidth;
|
|
103
109
|
// More button
|
|
104
110
|
const buttonMore = resetButton.previousElementSibling;
|
|
105
111
|
// Cached button width
|
|
@@ -174,8 +180,8 @@ export function SearchBar(props) {
|
|
|
174
180
|
const handleForm = (event) => {
|
|
175
181
|
if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
|
|
176
182
|
return;
|
|
177
|
-
if (
|
|
178
|
-
|
|
183
|
+
if (state.form == null)
|
|
184
|
+
state.form = event.currentTarget;
|
|
179
185
|
handleSubmit();
|
|
180
186
|
};
|
|
181
187
|
// Handle more button click
|
|
@@ -186,54 +192,56 @@ export function SearchBar(props) {
|
|
|
186
192
|
const moreFormChange = (event) => {
|
|
187
193
|
if (event.nativeEvent.cancelable && !event.nativeEvent.composed)
|
|
188
194
|
return;
|
|
189
|
-
if (
|
|
190
|
-
|
|
195
|
+
if (state.moreForm == null)
|
|
196
|
+
state.moreForm = event.currentTarget;
|
|
191
197
|
handleSubmit();
|
|
192
198
|
};
|
|
193
199
|
// Reset
|
|
194
200
|
const handleReset = () => {
|
|
195
201
|
// Clear form values
|
|
196
|
-
if (
|
|
197
|
-
resetForm(
|
|
198
|
-
if (
|
|
199
|
-
resetForm(
|
|
202
|
+
if (state.form != null)
|
|
203
|
+
resetForm(state.form);
|
|
204
|
+
if (state.moreForm != null)
|
|
205
|
+
resetForm(state.moreForm);
|
|
200
206
|
// Resubmit
|
|
201
207
|
handleSubmitInstant(true);
|
|
202
208
|
};
|
|
203
209
|
// Submit
|
|
204
210
|
const handleSubmit = (delay = 480) => {
|
|
205
|
-
if (
|
|
206
|
-
clearTimeout(
|
|
211
|
+
if (state.submitSeed != null) {
|
|
212
|
+
clearTimeout(state.submitSeed);
|
|
207
213
|
}
|
|
208
214
|
// Delay the change
|
|
209
|
-
|
|
215
|
+
state.submitSeed = window.setTimeout(handleSubmitInstant, delay);
|
|
210
216
|
};
|
|
211
217
|
// Submit at once
|
|
212
218
|
const handleSubmitInstant = (reset = false) => {
|
|
213
219
|
// Reset timeout
|
|
214
|
-
|
|
220
|
+
state.submitSeed = undefined;
|
|
215
221
|
// Prepare data
|
|
216
|
-
const data = new FormData(
|
|
217
|
-
if (
|
|
218
|
-
DomUtils.mergeFormData(data, new FormData(
|
|
222
|
+
const data = new FormData(state.form);
|
|
223
|
+
if (state.moreForm != null) {
|
|
224
|
+
DomUtils.mergeFormData(data, new FormData(state.moreForm));
|
|
219
225
|
}
|
|
220
226
|
onSubmit(data, reset);
|
|
221
227
|
};
|
|
222
228
|
// First loading
|
|
223
229
|
React.useEffect(() => {
|
|
224
|
-
// Delayed way
|
|
225
|
-
handleSubmit(100);
|
|
226
230
|
return () => {
|
|
227
231
|
// Clear the seeds
|
|
228
|
-
if (
|
|
229
|
-
clearTimeout(
|
|
232
|
+
if (state.submitSeed != null)
|
|
233
|
+
clearTimeout(state.submitSeed);
|
|
230
234
|
};
|
|
231
235
|
}, []);
|
|
236
|
+
React.useEffect(() => {
|
|
237
|
+
// Delayed way
|
|
238
|
+
handleSubmit(100);
|
|
239
|
+
}, [className]);
|
|
232
240
|
// Layout
|
|
233
241
|
return (React.createElement(React.Fragment, null,
|
|
234
242
|
React.createElement("form", { id: "SearchBarForm", className: className, onChange: handleForm, ref: (form) => {
|
|
235
243
|
if (form)
|
|
236
|
-
|
|
244
|
+
state.form = form;
|
|
237
245
|
} },
|
|
238
246
|
React.createElement(Stack, { ref: dimensions[0][0], justifyContent: "center", alignItems: "center", direction: "row", spacing: 1, height: innerHeight, sx: {
|
|
239
247
|
'& > :not(style)': {
|
|
@@ -260,7 +268,7 @@ export function SearchBar(props) {
|
|
|
260
268
|
}, open: open, onClose: () => updateOpen(false) },
|
|
261
269
|
React.createElement("form", { onChange: moreFormChange, ref: (form) => {
|
|
262
270
|
if (form)
|
|
263
|
-
|
|
271
|
+
state.moreForm = form;
|
|
264
272
|
} },
|
|
265
273
|
React.createElement(Stack, { direction: "column", alignItems: "stretch", spacing: 2, padding: 2 }, moreItems))))));
|
|
266
274
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FabBox } from '../FabBox';
|
|
3
3
|
import { ScrollTopFab } from '../ScrollTopFab';
|
|
4
|
-
import { PullToRefreshUI } from '../PullToRefreshUI';
|
|
5
4
|
import { Labels } from '../../app/Labels';
|
|
6
5
|
import { MUGlobal } from '../MUGlobal';
|
|
7
6
|
import { MoreFab } from '../MoreFab';
|
|
8
7
|
import { ReactAppStateDetector } from '../../app/ReactApp';
|
|
9
8
|
import { Container, Fab } from '@mui/material';
|
|
10
9
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
11
|
-
/**
|
|
12
|
-
* Default pull container
|
|
13
|
-
*/
|
|
14
|
-
export const CommonPagePullContainer = '#page-container';
|
|
15
10
|
/**
|
|
16
11
|
* Default scroll container
|
|
17
12
|
*/
|
|
@@ -22,7 +17,7 @@ export const CommonPageScrollContainer = global;
|
|
|
22
17
|
*/
|
|
23
18
|
export function CommonPage(props) {
|
|
24
19
|
// Destruct
|
|
25
|
-
const { children, disableGutters = true, fabButtons, fabColumnDirection, fabPaddingAdjust = 1.5, fabSize = 'small', maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, targetFields,
|
|
20
|
+
const { children, disableGutters = true, fabButtons, fabColumnDirection, fabPaddingAdjust = 1.5, fabSize = 'small', maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, targetFields, sx = {}, ...rest } = props;
|
|
26
21
|
// Merge style
|
|
27
22
|
Object.assign(sx, {
|
|
28
23
|
padding: paddings
|
|
@@ -59,9 +54,5 @@ export function CommonPage(props) {
|
|
|
59
54
|
onRefresh != null && (React.createElement(Fab, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: 'none', md: 'inherit' } } },
|
|
60
55
|
React.createElement(RefreshIcon, null))),
|
|
61
56
|
React.createElement(MoreFab, { size: fabSize, title: labels.more, actions: moreActions })),
|
|
62
|
-
children)
|
|
63
|
-
onRefresh != null && pullContainer != null && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: onRefresh, shouldPullToRefresh: () => {
|
|
64
|
-
const container = document.querySelector(pullContainer);
|
|
65
|
-
return !(container === null || container === void 0 ? void 0 : container.scrollTop);
|
|
66
|
-
} }))));
|
|
57
|
+
children)));
|
|
67
58
|
}
|
|
@@ -13,7 +13,7 @@ import { CommonPage } from './CommonPage';
|
|
|
13
13
|
* @returns Component
|
|
14
14
|
*/
|
|
15
15
|
export function DataGridPage(props) {
|
|
16
|
-
var _a
|
|
16
|
+
var _a;
|
|
17
17
|
// Destruct
|
|
18
18
|
const { adjustHeight, fields, fieldTemplate, height, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
|
|
19
19
|
(_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
|
|
@@ -42,7 +42,8 @@ export function DataGridPage(props) {
|
|
|
42
42
|
const rect = dimensions[0][2];
|
|
43
43
|
React.useEffect(() => {
|
|
44
44
|
if (rect != null && rect.height > 50 && height == null) {
|
|
45
|
-
let gridHeight =
|
|
45
|
+
let gridHeight = document.documentElement.clientHeight -
|
|
46
|
+
Math.round(rect.top + rect.height + 1);
|
|
46
47
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
47
48
|
const paddingBottom = parseFloat(style.paddingBottom);
|
|
48
49
|
if (!isNaN(paddingBottom))
|
|
@@ -69,12 +70,8 @@ export function DataGridPage(props) {
|
|
|
69
70
|
return;
|
|
70
71
|
ref.reset({ data });
|
|
71
72
|
}, [ref, data]);
|
|
72
|
-
// Pull container id
|
|
73
|
-
const pullContainer = ((_b = states.element) === null || _b === void 0 ? void 0 : _b.parentElement)
|
|
74
|
-
? '.DataGridEx-Body'
|
|
75
|
-
: undefined;
|
|
76
73
|
// Layout
|
|
77
|
-
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: states.element
|
|
74
|
+
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: states.element },
|
|
78
75
|
React.createElement(Stack, null,
|
|
79
76
|
React.createElement(Box, { ref: dimensions[0][0], sx: {
|
|
80
77
|
paddingBottom: pageProps.paddings
|
|
@@ -48,7 +48,8 @@ export function FixedListPage(props) {
|
|
|
48
48
|
const rect = dimensions[0][2];
|
|
49
49
|
const list = React.useMemo(() => {
|
|
50
50
|
if (rect != null && rect.height > 50) {
|
|
51
|
-
let height =
|
|
51
|
+
let height = document.documentElement.clientHeight -
|
|
52
|
+
Math.round(rect.top + rect.height + 1);
|
|
52
53
|
if (adjustHeight != null) {
|
|
53
54
|
height -= adjustHeight(height);
|
|
54
55
|
}
|
|
@@ -61,13 +62,9 @@ export function FixedListPage(props) {
|
|
|
61
62
|
}, ...rest })));
|
|
62
63
|
}
|
|
63
64
|
}, [rect]);
|
|
64
|
-
// Pull container id
|
|
65
|
-
const pullContainer = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.parentElement)
|
|
66
|
-
? '#' + (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.parentElement.id)
|
|
67
|
-
: undefined;
|
|
68
65
|
const { paddings, ...pageRest } = pageProps;
|
|
69
66
|
// Layout
|
|
70
|
-
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer
|
|
67
|
+
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer },
|
|
71
68
|
React.createElement(Stack, null,
|
|
72
69
|
React.createElement(Box, { ref: dimensions[0][0], sx: { padding: paddings } },
|
|
73
70
|
React.createElement(SearchBar, { fields: fields, onSubmit: onSubmit })),
|
package/lib/mu/pages/ListPage.js
CHANGED
|
@@ -5,7 +5,7 @@ import useCombinedRefs from '../../uses/useCombinedRefs';
|
|
|
5
5
|
import { MUGlobal } from '../MUGlobal';
|
|
6
6
|
import { ScrollerListEx } from '../ScrollerListEx';
|
|
7
7
|
import { SearchBar } from '../SearchBar';
|
|
8
|
-
import { CommonPage,
|
|
8
|
+
import { CommonPage, CommonPageScrollContainer } from './CommonPage';
|
|
9
9
|
/**
|
|
10
10
|
* List page
|
|
11
11
|
* @param props Props
|
|
@@ -41,7 +41,7 @@ export function ListPage(props) {
|
|
|
41
41
|
return loadData(data);
|
|
42
42
|
};
|
|
43
43
|
// Layout
|
|
44
|
-
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer
|
|
44
|
+
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer },
|
|
45
45
|
React.createElement(Stack, null,
|
|
46
46
|
React.createElement(Box, { sx: {
|
|
47
47
|
paddingBottom: pageProps.paddings
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { Box, Stack } from '@mui/material';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { GridDataGet } from '../../components/GridLoader';
|
|
4
|
-
import useCombinedRefs from '../../uses/useCombinedRefs';
|
|
5
|
-
import { useDimensions } from '../../uses/useDimensions';
|
|
6
|
-
import { DataGridEx, DataGridExCalColumns } from '../DataGridEx';
|
|
7
2
|
import { MUGlobal } from '../MUGlobal';
|
|
8
|
-
import {
|
|
9
|
-
import { SearchBar } from '../SearchBar';
|
|
3
|
+
import { ResponsibleContainer } from '../ResponsibleContainer';
|
|
10
4
|
import { CommonPage } from './CommonPage';
|
|
11
5
|
/**
|
|
12
6
|
* Fixed height list page
|
|
@@ -14,119 +8,39 @@ import { CommonPage } from './CommonPage';
|
|
|
14
8
|
* @returns Component
|
|
15
9
|
*/
|
|
16
10
|
export function ResponsivePage(props) {
|
|
17
|
-
var _a
|
|
11
|
+
var _a;
|
|
18
12
|
// Destruct
|
|
19
|
-
const {
|
|
13
|
+
const { pageProps = {}, ...rest } = props;
|
|
20
14
|
(_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
height
|
|
26
|
-
});
|
|
27
|
-
const localLoadData = (props) => {
|
|
28
|
-
const data = GridDataGet(props, fieldTemplate);
|
|
29
|
-
return loadData(data);
|
|
30
|
-
};
|
|
31
|
-
const refs = useCombinedRefs(mRef, (ref) => {
|
|
32
|
-
if (ref == null)
|
|
33
|
-
return;
|
|
34
|
-
states.ref = ref;
|
|
35
|
-
// setStates({ ref });
|
|
36
|
-
});
|
|
37
|
-
// On submit callback
|
|
38
|
-
const onSubmit = (data, _reset) => {
|
|
39
|
-
setStates({ data });
|
|
40
|
-
};
|
|
41
|
-
// Watch container
|
|
42
|
-
const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
|
|
43
|
-
const rect = dimensions[0][2];
|
|
44
|
-
const showDataGrid = ((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0) >= dataGridMinWidth;
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
if (rect != null && rect.height > 50 && height == null) {
|
|
47
|
-
let gridHeight = window.innerHeight - Math.round(rect.top + rect.height + 1);
|
|
48
|
-
const style = window.getComputedStyle(dimensions[0][1]);
|
|
49
|
-
const boxPadding = parseFloat(style.paddingLeft);
|
|
50
|
-
if (!isNaN(boxPadding))
|
|
51
|
-
gridHeight -= 2 * boxPadding;
|
|
52
|
-
if (adjustHeight != null) {
|
|
53
|
-
gridHeight -= adjustHeight(gridHeight);
|
|
54
|
-
}
|
|
55
|
-
if (gridHeight !== states.height)
|
|
56
|
-
setStates({ height: gridHeight });
|
|
57
|
-
}
|
|
58
|
-
}, [rect]);
|
|
59
|
-
const { paddings, ...pageRest } = pageProps;
|
|
60
|
-
const list = React.useMemo(() => {
|
|
61
|
-
const gridHeight = states.height;
|
|
62
|
-
if (gridHeight == null)
|
|
63
|
-
return;
|
|
64
|
-
// Show in a row when under DataGrid
|
|
65
|
-
pageProps.fabColumnDirection = !showDataGrid;
|
|
66
|
-
if (showDataGrid) {
|
|
67
|
-
// Delete
|
|
68
|
-
delete rest.itemRenderer;
|
|
69
|
-
return (React.createElement(Box, { sx: {
|
|
70
|
-
padding: paddings
|
|
71
|
-
} },
|
|
72
|
-
React.createElement(DataGridEx, { autoLoad: false, height: gridHeight, loadData: localLoadData, mRef: refs, columns: columns, outerRef: (element) => {
|
|
73
|
-
if (element != null)
|
|
74
|
-
setStates({ element });
|
|
75
|
-
}, ...rest })));
|
|
76
|
-
}
|
|
77
|
-
// Delete
|
|
78
|
-
delete rest.checkable;
|
|
79
|
-
delete rest.borderRowsCount;
|
|
80
|
-
delete rest.bottomHeight;
|
|
81
|
-
delete rest.footerItemRenderer;
|
|
82
|
-
delete rest.headerHeight;
|
|
83
|
-
delete rest.hideFooter;
|
|
84
|
-
delete rest.hoverColor;
|
|
85
|
-
delete rest.selectable;
|
|
86
|
-
// Half
|
|
87
|
-
const halfPadding = MUGlobal.half(paddings);
|
|
88
|
-
const style = window.getComputedStyle(dimensions[0][1]);
|
|
89
|
-
const boxPadding = parseFloat(style.paddingLeft);
|
|
90
|
-
return (React.createElement(Box, { sx: {
|
|
91
|
-
height: gridHeight + (isNaN(boxPadding) ? 0 : boxPadding),
|
|
92
|
-
paddingTop: halfPadding,
|
|
93
|
-
paddingBottom: halfPadding
|
|
94
|
-
} },
|
|
95
|
-
React.createElement(ScrollerListEx, { autoLoad: false, height: gridHeight, innerItemRenderer: innerItemRenderer, itemSize: itemSize, loadData: localLoadData, mRef: refs, oRef: (element) => {
|
|
96
|
-
if (element != null)
|
|
97
|
-
setStates({ element });
|
|
98
|
-
}, ...rest })));
|
|
99
|
-
}, [states.height, showDataGrid, localLoadData]);
|
|
100
|
-
const sizeRef = React.useRef();
|
|
101
|
-
const { ref, data } = states;
|
|
102
|
-
React.useEffect(() => {
|
|
103
|
-
if (ref == null || data == null || rect == null)
|
|
104
|
-
return;
|
|
105
|
-
// Resize without reset
|
|
106
|
-
if (sizeRef.current == null) {
|
|
107
|
-
sizeRef.current = [rect.width, rect.height];
|
|
108
|
-
}
|
|
109
|
-
else if (sizeRef.current[0] !== rect.width ||
|
|
110
|
-
sizeRef.current[1] !== rect.height) {
|
|
111
|
-
sizeRef.current = [rect.width, rect.height];
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
ref.reset({ data });
|
|
115
|
-
});
|
|
116
|
-
// Pull container id
|
|
117
|
-
const pullContainer = states.element
|
|
118
|
-
? showDataGrid
|
|
119
|
-
? '.DataGridEx-Body'
|
|
120
|
-
: '.ScrollerListEx-Body'
|
|
121
|
-
: undefined;
|
|
15
|
+
const { paddings, fabColumnDirection, ...pageRest } = pageProps;
|
|
16
|
+
// State
|
|
17
|
+
const [scrollContainer, setScrollContainer] = React.useState();
|
|
18
|
+
const [direction, setDirection] = React.useState(fabColumnDirection);
|
|
122
19
|
// Layout
|
|
123
|
-
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer:
|
|
124
|
-
React.createElement(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
20
|
+
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer, fabColumnDirection: direction },
|
|
21
|
+
React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (dataGrid) => {
|
|
22
|
+
if (dataGrid) {
|
|
23
|
+
return {
|
|
24
|
+
padding: paddings
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
paddingTop: paddings,
|
|
30
|
+
paddingBottom: paddings
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}, elementReady: (element, isDataGrid) => {
|
|
34
|
+
setDirection(!isDataGrid);
|
|
35
|
+
setScrollContainer(element);
|
|
36
|
+
}, listBoxSx: (dataGrid, height) => {
|
|
37
|
+
if (dataGrid) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return {
|
|
42
|
+
height: height
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}, ...rest })));
|
|
132
46
|
}
|
|
@@ -6,7 +6,7 @@ import { useDimensions } from '../../uses/useDimensions';
|
|
|
6
6
|
import { MUGlobal } from '../MUGlobal';
|
|
7
7
|
import { SearchBar } from '../SearchBar';
|
|
8
8
|
import { TableEx, TableExMinWidth } from '../TableEx';
|
|
9
|
-
import { CommonPage,
|
|
9
|
+
import { CommonPage, CommonPageScrollContainer } from './CommonPage';
|
|
10
10
|
/**
|
|
11
11
|
* Table page
|
|
12
12
|
* @param props Props
|
|
@@ -51,7 +51,8 @@ export function TablePage(props) {
|
|
|
51
51
|
const rect = dimensions[0][2];
|
|
52
52
|
const list = React.useMemo(() => {
|
|
53
53
|
if (rect != null && rect.height > 50 && rect.width >= totalWidth) {
|
|
54
|
-
let maxHeight =
|
|
54
|
+
let maxHeight = document.documentElement.clientHeight -
|
|
55
|
+
(rect.top + rect.height + 1);
|
|
55
56
|
const style = window.getComputedStyle(dimensions[0][1]);
|
|
56
57
|
const paddingBottom = parseFloat(style.paddingBottom);
|
|
57
58
|
if (!isNaN(paddingBottom))
|
|
@@ -60,7 +61,7 @@ export function TablePage(props) {
|
|
|
60
61
|
}
|
|
61
62
|
}, [rect]);
|
|
62
63
|
// Layout
|
|
63
|
-
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer
|
|
64
|
+
return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer },
|
|
64
65
|
React.createElement(Stack, null,
|
|
65
66
|
React.createElement(Box, { ref: dimensions[0][0], sx: {
|
|
66
67
|
paddingBottom: pageProps.paddings
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
interface ISize {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Detect window size
|
|
3
|
-
* @param miliseconds Miliseconds delayed
|
|
4
7
|
* @returns Window size
|
|
5
8
|
*/
|
|
6
|
-
export declare const useWindowSize: (
|
|
7
|
-
|
|
8
|
-
height: number;
|
|
9
|
-
};
|
|
9
|
+
export declare const useWindowSize: () => ISize;
|
|
10
|
+
export {};
|