@etsoo/react 1.4.30 → 1.4.34

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.
@@ -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, isMounted } = state;
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 = true;
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
- setRows([]);
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
- // Destruct state
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 && stateAutoLoad)
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, isMounted } = state;
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 = true;
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
- setRows([]);
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
- // Destruct state
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 && stateAutoLoad)
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: boolean) => SxProps<Theme>;
26
+ containerBoxSx?: (paddings: {}, 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
  */
@@ -9,13 +9,12 @@ 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) {
12
+ function defaultContainerBoxSx(paddings, _dataGrid) {
13
13
  const half = MUGlobal.half(paddings);
14
14
  return {
15
- paddingLeft: (theme) => theme.spacing(0.5),
16
- paddingRight: (theme) => theme.spacing(0.5),
17
- paddingTop: half,
18
- marginBottom: half
15
+ '& .SearchBox': {
16
+ marginBottom: half
17
+ }
19
18
  };
20
19
  }
21
20
  /**
@@ -25,7 +24,7 @@ function getDefaultSearchBoxSx(paddings) {
25
24
  */
26
25
  export function ResponsibleContainer(props) {
27
26
  // Destruct
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;
27
+ const { adjustHeight, columns, containerBoxSx = defaultContainerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, sizeReadyMiliseconds = 0, ...rest } = props;
29
28
  // Labels
30
29
  const labels = Labels.CommonPage;
31
30
  // Refs
@@ -64,7 +63,6 @@ export function ResponsibleContainer(props) {
64
63
  // Last rect
65
64
  const lastRect = state.rect;
66
65
  // 32 = scroll bar width
67
- console.log(lastRect, rect);
68
66
  if (lastRect != null &&
69
67
  state.mounted !== true &&
70
68
  Math.abs(rect.width - lastRect.width) <= 32 &&
@@ -107,9 +105,7 @@ export function ResponsibleContainer(props) {
107
105
  // Delete
108
106
  delete rest.itemRenderer;
109
107
  return [
110
- React.createElement(Box, { sx: listBoxSx == null
111
- ? undefined
112
- : listBoxSx(true, heightLocal) },
108
+ React.createElement(Box, { className: "DataGridBox" },
113
109
  React.createElement(DataGridEx, { autoLoad: !hasFields, height: heightLocal, width: rect.width, loadData: localLoadData, mRef: mRefs, outerRef: (element) => {
114
110
  if (element != null && elementReady)
115
111
  elementReady(element, true);
@@ -127,9 +123,7 @@ export function ResponsibleContainer(props) {
127
123
  delete rest.hoverColor;
128
124
  delete rest.selectable;
129
125
  return [
130
- React.createElement(Box, { sx: listBoxSx == null
131
- ? undefined
132
- : listBoxSx(false, heightLocal) },
126
+ React.createElement(Box, { className: "ListBox", sx: { height: heightLocal } },
133
127
  React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, oRef: (element) => {
134
128
  if (element != null && elementReady)
135
129
  elementReady(element, false);
@@ -149,11 +143,11 @@ export function ResponsibleContainer(props) {
149
143
  ? '.DataGridEx-Body'
150
144
  : '.ScrollerListEx-Body';
151
145
  // Layout
152
- return (React.createElement(Box, { sx: containerBoxSx == null || showDataGrid == null
146
+ return (React.createElement(Box, { sx: containerBoxSx == null
153
147
  ? undefined
154
- : containerBoxSx(showDataGrid) },
148
+ : containerBoxSx(paddings, showDataGrid) },
155
149
  React.createElement(Stack, null,
156
- React.createElement(Box, { ref: dimensions[0][0], sx: searchBoxSx }, searchBar),
150
+ React.createElement(Box, { ref: dimensions[0][0], className: "SearchBox" }, searchBar),
157
151
  list),
158
152
  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: () => {
159
153
  const container = document.querySelector(pullContainer);
@@ -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,14 +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
- console.log('useDimensions', state.hasMore, rect.width, lastMaxWidth);
74
- if (rect.width === lastMaxWidth ||
75
- (!state.hasMore && rect.width > lastMaxWidth))
71
+ if (rect.width === state.lastMaxWidth ||
72
+ (!state.hasMore && rect.width > state.lastMaxWidth))
76
73
  return false;
77
74
  // Len
78
75
  const len = target.children.length;
@@ -80,7 +77,7 @@ export function SearchBar(props) {
80
77
  var classList = target.children[i].classList;
81
78
  classList.remove('showChild');
82
79
  }
83
- });
80
+ }, 0);
84
81
  // Show or hide element
85
82
  const setElementVisible = (element, visible) => {
86
83
  element.classList.remove(visible ? 'hiddenChild' : 'showChild');
@@ -99,10 +96,9 @@ export function SearchBar(props) {
99
96
  containerRect.width < 10)
100
97
  return;
101
98
  // Container width
102
- console.log('resetButtonRef', state.hasMore, containerRect.width, lastMaxWidth);
103
99
  let maxWidth = containerRect.width;
104
- if (maxWidth === lastMaxWidth ||
105
- (!state.hasMore && maxWidth > lastMaxWidth)) {
100
+ if (maxWidth === state.lastMaxWidth ||
101
+ (!state.hasMore && maxWidth > state.lastMaxWidth)) {
106
102
  return;
107
103
  }
108
104
  state.lastMaxWidth = maxWidth;
@@ -18,29 +18,28 @@ export function ResponsivePage(props) {
18
18
  const [direction, setDirection] = React.useState(fabColumnDirection);
19
19
  // Layout
20
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
- }
21
+ React.createElement(ResponsibleContainer, { paddings: paddings, containerBoxSx: (paddings, _dataGrid) => {
22
+ // Half
23
+ const half = MUGlobal.half(paddings);
24
+ // .SearchBox keep the same to avoid flick when switching between DataGrid and List
25
+ return {
26
+ '& .SearchBox': {
27
+ marginLeft: paddings,
28
+ marginTop: paddings,
29
+ marginRight: paddings,
30
+ marginBottom: half
31
+ },
32
+ '& .ListBox': {
33
+ marginBottom: paddings
34
+ },
35
+ '& .DataGridBox': {
36
+ marginLeft: paddings,
37
+ marginRight: paddings,
38
+ marginBottom: paddings
39
+ }
40
+ };
33
41
  }, elementReady: (element, isDataGrid) => {
34
42
  setDirection(!isDataGrid);
35
43
  setScrollContainer(element);
36
- }, listBoxSx: (dataGrid, height) => {
37
- if (dataGrid) {
38
- return {};
39
- }
40
- else {
41
- return {
42
- height: height
43
- };
44
- }
45
44
  }, ...rest })));
46
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.30",
3
+ "version": "1.4.34",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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, isMounted } =
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 = true;
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
- // Destruct state
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 && stateAutoLoad) loadDataLocal();
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, isMounted } =
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 = true;
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
- // Destruct state
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 && stateAutoLoad) loadDataLocal();
322
+ if (state.currentPage === 0 && state.autoLoad) loadDataLocal();
326
323
 
327
324
  // Layout
328
325
  return typeof itemSize === 'function' ? (
@@ -103,7 +103,7 @@ export namespace DataGridRenderers {
103
103
  }
104
104
 
105
105
  if (value) return <CheckIcon fontSize="small" />;
106
- else return <ClearIcon fontSize="small" />;
106
+ else return <ClearIcon fontSize="small" color="error" />;
107
107
  }
108
108
 
109
109
  // To string
@@ -54,7 +54,7 @@ export interface ResponsibleContainerProps<
54
54
  /**
55
55
  * Container box SX (dataGrid determines the case)
56
56
  */
57
- containerBoxSx?: (dataGrid: boolean) => SxProps<Theme>;
57
+ containerBoxSx?: (paddings: {}, 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
  */
@@ -142,13 +132,15 @@ interface LocalRefs {
142
132
  mounted?: boolean;
143
133
  }
144
134
 
145
- function getDefaultSearchBoxSx(paddings: {}): SxProps<Theme> {
135
+ function defaultContainerBoxSx(
136
+ paddings: {},
137
+ _dataGrid?: boolean
138
+ ): SxProps<Theme> {
146
139
  const half = MUGlobal.half(paddings);
147
140
  return {
148
- paddingLeft: (theme) => theme.spacing(0.5),
149
- paddingRight: (theme) => theme.spacing(0.5),
150
- paddingTop: half,
151
- marginBottom: half
141
+ '& .SearchBox': {
142
+ marginBottom: half
143
+ }
152
144
  };
153
145
  }
154
146
 
@@ -165,18 +157,16 @@ export function ResponsibleContainer<
165
157
  const {
166
158
  adjustHeight,
167
159
  columns,
168
- containerBoxSx,
169
- dataGridMinWidth = DataGridExCalColumns(columns).total,
160
+ containerBoxSx = defaultContainerBoxSx,
161
+ dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total),
170
162
  elementReady,
171
163
  fields,
172
164
  fieldTemplate,
173
165
  height,
174
- listBoxSx,
175
166
  loadData,
176
167
  mRef,
177
168
  paddings = MUGlobal.pagePaddings,
178
169
  pullToRefresh = true,
179
- searchBoxSx = getDefaultSearchBoxSx(paddings),
180
170
  sizeReadyMiliseconds = 0,
181
171
  ...rest
182
172
  } = props;
@@ -229,7 +219,6 @@ export function ResponsibleContainer<
229
219
  const lastRect = state.rect;
230
220
 
231
221
  // 32 = scroll bar width
232
- console.log(lastRect, rect);
233
222
  if (
234
223
  lastRect != null &&
235
224
  state.mounted !== true &&
@@ -283,13 +272,7 @@ export function ResponsibleContainer<
283
272
  delete rest.itemRenderer;
284
273
 
285
274
  return [
286
- <Box
287
- sx={
288
- listBoxSx == null
289
- ? undefined
290
- : listBoxSx(true, heightLocal)
291
- }
292
- >
275
+ <Box className="DataGridBox">
293
276
  <DataGridEx<T>
294
277
  autoLoad={!hasFields}
295
278
  height={heightLocal}
@@ -319,13 +302,7 @@ export function ResponsibleContainer<
319
302
  delete rest.selectable;
320
303
 
321
304
  return [
322
- <Box
323
- sx={
324
- listBoxSx == null
325
- ? undefined
326
- : listBoxSx(false, heightLocal)
327
- }
328
- >
305
+ <Box className="ListBox" sx={{ height: heightLocal }}>
329
306
  <ScrollerListEx<T>
330
307
  autoLoad={!hasFields}
331
308
  height={heightLocal}
@@ -365,13 +342,13 @@ export function ResponsibleContainer<
365
342
  return (
366
343
  <Box
367
344
  sx={
368
- containerBoxSx == null || showDataGrid == null
345
+ containerBoxSx == null
369
346
  ? undefined
370
- : containerBoxSx(showDataGrid)
347
+ : containerBoxSx(paddings, showDataGrid)
371
348
  }
372
349
  >
373
350
  <Stack>
374
- <Box ref={dimensions[0][0]} sx={searchBoxSx}>
351
+ <Box ref={dimensions[0][0]} className="SearchBox">
375
352
  {searchBar}
376
353
  </Box>
377
354
  {list}
@@ -104,28 +104,30 @@ export function SearchBar(props: SearchBarProps) {
104
104
  form?: HTMLFormElement;
105
105
  moreForm?: HTMLFormElement;
106
106
  submitSeed?: number;
107
- lastMaxWidth?: number;
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(1, (target, rect) => {
114
- // Same logic from resetButtonRef
115
- console.log('useDimensions', state.hasMore, rect.width, lastMaxWidth);
116
- if (
117
- rect.width === lastMaxWidth ||
118
- (!state.hasMore && rect.width > 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
- });
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
+ );
129
131
 
130
132
  // Show or hide element
131
133
  const setElementVisible = (element: Element, visible: boolean) => {
@@ -149,16 +151,10 @@ export function SearchBar(props: SearchBarProps) {
149
151
  return;
150
152
 
151
153
  // Container width
152
- console.log(
153
- 'resetButtonRef',
154
- state.hasMore,
155
- containerRect.width,
156
- lastMaxWidth
157
- );
158
154
  let maxWidth = containerRect.width;
159
155
  if (
160
- maxWidth === lastMaxWidth ||
161
- (!state.hasMore && maxWidth > lastMaxWidth)
156
+ maxWidth === state.lastMaxWidth ||
157
+ (!state.hasMore && maxWidth > state.lastMaxWidth)
162
158
  ) {
163
159
  return;
164
160
  }
@@ -34,31 +34,32 @@ export function ResponsivePage<
34
34
  >
35
35
  <ResponsibleContainer<T, F>
36
36
  paddings={paddings}
37
- containerBoxSx={(dataGrid) => {
38
- if (dataGrid) {
39
- return {
40
- padding: paddings
41
- };
42
- } else {
43
- return {
44
- paddingTop: paddings,
45
- paddingBottom: paddings
46
- };
47
- }
37
+ containerBoxSx={(paddings, _dataGrid) => {
38
+ // Half
39
+ const half = MUGlobal.half(paddings);
40
+
41
+ // .SearchBox keep the same to avoid flick when switching between DataGrid and List
42
+ return {
43
+ '& .SearchBox': {
44
+ marginLeft: paddings,
45
+ marginTop: paddings,
46
+ marginRight: paddings,
47
+ marginBottom: half
48
+ },
49
+ '& .ListBox': {
50
+ marginBottom: paddings
51
+ },
52
+ '& .DataGridBox': {
53
+ marginLeft: paddings,
54
+ marginRight: paddings,
55
+ marginBottom: paddings
56
+ }
57
+ };
48
58
  }}
49
59
  elementReady={(element, isDataGrid) => {
50
60
  setDirection(!isDataGrid);
51
61
  setScrollContainer(element);
52
62
  }}
53
- listBoxSx={(dataGrid, height) => {
54
- if (dataGrid) {
55
- return {};
56
- } else {
57
- return {
58
- height: height
59
- };
60
- }
61
- }}
62
63
  {...rest}
63
64
  />
64
65
  </CommonPage>