@etsoo/react 1.4.29 → 1.4.33
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/ScrollerGrid.js +8 -8
- package/lib/components/ScrollerList.js +8 -8
- package/lib/mu/DataGridRenderers.js +1 -1
- package/lib/mu/ResponsibleContainer.d.ts +1 -9
- package/lib/mu/ResponsibleContainer.js +8 -12
- package/lib/mu/SearchBar.js +6 -8
- package/lib/mu/pages/ResponsivePage.js +18 -20
- package/package.json +1 -1
- package/src/components/ScrollerGrid.tsx +7 -10
- package/src/components/ScrollerList.tsx +7 -10
- package/src/mu/DataGridRenderers.tsx +1 -1
- package/src/mu/ResponsibleContainer.tsx +9 -33
- package/src/mu/SearchBar.tsx +23 -20
- package/src/mu/pages/ResponsivePage.tsx +19 -19
|
@@ -36,7 +36,7 @@ export const ScrollerGrid = (props) => {
|
|
|
36
36
|
// Update state
|
|
37
37
|
state.isNextPageLoading = true;
|
|
38
38
|
// Parameters
|
|
39
|
-
const { currentPage, batchSize, orderBy, orderByAsc, data
|
|
39
|
+
const { currentPage, batchSize, orderBy, orderByAsc, data } = state;
|
|
40
40
|
const loadProps = {
|
|
41
41
|
currentPage,
|
|
42
42
|
batchSize,
|
|
@@ -45,10 +45,10 @@ export const ScrollerGrid = (props) => {
|
|
|
45
45
|
data
|
|
46
46
|
};
|
|
47
47
|
loadData(loadProps).then((result) => {
|
|
48
|
-
state.isMounted
|
|
49
|
-
if (result == null || isMounted === false) {
|
|
48
|
+
if (result == null || state.isMounted === false) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
51
|
+
state.isMounted = true;
|
|
52
52
|
const newItems = result.length;
|
|
53
53
|
state.lastLoadedItems = newItems;
|
|
54
54
|
state.isNextPageLoading = false;
|
|
@@ -109,7 +109,8 @@ export const ScrollerGrid = (props) => {
|
|
|
109
109
|
};
|
|
110
110
|
Object.assign(state, resetState);
|
|
111
111
|
// Reset items
|
|
112
|
-
|
|
112
|
+
if (state.isMounted !== false)
|
|
113
|
+
setRows([]);
|
|
113
114
|
};
|
|
114
115
|
React.useImperativeHandle(mRef, () => ({
|
|
115
116
|
scrollTo(params) {
|
|
@@ -184,13 +185,12 @@ export const ScrollerGrid = (props) => {
|
|
|
184
185
|
shouldForceUpdate: true
|
|
185
186
|
});
|
|
186
187
|
}, [width]);
|
|
187
|
-
//
|
|
188
|
-
const { autoLoad: stateAutoLoad, hasNextPage, currentPage } = state;
|
|
188
|
+
// Rows
|
|
189
189
|
const rowLength = rows.length;
|
|
190
190
|
// Row count
|
|
191
|
-
const rowCount = hasNextPage ? rowLength + 1 : rowLength;
|
|
191
|
+
const rowCount = state.hasNextPage ? rowLength + 1 : rowLength;
|
|
192
192
|
// Auto load data when current page is 0
|
|
193
|
-
if (currentPage === 0 &&
|
|
193
|
+
if (state.currentPage === 0 && state.autoLoad)
|
|
194
194
|
loadDataLocal();
|
|
195
195
|
// Layout
|
|
196
196
|
return (React.createElement(React.Fragment, null,
|
|
@@ -53,7 +53,7 @@ export const ScrollerList = (props) => {
|
|
|
53
53
|
// Update state
|
|
54
54
|
state.isNextPageLoading = true;
|
|
55
55
|
// Parameters
|
|
56
|
-
const { currentPage, batchSize, orderBy, orderByAsc, data
|
|
56
|
+
const { currentPage, batchSize, orderBy, orderByAsc, data } = state;
|
|
57
57
|
const loadProps = {
|
|
58
58
|
currentPage,
|
|
59
59
|
batchSize,
|
|
@@ -62,10 +62,10 @@ export const ScrollerList = (props) => {
|
|
|
62
62
|
data
|
|
63
63
|
};
|
|
64
64
|
loadData(loadProps).then((result) => {
|
|
65
|
-
state.isMounted
|
|
66
|
-
if (result == null || isMounted === false) {
|
|
65
|
+
if (result == null || state.isMounted === false) {
|
|
67
66
|
return;
|
|
68
67
|
}
|
|
68
|
+
state.isMounted = true;
|
|
69
69
|
const newItems = result.length;
|
|
70
70
|
state.lastLoadedItems = newItems;
|
|
71
71
|
state.hasNextPage = newItems >= loadBatchSize;
|
|
@@ -121,7 +121,8 @@ export const ScrollerList = (props) => {
|
|
|
121
121
|
};
|
|
122
122
|
Object.assign(state, resetState);
|
|
123
123
|
// Reset
|
|
124
|
-
|
|
124
|
+
if (state.isMounted !== false)
|
|
125
|
+
setRows([]);
|
|
125
126
|
},
|
|
126
127
|
scrollTo(scrollOffset) {
|
|
127
128
|
refMethods.scrollTo(scrollOffset);
|
|
@@ -160,8 +161,7 @@ export const ScrollerList = (props) => {
|
|
|
160
161
|
state.isMounted = false;
|
|
161
162
|
};
|
|
162
163
|
}, []);
|
|
163
|
-
//
|
|
164
|
-
const { autoLoad: stateAutoLoad, hasNextPage, currentPage } = state;
|
|
164
|
+
// Row count
|
|
165
165
|
const rowCount = rows.length;
|
|
166
166
|
// Local items renderer callback
|
|
167
167
|
const onItemsRenderedLocal = (props) => {
|
|
@@ -175,9 +175,9 @@ export const ScrollerList = (props) => {
|
|
|
175
175
|
onItemsRendered(props);
|
|
176
176
|
};
|
|
177
177
|
// Item count
|
|
178
|
-
const itemCount = hasNextPage ? rowCount + 1 : rowCount;
|
|
178
|
+
const itemCount = state.hasNextPage ? rowCount + 1 : rowCount;
|
|
179
179
|
// Auto load data when current page is 0
|
|
180
|
-
if (currentPage === 0 &&
|
|
180
|
+
if (state.currentPage === 0 && state.autoLoad)
|
|
181
181
|
loadDataLocal();
|
|
182
182
|
// Layout
|
|
183
183
|
return typeof itemSize === 'function' ? (React.createElement(VariableSizeList, { height: height, width: width, itemCount: itemCount, itemSize: itemSize, outerRef: refs, ref: listRef, style: style, onItemsRendered: onItemsRenderedLocal, ...rest }, itemRendererLocal)) : (React.createElement(FixedSizeList, { height: height, width: width, itemCount: itemCount, itemSize: itemSize, outerRef: refs, ref: listRef, style: style, onItemsRendered: onItemsRenderedLocal, ...rest }, itemRendererLocal));
|
|
@@ -67,7 +67,7 @@ export var DataGridRenderers;
|
|
|
67
67
|
if (value)
|
|
68
68
|
return React.createElement(CheckIcon, { fontSize: "small" });
|
|
69
69
|
else
|
|
70
|
-
return React.createElement(ClearIcon, { fontSize: "small" });
|
|
70
|
+
return React.createElement(ClearIcon, { fontSize: "small", color: "error" });
|
|
71
71
|
}
|
|
72
72
|
// To string
|
|
73
73
|
return new String(value);
|
|
@@ -23,7 +23,7 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
23
23
|
/**
|
|
24
24
|
* Container box SX (dataGrid determines the case)
|
|
25
25
|
*/
|
|
26
|
-
containerBoxSx?: (dataGrid
|
|
26
|
+
containerBoxSx?: (dataGrid?: boolean) => SxProps<Theme>;
|
|
27
27
|
/**
|
|
28
28
|
* Min width to show Datagrid
|
|
29
29
|
*/
|
|
@@ -52,10 +52,6 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
52
52
|
* Item size, a function indicates its a variable size list
|
|
53
53
|
*/
|
|
54
54
|
itemSize: ((index: number) => number) | number;
|
|
55
|
-
/**
|
|
56
|
-
* Listbox SX (dataGrid determines the case)
|
|
57
|
-
*/
|
|
58
|
-
listBoxSx?: (dataGrid: boolean, height: number) => SxProps<Theme>;
|
|
59
55
|
/**
|
|
60
56
|
* Load data callback
|
|
61
57
|
*/
|
|
@@ -76,10 +72,6 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
|
|
|
76
72
|
* Pull to refresh data
|
|
77
73
|
*/
|
|
78
74
|
pullToRefresh?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Searchbox SX
|
|
81
|
-
*/
|
|
82
|
-
searchBoxSx?: SxProps<Theme>;
|
|
83
75
|
/**
|
|
84
76
|
* Size ready to read miliseconds span
|
|
85
77
|
*/
|
|
@@ -12,8 +12,8 @@ import { SearchBar } from './SearchBar';
|
|
|
12
12
|
function getDefaultSearchBoxSx(paddings) {
|
|
13
13
|
const half = MUGlobal.half(paddings);
|
|
14
14
|
return {
|
|
15
|
-
paddingLeft: (theme) => theme.spacing(
|
|
16
|
-
paddingRight: (theme) => theme.spacing(
|
|
15
|
+
paddingLeft: (theme) => theme.spacing(1),
|
|
16
|
+
paddingRight: (theme) => theme.spacing(1),
|
|
17
17
|
paddingTop: half,
|
|
18
18
|
marginBottom: half
|
|
19
19
|
};
|
|
@@ -25,7 +25,7 @@ function getDefaultSearchBoxSx(paddings) {
|
|
|
25
25
|
*/
|
|
26
26
|
export function ResponsibleContainer(props) {
|
|
27
27
|
// Destruct
|
|
28
|
-
const { adjustHeight, columns, containerBoxSx, dataGridMinWidth = DataGridExCalColumns(columns).total, elementReady, fields, fieldTemplate, height,
|
|
28
|
+
const { adjustHeight, columns, containerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, sizeReadyMiliseconds = 0, ...rest } = props;
|
|
29
29
|
// Labels
|
|
30
30
|
const labels = Labels.CommonPage;
|
|
31
31
|
// Refs
|
|
@@ -64,7 +64,6 @@ export function ResponsibleContainer(props) {
|
|
|
64
64
|
// Last rect
|
|
65
65
|
const lastRect = state.rect;
|
|
66
66
|
// 32 = scroll bar width
|
|
67
|
-
console.log(lastRect, rect);
|
|
68
67
|
if (lastRect != null &&
|
|
69
68
|
state.mounted !== true &&
|
|
70
69
|
Math.abs(rect.width - lastRect.width) <= 32 &&
|
|
@@ -107,9 +106,7 @@ export function ResponsibleContainer(props) {
|
|
|
107
106
|
// Delete
|
|
108
107
|
delete rest.itemRenderer;
|
|
109
108
|
return [
|
|
110
|
-
React.createElement(Box, {
|
|
111
|
-
? undefined
|
|
112
|
-
: listBoxSx(true, heightLocal) },
|
|
109
|
+
React.createElement(Box, { className: "DataGridBox" },
|
|
113
110
|
React.createElement(DataGridEx, { autoLoad: !hasFields, height: heightLocal, width: rect.width, loadData: localLoadData, mRef: mRefs, outerRef: (element) => {
|
|
114
111
|
if (element != null && elementReady)
|
|
115
112
|
elementReady(element, true);
|
|
@@ -127,9 +124,7 @@ export function ResponsibleContainer(props) {
|
|
|
127
124
|
delete rest.hoverColor;
|
|
128
125
|
delete rest.selectable;
|
|
129
126
|
return [
|
|
130
|
-
React.createElement(Box, { sx:
|
|
131
|
-
? undefined
|
|
132
|
-
: listBoxSx(false, heightLocal) },
|
|
127
|
+
React.createElement(Box, { className: "ListBox", sx: { height: heightLocal } },
|
|
133
128
|
React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, oRef: (element) => {
|
|
134
129
|
if (element != null && elementReady)
|
|
135
130
|
elementReady(element, false);
|
|
@@ -149,11 +144,12 @@ export function ResponsibleContainer(props) {
|
|
|
149
144
|
? '.DataGridEx-Body'
|
|
150
145
|
: '.ScrollerListEx-Body';
|
|
151
146
|
// Layout
|
|
152
|
-
return (React.createElement(Box, { sx: containerBoxSx == null
|
|
147
|
+
return (React.createElement(Box, { sx: containerBoxSx == null
|
|
153
148
|
? undefined
|
|
154
149
|
: containerBoxSx(showDataGrid) },
|
|
155
150
|
React.createElement(Stack, null,
|
|
156
|
-
React.createElement(Box, { ref: dimensions[0][0],
|
|
151
|
+
React.createElement(Box, { ref: dimensions[0][0], className: "SearchBox" }, searchBar),
|
|
152
|
+
list),
|
|
157
153
|
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: () => {
|
|
158
154
|
const container = document.querySelector(pullContainer);
|
|
159
155
|
return !(container === null || container === void 0 ? void 0 : container.scrollTop);
|
package/lib/mu/SearchBar.js
CHANGED
|
@@ -52,7 +52,6 @@ const setChildState = (child, enabled) => {
|
|
|
52
52
|
* @returns Component
|
|
53
53
|
*/
|
|
54
54
|
export function SearchBar(props) {
|
|
55
|
-
var _a;
|
|
56
55
|
// Destruct
|
|
57
56
|
const { className, fields, innerHeight = 40, onSubmit } = props;
|
|
58
57
|
// Labels
|
|
@@ -65,13 +64,12 @@ export function SearchBar(props) {
|
|
|
65
64
|
// Drawer open / close
|
|
66
65
|
const [open, updateOpen] = React.useState(false);
|
|
67
66
|
// State
|
|
68
|
-
const state = React.useRef({ hasMore: true }).current;
|
|
69
|
-
const lastMaxWidth = (_a = state.lastMaxWidth) !== null && _a !== void 0 ? _a : 9999;
|
|
67
|
+
const state = React.useRef({ hasMore: true, lastMaxWidth: 9999 }).current;
|
|
70
68
|
// Watch container
|
|
71
69
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
72
70
|
// Same logic from resetButtonRef
|
|
73
|
-
if (rect.width === lastMaxWidth ||
|
|
74
|
-
(!state.hasMore && rect.width > lastMaxWidth))
|
|
71
|
+
if (rect.width === state.lastMaxWidth ||
|
|
72
|
+
(!state.hasMore && rect.width > state.lastMaxWidth))
|
|
75
73
|
return false;
|
|
76
74
|
// Len
|
|
77
75
|
const len = target.children.length;
|
|
@@ -79,7 +77,7 @@ export function SearchBar(props) {
|
|
|
79
77
|
var classList = target.children[i].classList;
|
|
80
78
|
classList.remove('showChild');
|
|
81
79
|
}
|
|
82
|
-
});
|
|
80
|
+
}, 0);
|
|
83
81
|
// Show or hide element
|
|
84
82
|
const setElementVisible = (element, visible) => {
|
|
85
83
|
element.classList.remove(visible ? 'hiddenChild' : 'showChild');
|
|
@@ -99,8 +97,8 @@ export function SearchBar(props) {
|
|
|
99
97
|
return;
|
|
100
98
|
// Container width
|
|
101
99
|
let maxWidth = containerRect.width;
|
|
102
|
-
if (maxWidth === lastMaxWidth ||
|
|
103
|
-
(!state.hasMore && maxWidth > lastMaxWidth)) {
|
|
100
|
+
if (maxWidth === state.lastMaxWidth ||
|
|
101
|
+
(!state.hasMore && maxWidth > state.lastMaxWidth)) {
|
|
104
102
|
return;
|
|
105
103
|
}
|
|
106
104
|
state.lastMaxWidth = maxWidth;
|
|
@@ -13,34 +13,32 @@ export function ResponsivePage(props) {
|
|
|
13
13
|
const { pageProps = {}, ...rest } = props;
|
|
14
14
|
(_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
|
|
15
15
|
const { paddings, fabColumnDirection, ...pageRest } = pageProps;
|
|
16
|
+
const half = MUGlobal.half(paddings);
|
|
16
17
|
// State
|
|
17
18
|
const [scrollContainer, setScrollContainer] = React.useState();
|
|
18
19
|
const [direction, setDirection] = React.useState(fabColumnDirection);
|
|
19
20
|
// Layout
|
|
20
21
|
return (React.createElement(CommonPage, { ...pageRest, paddings: {}, scrollContainer: scrollContainer, fabColumnDirection: direction },
|
|
21
22
|
React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (dataGrid) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
// .SearchBox keep the same to avoid flick when switching between DataGrid and List
|
|
24
|
+
return {
|
|
25
|
+
'& .SearchBox': {
|
|
26
|
+
marginLeft: paddings,
|
|
27
|
+
marginTop: paddings,
|
|
28
|
+
marginRight: paddings,
|
|
29
|
+
marginBottom: half
|
|
30
|
+
},
|
|
31
|
+
'& .ListBox': {
|
|
32
|
+
marginBottom: paddings
|
|
33
|
+
},
|
|
34
|
+
'& .DataGridBox': {
|
|
35
|
+
marginLeft: paddings,
|
|
36
|
+
marginRight: paddings,
|
|
37
|
+
marginBottom: paddings
|
|
38
|
+
}
|
|
39
|
+
};
|
|
33
40
|
}, elementReady: (element, isDataGrid) => {
|
|
34
41
|
setDirection(!isDataGrid);
|
|
35
42
|
setScrollContainer(element);
|
|
36
|
-
}, listBoxSx: (dataGrid, height) => {
|
|
37
|
-
if (dataGrid) {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return {
|
|
42
|
-
height: height
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
43
|
}, ...rest })));
|
|
46
44
|
}
|
package/package.json
CHANGED
|
@@ -198,8 +198,7 @@ export const ScrollerGrid = <T extends Record<string, unknown>>(
|
|
|
198
198
|
state.isNextPageLoading = true;
|
|
199
199
|
|
|
200
200
|
// Parameters
|
|
201
|
-
const { currentPage, batchSize, orderBy, orderByAsc, data
|
|
202
|
-
state;
|
|
201
|
+
const { currentPage, batchSize, orderBy, orderByAsc, data } = state;
|
|
203
202
|
|
|
204
203
|
const loadProps: GridLoadDataProps = {
|
|
205
204
|
currentPage,
|
|
@@ -210,11 +209,10 @@ export const ScrollerGrid = <T extends Record<string, unknown>>(
|
|
|
210
209
|
};
|
|
211
210
|
|
|
212
211
|
loadData(loadProps).then((result) => {
|
|
213
|
-
state.isMounted
|
|
214
|
-
|
|
215
|
-
if (result == null || isMounted === false) {
|
|
212
|
+
if (result == null || state.isMounted === false) {
|
|
216
213
|
return;
|
|
217
214
|
}
|
|
215
|
+
state.isMounted = true;
|
|
218
216
|
|
|
219
217
|
const newItems = result.length;
|
|
220
218
|
state.lastLoadedItems = newItems;
|
|
@@ -291,7 +289,7 @@ export const ScrollerGrid = <T extends Record<string, unknown>>(
|
|
|
291
289
|
Object.assign(state, resetState);
|
|
292
290
|
|
|
293
291
|
// Reset items
|
|
294
|
-
setRows([]);
|
|
292
|
+
if (state.isMounted !== false) setRows([]);
|
|
295
293
|
};
|
|
296
294
|
|
|
297
295
|
React.useImperativeHandle(
|
|
@@ -378,15 +376,14 @@ export const ScrollerGrid = <T extends Record<string, unknown>>(
|
|
|
378
376
|
});
|
|
379
377
|
}, [width]);
|
|
380
378
|
|
|
381
|
-
//
|
|
382
|
-
const { autoLoad: stateAutoLoad, hasNextPage, currentPage } = state;
|
|
379
|
+
// Rows
|
|
383
380
|
const rowLength = rows.length;
|
|
384
381
|
|
|
385
382
|
// Row count
|
|
386
|
-
const rowCount = hasNextPage ? rowLength + 1 : rowLength;
|
|
383
|
+
const rowCount = state.hasNextPage ? rowLength + 1 : rowLength;
|
|
387
384
|
|
|
388
385
|
// Auto load data when current page is 0
|
|
389
|
-
if (currentPage === 0 &&
|
|
386
|
+
if (state.currentPage === 0 && state.autoLoad) loadDataLocal();
|
|
390
387
|
|
|
391
388
|
// Layout
|
|
392
389
|
return (
|
|
@@ -163,8 +163,7 @@ export const ScrollerList = <T extends Record<string, any>>(
|
|
|
163
163
|
state.isNextPageLoading = true;
|
|
164
164
|
|
|
165
165
|
// Parameters
|
|
166
|
-
const { currentPage, batchSize, orderBy, orderByAsc, data
|
|
167
|
-
state;
|
|
166
|
+
const { currentPage, batchSize, orderBy, orderByAsc, data } = state;
|
|
168
167
|
|
|
169
168
|
const loadProps: GridLoadDataProps = {
|
|
170
169
|
currentPage,
|
|
@@ -175,11 +174,10 @@ export const ScrollerList = <T extends Record<string, any>>(
|
|
|
175
174
|
};
|
|
176
175
|
|
|
177
176
|
loadData(loadProps).then((result) => {
|
|
178
|
-
state.isMounted
|
|
179
|
-
|
|
180
|
-
if (result == null || isMounted === false) {
|
|
177
|
+
if (result == null || state.isMounted === false) {
|
|
181
178
|
return;
|
|
182
179
|
}
|
|
180
|
+
state.isMounted = true;
|
|
183
181
|
|
|
184
182
|
const newItems = result.length;
|
|
185
183
|
state.lastLoadedItems = newItems;
|
|
@@ -250,7 +248,7 @@ export const ScrollerList = <T extends Record<string, any>>(
|
|
|
250
248
|
Object.assign(state, resetState);
|
|
251
249
|
|
|
252
250
|
// Reset
|
|
253
|
-
setRows([]);
|
|
251
|
+
if (state.isMounted !== false) setRows([]);
|
|
254
252
|
},
|
|
255
253
|
|
|
256
254
|
scrollTo(scrollOffset: number): void {
|
|
@@ -301,8 +299,7 @@ export const ScrollerList = <T extends Record<string, any>>(
|
|
|
301
299
|
};
|
|
302
300
|
}, []);
|
|
303
301
|
|
|
304
|
-
//
|
|
305
|
-
const { autoLoad: stateAutoLoad, hasNextPage, currentPage } = state;
|
|
302
|
+
// Row count
|
|
306
303
|
const rowCount = rows.length;
|
|
307
304
|
|
|
308
305
|
// Local items renderer callback
|
|
@@ -319,10 +316,10 @@ export const ScrollerList = <T extends Record<string, any>>(
|
|
|
319
316
|
};
|
|
320
317
|
|
|
321
318
|
// Item count
|
|
322
|
-
const itemCount = hasNextPage ? rowCount + 1 : rowCount;
|
|
319
|
+
const itemCount = state.hasNextPage ? rowCount + 1 : rowCount;
|
|
323
320
|
|
|
324
321
|
// Auto load data when current page is 0
|
|
325
|
-
if (currentPage === 0 &&
|
|
322
|
+
if (state.currentPage === 0 && state.autoLoad) loadDataLocal();
|
|
326
323
|
|
|
327
324
|
// Layout
|
|
328
325
|
return typeof itemSize === 'function' ? (
|
|
@@ -54,7 +54,7 @@ export interface ResponsibleContainerProps<
|
|
|
54
54
|
/**
|
|
55
55
|
* Container box SX (dataGrid determines the case)
|
|
56
56
|
*/
|
|
57
|
-
containerBoxSx?: (dataGrid
|
|
57
|
+
containerBoxSx?: (dataGrid?: boolean) => SxProps<Theme>;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Min width to show Datagrid
|
|
@@ -93,11 +93,6 @@ export interface ResponsibleContainerProps<
|
|
|
93
93
|
*/
|
|
94
94
|
itemSize: ((index: number) => number) | number;
|
|
95
95
|
|
|
96
|
-
/**
|
|
97
|
-
* Listbox SX (dataGrid determines the case)
|
|
98
|
-
*/
|
|
99
|
-
listBoxSx?: (dataGrid: boolean, height: number) => SxProps<Theme>;
|
|
100
|
-
|
|
101
96
|
/**
|
|
102
97
|
* Load data callback
|
|
103
98
|
*/
|
|
@@ -125,11 +120,6 @@ export interface ResponsibleContainerProps<
|
|
|
125
120
|
*/
|
|
126
121
|
pullToRefresh?: boolean;
|
|
127
122
|
|
|
128
|
-
/**
|
|
129
|
-
* Searchbox SX
|
|
130
|
-
*/
|
|
131
|
-
searchBoxSx?: SxProps<Theme>;
|
|
132
|
-
|
|
133
123
|
/**
|
|
134
124
|
* Size ready to read miliseconds span
|
|
135
125
|
*/
|
|
@@ -145,8 +135,8 @@ interface LocalRefs {
|
|
|
145
135
|
function getDefaultSearchBoxSx(paddings: {}): SxProps<Theme> {
|
|
146
136
|
const half = MUGlobal.half(paddings);
|
|
147
137
|
return {
|
|
148
|
-
paddingLeft: (theme) => theme.spacing(
|
|
149
|
-
paddingRight: (theme) => theme.spacing(
|
|
138
|
+
paddingLeft: (theme) => theme.spacing(1),
|
|
139
|
+
paddingRight: (theme) => theme.spacing(1),
|
|
150
140
|
paddingTop: half,
|
|
151
141
|
marginBottom: half
|
|
152
142
|
};
|
|
@@ -166,17 +156,15 @@ export function ResponsibleContainer<
|
|
|
166
156
|
adjustHeight,
|
|
167
157
|
columns,
|
|
168
158
|
containerBoxSx,
|
|
169
|
-
dataGridMinWidth = DataGridExCalColumns(columns).total,
|
|
159
|
+
dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total),
|
|
170
160
|
elementReady,
|
|
171
161
|
fields,
|
|
172
162
|
fieldTemplate,
|
|
173
163
|
height,
|
|
174
|
-
listBoxSx,
|
|
175
164
|
loadData,
|
|
176
165
|
mRef,
|
|
177
166
|
paddings = MUGlobal.pagePaddings,
|
|
178
167
|
pullToRefresh = true,
|
|
179
|
-
searchBoxSx = getDefaultSearchBoxSx(paddings),
|
|
180
168
|
sizeReadyMiliseconds = 0,
|
|
181
169
|
...rest
|
|
182
170
|
} = props;
|
|
@@ -229,7 +217,6 @@ export function ResponsibleContainer<
|
|
|
229
217
|
const lastRect = state.rect;
|
|
230
218
|
|
|
231
219
|
// 32 = scroll bar width
|
|
232
|
-
console.log(lastRect, rect);
|
|
233
220
|
if (
|
|
234
221
|
lastRect != null &&
|
|
235
222
|
state.mounted !== true &&
|
|
@@ -283,13 +270,7 @@ export function ResponsibleContainer<
|
|
|
283
270
|
delete rest.itemRenderer;
|
|
284
271
|
|
|
285
272
|
return [
|
|
286
|
-
<Box
|
|
287
|
-
sx={
|
|
288
|
-
listBoxSx == null
|
|
289
|
-
? undefined
|
|
290
|
-
: listBoxSx(true, heightLocal)
|
|
291
|
-
}
|
|
292
|
-
>
|
|
273
|
+
<Box className="DataGridBox">
|
|
293
274
|
<DataGridEx<T>
|
|
294
275
|
autoLoad={!hasFields}
|
|
295
276
|
height={heightLocal}
|
|
@@ -319,13 +300,7 @@ export function ResponsibleContainer<
|
|
|
319
300
|
delete rest.selectable;
|
|
320
301
|
|
|
321
302
|
return [
|
|
322
|
-
<Box
|
|
323
|
-
sx={
|
|
324
|
-
listBoxSx == null
|
|
325
|
-
? undefined
|
|
326
|
-
: listBoxSx(false, heightLocal)
|
|
327
|
-
}
|
|
328
|
-
>
|
|
303
|
+
<Box className="ListBox" sx={{ height: heightLocal }}>
|
|
329
304
|
<ScrollerListEx<T>
|
|
330
305
|
autoLoad={!hasFields}
|
|
331
306
|
height={heightLocal}
|
|
@@ -365,15 +340,16 @@ export function ResponsibleContainer<
|
|
|
365
340
|
return (
|
|
366
341
|
<Box
|
|
367
342
|
sx={
|
|
368
|
-
containerBoxSx == null
|
|
343
|
+
containerBoxSx == null
|
|
369
344
|
? undefined
|
|
370
345
|
: containerBoxSx(showDataGrid)
|
|
371
346
|
}
|
|
372
347
|
>
|
|
373
348
|
<Stack>
|
|
374
|
-
<Box ref={dimensions[0][0]}
|
|
349
|
+
<Box ref={dimensions[0][0]} className="SearchBox">
|
|
375
350
|
{searchBar}
|
|
376
351
|
</Box>
|
|
352
|
+
{list}
|
|
377
353
|
</Stack>
|
|
378
354
|
{pullToRefresh && pullContainer && (
|
|
379
355
|
<PullToRefreshUI
|
package/src/mu/SearchBar.tsx
CHANGED
|
@@ -104,27 +104,30 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
104
104
|
form?: HTMLFormElement;
|
|
105
105
|
moreForm?: HTMLFormElement;
|
|
106
106
|
submitSeed?: number;
|
|
107
|
-
lastMaxWidth
|
|
107
|
+
lastMaxWidth: number;
|
|
108
108
|
hasMore: boolean;
|
|
109
|
-
}>({ hasMore: true }).current;
|
|
110
|
-
const lastMaxWidth = state.lastMaxWidth ?? 9999;
|
|
109
|
+
}>({ hasMore: true, lastMaxWidth: 9999 }).current;
|
|
111
110
|
|
|
112
111
|
// Watch container
|
|
113
|
-
const { dimensions } = useDimensions(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
const { dimensions } = useDimensions(
|
|
113
|
+
1,
|
|
114
|
+
(target, rect) => {
|
|
115
|
+
// Same logic from resetButtonRef
|
|
116
|
+
if (
|
|
117
|
+
rect.width === state.lastMaxWidth ||
|
|
118
|
+
(!state.hasMore && rect.width > state.lastMaxWidth)
|
|
119
|
+
)
|
|
120
|
+
return false;
|
|
121
|
+
|
|
122
|
+
// Len
|
|
123
|
+
const len = target.children.length;
|
|
124
|
+
for (let i = 0; i < len; i++) {
|
|
125
|
+
var classList = target.children[i].classList;
|
|
126
|
+
classList.remove('showChild');
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
0
|
|
130
|
+
);
|
|
128
131
|
|
|
129
132
|
// Show or hide element
|
|
130
133
|
const setElementVisible = (element: Element, visible: boolean) => {
|
|
@@ -150,8 +153,8 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
150
153
|
// Container width
|
|
151
154
|
let maxWidth = containerRect.width;
|
|
152
155
|
if (
|
|
153
|
-
maxWidth === lastMaxWidth ||
|
|
154
|
-
(!state.hasMore && maxWidth > lastMaxWidth)
|
|
156
|
+
maxWidth === state.lastMaxWidth ||
|
|
157
|
+
(!state.hasMore && maxWidth > state.lastMaxWidth)
|
|
155
158
|
) {
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
@@ -20,6 +20,8 @@ export function ResponsivePage<
|
|
|
20
20
|
pageProps.paddings ??= MUGlobal.pagePaddings;
|
|
21
21
|
const { paddings, fabColumnDirection, ...pageRest } = pageProps;
|
|
22
22
|
|
|
23
|
+
const half = MUGlobal.half(paddings);
|
|
24
|
+
|
|
23
25
|
// State
|
|
24
26
|
const [scrollContainer, setScrollContainer] = React.useState<HTMLElement>();
|
|
25
27
|
const [direction, setDirection] = React.useState(fabColumnDirection);
|
|
@@ -35,30 +37,28 @@ export function ResponsivePage<
|
|
|
35
37
|
<ResponsibleContainer<T, F>
|
|
36
38
|
paddings={paddings}
|
|
37
39
|
containerBoxSx={(dataGrid) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
// .SearchBox keep the same to avoid flick when switching between DataGrid and List
|
|
41
|
+
return {
|
|
42
|
+
'& .SearchBox': {
|
|
43
|
+
marginLeft: paddings,
|
|
44
|
+
marginTop: paddings,
|
|
45
|
+
marginRight: paddings,
|
|
46
|
+
marginBottom: half
|
|
47
|
+
},
|
|
48
|
+
'& .ListBox': {
|
|
49
|
+
marginBottom: paddings
|
|
50
|
+
},
|
|
51
|
+
'& .DataGridBox': {
|
|
52
|
+
marginLeft: paddings,
|
|
53
|
+
marginRight: paddings,
|
|
54
|
+
marginBottom: paddings
|
|
55
|
+
}
|
|
56
|
+
};
|
|
48
57
|
}}
|
|
49
58
|
elementReady={(element, isDataGrid) => {
|
|
50
59
|
setDirection(!isDataGrid);
|
|
51
60
|
setScrollContainer(element);
|
|
52
61
|
}}
|
|
53
|
-
listBoxSx={(dataGrid, height) => {
|
|
54
|
-
if (dataGrid) {
|
|
55
|
-
return {};
|
|
56
|
-
} else {
|
|
57
|
-
return {
|
|
58
|
-
height: height
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}}
|
|
62
62
|
{...rest}
|
|
63
63
|
/>
|
|
64
64
|
</CommonPage>
|