@etsoo/react 1.4.27 → 1.4.31
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/mu/ResponsibleContainer.d.ts +1 -9
- package/lib/mu/ResponsibleContainer.js +7 -12
- package/lib/mu/SearchBar.js +7 -4
- package/lib/mu/pages/ResponsivePage.js +18 -20
- package/package.json +1 -1
- package/src/mu/ResponsibleContainer.tsx +8 -33
- package/src/mu/SearchBar.tsx +27 -14
- package/src/mu/pages/ResponsivePage.tsx +19 -19
|
@@ -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,11 @@ 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),
|
|
157
152
|
list),
|
|
158
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: () => {
|
|
159
154
|
const container = document.querySelector(pullContainer);
|
package/lib/mu/SearchBar.js
CHANGED
|
@@ -64,11 +64,12 @@ export function SearchBar(props) {
|
|
|
64
64
|
// Drawer open / close
|
|
65
65
|
const [open, updateOpen] = React.useState(false);
|
|
66
66
|
// State
|
|
67
|
-
const state = React.useRef({}).current;
|
|
67
|
+
const state = React.useRef({ hasMore: true, lastMaxWidth: 9999 }).current;
|
|
68
68
|
// Watch container
|
|
69
69
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
70
70
|
// Same logic from resetButtonRef
|
|
71
|
-
if (rect.width === state.lastMaxWidth
|
|
71
|
+
if (rect.width === state.lastMaxWidth ||
|
|
72
|
+
(!state.hasMore && rect.width > state.lastMaxWidth))
|
|
72
73
|
return false;
|
|
73
74
|
// Len
|
|
74
75
|
const len = target.children.length;
|
|
@@ -76,7 +77,7 @@ export function SearchBar(props) {
|
|
|
76
77
|
var classList = target.children[i].classList;
|
|
77
78
|
classList.remove('showChild');
|
|
78
79
|
}
|
|
79
|
-
});
|
|
80
|
+
}, 0);
|
|
80
81
|
// Show or hide element
|
|
81
82
|
const setElementVisible = (element, visible) => {
|
|
82
83
|
element.classList.remove(visible ? 'hiddenChild' : 'showChild');
|
|
@@ -96,7 +97,8 @@ export function SearchBar(props) {
|
|
|
96
97
|
return;
|
|
97
98
|
// Container width
|
|
98
99
|
let maxWidth = containerRect.width;
|
|
99
|
-
if (maxWidth === state.lastMaxWidth
|
|
100
|
+
if (maxWidth === state.lastMaxWidth ||
|
|
101
|
+
(!state.hasMore && maxWidth > state.lastMaxWidth)) {
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
102
104
|
state.lastMaxWidth = maxWidth;
|
|
@@ -158,6 +160,7 @@ export function SearchBar(props) {
|
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
// Show or hide more button
|
|
163
|
+
state.hasMore = hasMore;
|
|
161
164
|
setElementVisible(buttonMore, hasMore);
|
|
162
165
|
setElementVisible(resetButton, true);
|
|
163
166
|
// Update menu start index
|
|
@@ -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
|
@@ -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,13 +340,13 @@ 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>
|
|
377
352
|
{list}
|
package/src/mu/SearchBar.tsx
CHANGED
|
@@ -104,21 +104,30 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
104
104
|
form?: HTMLFormElement;
|
|
105
105
|
moreForm?: HTMLFormElement;
|
|
106
106
|
submitSeed?: number;
|
|
107
|
-
lastMaxWidth
|
|
108
|
-
|
|
107
|
+
lastMaxWidth: number;
|
|
108
|
+
hasMore: boolean;
|
|
109
|
+
}>({ hasMore: true, lastMaxWidth: 9999 }).current;
|
|
109
110
|
|
|
110
111
|
// Watch container
|
|
111
|
-
const { dimensions } = useDimensions(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
);
|
|
122
131
|
|
|
123
132
|
// Show or hide element
|
|
124
133
|
const setElementVisible = (element: Element, visible: boolean) => {
|
|
@@ -143,7 +152,10 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
143
152
|
|
|
144
153
|
// Container width
|
|
145
154
|
let maxWidth = containerRect.width;
|
|
146
|
-
if (
|
|
155
|
+
if (
|
|
156
|
+
maxWidth === state.lastMaxWidth ||
|
|
157
|
+
(!state.hasMore && maxWidth > state.lastMaxWidth)
|
|
158
|
+
) {
|
|
147
159
|
return;
|
|
148
160
|
}
|
|
149
161
|
state.lastMaxWidth = maxWidth;
|
|
@@ -220,6 +232,7 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
// Show or hide more button
|
|
235
|
+
state.hasMore = hasMore;
|
|
223
236
|
setElementVisible(buttonMore, hasMore);
|
|
224
237
|
setElementVisible(resetButton, true);
|
|
225
238
|
|
|
@@ -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>
|