@etsoo/react 1.4.21 → 1.4.25

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.
@@ -1,7 +1,6 @@
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 { CommonPageProps } from './CommonPageProps';
@@ -10,11 +9,6 @@ import { ReactAppStateDetector } from '../../app/ReactApp';
10
9
  import { Container, Fab } from '@mui/material';
11
10
  import RefreshIcon from '@mui/icons-material/Refresh';
12
11
 
13
- /**
14
- * Default pull container
15
- */
16
- export const CommonPagePullContainer = '#page-container';
17
-
18
12
  /**
19
13
  * Default scroll container
20
14
  */
@@ -41,7 +35,6 @@ export function CommonPage(props: CommonPageProps) {
41
35
  paddings = MUGlobal.pagePaddings,
42
36
  scrollContainer,
43
37
  targetFields,
44
- pullContainer,
45
38
  sx = {},
46
39
  ...rest
47
40
  } = props;
@@ -125,20 +118,6 @@ export function CommonPage(props: CommonPageProps) {
125
118
  </FabBox>
126
119
  {children}
127
120
  </Container>
128
- {onRefresh != null && pullContainer != null && (
129
- <PullToRefreshUI
130
- mainElement={pullContainer}
131
- triggerElement={pullContainer}
132
- instructionsPullToRefresh={labels.pullToRefresh}
133
- instructionsReleaseToRefresh={labels.releaseToRefresh}
134
- instructionsRefreshing={labels.refreshing}
135
- onRefresh={onRefresh}
136
- shouldPullToRefresh={() => {
137
- const container = document.querySelector(pullContainer);
138
- return !container?.scrollTop;
139
- }}
140
- />
141
- )}
142
121
  </React.Fragment>
143
122
  );
144
123
  }
@@ -54,11 +54,6 @@ export interface CommonPageProps extends Omit<ContainerProps, 'id'> {
54
54
  */
55
55
  paddings?: {};
56
56
 
57
- /**
58
- * Pull container
59
- */
60
- pullContainer?: string;
61
-
62
57
  /**
63
58
  * Scroll container
64
59
  */
@@ -113,18 +113,9 @@ export function DataGridPage<
113
113
  ref.reset({ data });
114
114
  }, [ref, data]);
115
115
 
116
- // Pull container id
117
- const pullContainer = states.element?.parentElement
118
- ? '.DataGridEx-Body'
119
- : undefined;
120
-
121
116
  // Layout
122
117
  return (
123
- <CommonPage
124
- {...pageProps}
125
- scrollContainer={states.element}
126
- pullContainer={pullContainer}
127
- >
118
+ <CommonPage {...pageProps} scrollContainer={states.element}>
128
119
  <Stack>
129
120
  <Box
130
121
  ref={dimensions[0][0]}
@@ -113,11 +113,6 @@ export function FixedListPage<
113
113
  }
114
114
  }, [rect]);
115
115
 
116
- // Pull container id
117
- const pullContainer = scrollContainer?.parentElement
118
- ? '#' + scrollContainer?.parentElement.id
119
- : undefined;
120
-
121
116
  const { paddings, ...pageRest } = pageProps;
122
117
 
123
118
  // Layout
@@ -126,7 +121,6 @@ export function FixedListPage<
126
121
  {...pageRest}
127
122
  paddings={{}}
128
123
  scrollContainer={scrollContainer}
129
- pullContainer={pullContainer}
130
124
  >
131
125
  <Stack>
132
126
  <Box ref={dimensions[0][0]} sx={{ padding: paddings }}>
@@ -7,11 +7,7 @@ import useCombinedRefs from '../../uses/useCombinedRefs';
7
7
  import { MUGlobal } from '../MUGlobal';
8
8
  import { ScrollerListEx } from '../ScrollerListEx';
9
9
  import { SearchBar } from '../SearchBar';
10
- import {
11
- CommonPage,
12
- CommonPagePullContainer,
13
- CommonPageScrollContainer
14
- } from './CommonPage';
10
+ import { CommonPage, CommonPageScrollContainer } from './CommonPage';
15
11
  import { ListPageProps } from './ListPageProps';
16
12
 
17
13
  /**
@@ -69,11 +65,7 @@ export function ListPage<
69
65
 
70
66
  // Layout
71
67
  return (
72
- <CommonPage
73
- {...pageProps}
74
- scrollContainer={CommonPageScrollContainer}
75
- pullContainer={CommonPagePullContainer}
76
- >
68
+ <CommonPage {...pageProps} scrollContainer={CommonPageScrollContainer}>
77
69
  <Stack>
78
70
  <Box
79
71
  sx={{
@@ -1,24 +1,10 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { Box, Stack } from '@mui/material';
3
2
  import React from 'react';
4
- import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
5
- import useCombinedRefs from '../../uses/useCombinedRefs';
6
- import { useDimensions } from '../../uses/useDimensions';
7
- import { DataGridEx, DataGridExCalColumns } from '../DataGridEx';
8
- import { GridMethodRef } from '../GridMethodRef';
9
3
  import { MUGlobal } from '../MUGlobal';
10
- import { ScrollerListEx } from '../ScrollerListEx';
11
- import { SearchBar } from '../SearchBar';
4
+ import { ResponsibleContainer } from '../ResponsibleContainer';
12
5
  import { CommonPage } from './CommonPage';
13
6
  import { ResponsePageProps } from './ResponsivePageProps';
14
7
 
15
- interface LocalStates {
16
- data?: FormData;
17
- element?: HTMLElement;
18
- height?: number;
19
- ref?: GridMethodRef;
20
- }
21
-
22
8
  /**
23
9
  * Fixed height list page
24
10
  * @param props Props
@@ -29,193 +15,33 @@ export function ResponsivePage<
29
15
  F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate
30
16
  >(props: ResponsePageProps<T, F>) {
31
17
  // Destruct
32
- const {
33
- adjustHeight,
34
- columns,
35
- dataGridMinWidth = DataGridExCalColumns(columns).total,
36
- fields,
37
- fieldTemplate,
38
- height,
39
- loadData,
40
- innerItemRenderer,
41
- itemSize,
42
- mRef,
43
- sizeReadyMiliseconds = 0,
44
- pageProps = {},
45
- ...rest
46
- } = props;
18
+ const { pageProps = {}, ...rest } = props;
47
19
 
48
20
  pageProps.paddings ??= MUGlobal.pagePaddings;
49
-
50
- // States
51
- const [states, setStates] = React.useReducer(
52
- (currentState: LocalStates, newState: Partial<LocalStates>) => {
53
- return { ...currentState, ...newState };
54
- },
55
- {
56
- height
57
- }
58
- );
59
-
60
- const localLoadData = (props: GridLoadDataProps) => {
61
- const data = GridDataGet(props, fieldTemplate);
62
- return loadData(data);
63
- };
64
-
65
- const refs = useCombinedRefs(mRef, (ref: GridMethodRef) => {
66
- if (ref == null) return;
67
- states.ref = ref;
68
- // setStates({ ref });
69
- });
70
-
71
- // On submit callback
72
- const onSubmit = (data: FormData, _reset: boolean) => {
73
- setStates({ data });
74
- };
75
-
76
- // Watch container
77
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
78
- const rect = dimensions[0][2];
79
- const showDataGrid = (rect?.width ?? 0) >= dataGridMinWidth;
80
-
81
- React.useEffect(() => {
82
- if (rect != null && rect.height > 50 && height == null) {
83
- let gridHeight =
84
- window.innerHeight - Math.round(rect.top + rect.height + 1);
85
-
86
- const style = window.getComputedStyle(dimensions[0][1]!);
87
- const boxPadding = parseFloat(style.paddingLeft);
88
- if (!isNaN(boxPadding)) gridHeight -= 2 * boxPadding;
89
-
90
- if (adjustHeight != null) {
91
- gridHeight -= adjustHeight(gridHeight);
92
- }
93
-
94
- if (gridHeight !== states.height) setStates({ height: gridHeight });
95
- }
96
- }, [rect]);
97
-
98
21
  const { paddings, ...pageRest } = pageProps;
99
22
 
100
- const list = React.useMemo(() => {
101
- const gridHeight = states.height;
102
- if (gridHeight == null) return;
103
-
104
- // Show in a row when under DataGrid
105
- pageProps.fabColumnDirection = !showDataGrid;
106
-
107
- if (showDataGrid) {
108
- // Delete
109
- delete rest.itemRenderer;
110
-
111
- return (
112
- <Box
113
- sx={{
114
- padding: paddings
115
- }}
116
- >
117
- <DataGridEx<T>
118
- autoLoad={false}
119
- height={gridHeight}
120
- loadData={localLoadData}
121
- mRef={refs}
122
- columns={columns}
123
- outerRef={(element?: HTMLDivElement) => {
124
- if (element != null) setStates({ element });
125
- }}
126
- {...rest}
127
- />
128
- </Box>
129
- );
130
- }
131
-
132
- // Delete
133
- delete rest.checkable;
134
- delete rest.borderRowsCount;
135
- delete rest.bottomHeight;
136
- delete rest.footerItemRenderer;
137
- delete rest.headerHeight;
138
- delete rest.hideFooter;
139
- delete rest.hoverColor;
140
- delete rest.selectable;
141
-
142
- // Half
143
- const halfPadding = MUGlobal.half(paddings);
144
- const style = window.getComputedStyle(dimensions[0][1]!);
145
- const boxPadding = parseFloat(style.paddingLeft);
146
-
147
- return (
148
- <Box
149
- sx={{
150
- height: gridHeight + (isNaN(boxPadding) ? 0 : boxPadding),
151
- paddingTop: halfPadding,
152
- paddingBottom: halfPadding
153
- }}
154
- >
155
- <ScrollerListEx<T>
156
- autoLoad={false}
157
- height={gridHeight}
158
- innerItemRenderer={innerItemRenderer}
159
- itemSize={itemSize}
160
- loadData={localLoadData}
161
- mRef={refs}
162
- oRef={(element) => {
163
- if (element != null) setStates({ element });
164
- }}
165
- {...rest}
166
- />
167
- </Box>
168
- );
169
- }, [states.height, showDataGrid, localLoadData]);
170
-
171
- const sizeRef = React.useRef<[number, number]>();
172
-
173
- const { ref, data } = states;
174
- React.useEffect(() => {
175
- if (ref == null || data == null || rect == null) return;
176
-
177
- // Resize without reset
178
- if (sizeRef.current == null) {
179
- sizeRef.current = [rect.width, rect.height];
180
- } else if (
181
- sizeRef.current[0] !== rect.width ||
182
- sizeRef.current[1] !== rect.height
183
- ) {
184
- sizeRef.current = [rect.width, rect.height];
185
- return;
186
- }
187
-
188
- ref.reset({ data });
189
- });
190
-
191
- // Pull container id
192
- const pullContainer = states.element
193
- ? showDataGrid
194
- ? '.DataGridEx-Body'
195
- : '.ScrollerListEx-Body'
196
- : undefined;
23
+ const halfPadding = MUGlobal.half(paddings);
197
24
 
198
25
  // Layout
199
26
  return (
200
- <CommonPage
201
- {...pageRest}
202
- paddings={{}}
203
- scrollContainer={states.element}
204
- pullContainer={pullContainer}
205
- >
206
- <Stack>
207
- <Box
208
- ref={dimensions[0][0]}
209
- sx={{
210
- paddingLeft: paddings,
211
- paddingTop: MUGlobal.increase(paddings, 0.5, 'xs'),
212
- paddingRight: paddings
213
- }}
214
- >
215
- <SearchBar fields={fields} onSubmit={onSubmit} />
216
- </Box>
217
- {list}
218
- </Stack>
27
+ <CommonPage {...pageRest} paddings={{}}>
28
+ <ResponsibleContainer<T, F>
29
+ paddings={paddings}
30
+ listBoxSx={(dataGrid, height) => {
31
+ if (dataGrid) {
32
+ return {
33
+ padding: paddings
34
+ };
35
+ } else {
36
+ return {
37
+ height,
38
+ paddingTop: halfPadding,
39
+ paddingBottom: halfPadding
40
+ };
41
+ }
42
+ }}
43
+ {...rest}
44
+ />
219
45
  </CommonPage>
220
46
  );
221
47
  }
@@ -38,4 +38,9 @@ export interface ResponsePageProps<T, F extends DataTypes.BasicTemplate>
38
38
  * Methods
39
39
  */
40
40
  mRef?: React.MutableRefObject<GridMethodRef | undefined>;
41
+
42
+ /**
43
+ * Pull to refresh data
44
+ */
45
+ pullToRefresh?: boolean;
41
46
  }
@@ -7,11 +7,7 @@ import { useDimensions } from '../../uses/useDimensions';
7
7
  import { MUGlobal } from '../MUGlobal';
8
8
  import { SearchBar } from '../SearchBar';
9
9
  import { TableEx, TableExMethodRef, TableExMinWidth } from '../TableEx';
10
- import {
11
- CommonPage,
12
- CommonPagePullContainer,
13
- CommonPageScrollContainer
14
- } from './CommonPage';
10
+ import { CommonPage, CommonPageScrollContainer } from './CommonPage';
15
11
  import { TablePageProps } from './TablePageProps';
16
12
 
17
13
  /**
@@ -104,11 +100,7 @@ export function TablePage<
104
100
 
105
101
  // Layout
106
102
  return (
107
- <CommonPage
108
- {...pageProps}
109
- scrollContainer={CommonPageScrollContainer}
110
- pullContainer={CommonPagePullContainer}
111
- >
103
+ <CommonPage {...pageProps} scrollContainer={CommonPageScrollContainer}>
112
104
  <Stack>
113
105
  <Box
114
106
  ref={dimensions[0][0]}