@etsoo/materialui 1.1.56 → 1.1.58

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.
@@ -12,12 +12,9 @@ export type ResponsibleContainerProps<T extends object, F extends DataTypes.Basi
12
12
  /**
13
13
  * Height will be deducted
14
14
  * @param height Current calcuated height
15
+ * @param rect Current rect data
15
16
  */
16
- adjustHeight?: (height: number) => number;
17
- /**
18
- * Top height
19
- */
20
- topHeight?: number;
17
+ adjustHeight?: (height: number, rect: DOMRect) => number;
21
18
  /**
22
19
  * Columns
23
20
  */
@@ -22,7 +22,7 @@ function defaultContainerBoxSx(paddings, hasField, _dataGrid) {
22
22
  */
23
23
  export function ResponsibleContainer(props) {
24
24
  // Destruct
25
- const { adjustHeight, columns, containerBoxSx = defaultContainerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, topHeight, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, quickAction, sizeReadyMiliseconds = 0, searchBarHeight, ...rest } = props;
25
+ const { adjustHeight, columns, containerBoxSx = defaultContainerBoxSx, dataGridMinWidth = Math.max(576, DataGridExCalColumns(columns).total), elementReady, fields, fieldTemplate, height, loadData, mRef, paddings = MUGlobal.pagePaddings, pullToRefresh = true, quickAction, sizeReadyMiliseconds = 0, searchBarHeight, ...rest } = props;
26
26
  // Labels
27
27
  const labels = Labels.CommonPage;
28
28
  // Refs
@@ -89,15 +89,13 @@ export function ResponsibleContainer(props) {
89
89
  else {
90
90
  // Auto calculation
91
91
  heightLocal =
92
- document.documentElement.clientHeight -
93
- (topHeight !== null && topHeight !== void 0 ? topHeight : Math.round(rect.bottom + 1));
92
+ document.documentElement.clientHeight - Math.round(rect.bottom + 1);
94
93
  const style = window.getComputedStyle(dimensions[0][1]);
95
94
  const boxMargin = parseFloat(style.marginBottom);
96
95
  if (!isNaN(boxMargin))
97
96
  heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
98
- if (adjustHeight != null) {
99
- heightLocal -= adjustHeight(heightLocal);
100
- }
97
+ if (adjustHeight != null)
98
+ heightLocal -= adjustHeight(heightLocal, rect);
101
99
  }
102
100
  if (showDataGrid) {
103
101
  // Delete
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
3
- import { DataGridPageProps } from './DataGridPageProps';
2
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
3
+ import { DataGridPageProps } from "./DataGridPageProps";
4
4
  /**
5
5
  * DataGrid page
6
6
  * @param props Props
@@ -1,10 +1,10 @@
1
- import { GridDataGet, useCombinedRefs, useDimensions } from '@etsoo/react';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { DataGridEx } from '../DataGridEx';
5
- import { MUGlobal } from '../MUGlobal';
6
- import { SearchBar } from '../SearchBar';
7
- import { CommonPage } from './CommonPage';
1
+ import { GridDataGet, useCombinedRefs, useDimensions } from "@etsoo/react";
2
+ import { Box, Stack } from "@mui/material";
3
+ import React from "react";
4
+ import { DataGridEx } from "../DataGridEx";
5
+ import { MUGlobal } from "../MUGlobal";
6
+ import { SearchBar } from "../SearchBar";
7
+ import { CommonPage } from "./CommonPage";
8
8
  /**
9
9
  * DataGrid page
10
10
  * @param props Props
@@ -46,9 +46,8 @@ export function DataGridPage(props) {
46
46
  const paddingBottom = parseFloat(style.paddingBottom);
47
47
  if (!isNaN(paddingBottom))
48
48
  gridHeight -= paddingBottom;
49
- if (adjustHeight != null) {
50
- gridHeight -= adjustHeight(gridHeight);
51
- }
49
+ if (adjustHeight != null)
50
+ gridHeight -= adjustHeight(gridHeight, rect);
52
51
  if (gridHeight !== states.height)
53
52
  setStates({ height: gridHeight });
54
53
  }
@@ -1,15 +1,16 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { DataGridExProps } from '../DataGridEx';
3
- import { SearchPageProps } from './SearchPageProps';
1
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
2
+ import { DataGridExProps } from "../DataGridEx";
3
+ import { SearchPageProps } from "./SearchPageProps";
4
4
  /**
5
5
  * DataGrid page props
6
6
  */
7
- export type DataGridPageProps<T extends object, F extends DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = IdDefaultType<T>> = SearchPageProps<T, F> & Omit<DataGridExProps<T, D>, 'loadData' | 'height'> & {
7
+ export type DataGridPageProps<T extends object, F extends DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = IdDefaultType<T>> = SearchPageProps<T, F> & Omit<DataGridExProps<T, D>, "loadData" | "height"> & {
8
8
  /**
9
9
  * Height will be deducted
10
10
  * @param height Current calcuated height
11
+ * @param rect Current rect data
11
12
  */
12
- adjustHeight?: (height: number) => number;
13
+ adjustHeight?: (height: number, rect: DOMRect) => number;
13
14
  /**
14
15
  * Grid height
15
16
  */
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
3
- import { ListPageProps } from './ListPageProps';
2
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
3
+ import { ListPageProps } from "./ListPageProps";
4
4
  /**
5
5
  * Fixed height list page
6
6
  * @param props Props
@@ -10,6 +10,7 @@ export declare function FixedListPage<T extends object, F extends DataTypes.Basi
10
10
  /**
11
11
  * Height will be deducted
12
12
  * @param height Current calcuated height
13
+ * @param rect Current rect data
13
14
  */
14
- adjustHeight?: (height: number) => number;
15
+ adjustHeight?: (height: number, rect: DOMRect) => number;
15
16
  }): JSX.Element;
@@ -1,10 +1,10 @@
1
- import { GridDataGet, useCombinedRefs, useDimensions } from '@etsoo/react';
2
- import { Box, Stack } from '@mui/material';
3
- import React from 'react';
4
- import { MUGlobal } from '../MUGlobal';
5
- import { ScrollerListEx } from '../ScrollerListEx';
6
- import { SearchBar } from '../SearchBar';
7
- import { CommonPage } from './CommonPage';
1
+ import { GridDataGet, useCombinedRefs, useDimensions } from "@etsoo/react";
2
+ import { Box, Stack } from "@mui/material";
3
+ import React from "react";
4
+ import { MUGlobal } from "../MUGlobal";
5
+ import { ScrollerListEx } from "../ScrollerListEx";
6
+ import { SearchBar } from "../SearchBar";
7
+ import { CommonPage } from "./CommonPage";
8
8
  /**
9
9
  * Fixed height list page
10
10
  * @param props Props
@@ -48,11 +48,10 @@ export function FixedListPage(props) {
48
48
  if (rect != null && rect.height > 50) {
49
49
  let height = document.documentElement.clientHeight -
50
50
  Math.round(rect.top + rect.height + 1);
51
- if (adjustHeight != null) {
52
- height -= adjustHeight(height);
53
- }
51
+ if (adjustHeight != null)
52
+ height -= adjustHeight(height, rect);
54
53
  return (React.createElement(Box, { id: "list-container", sx: {
55
- height: height + 'px'
54
+ height: height + "px"
56
55
  } },
57
56
  React.createElement(ScrollerListEx, { autoLoad: false, height: height, loadData: localLoadData, mRef: refs, oRef: (element) => {
58
57
  if (element != null)
@@ -27,10 +27,6 @@ export type SearchPageProps<T extends object, F extends DataTypes.BasicTemplate>
27
27
  * @default 100
28
28
  */
29
29
  sizeReadyMiliseconds?: number;
30
- /**
31
- * Top height
32
- */
33
- topHeight?: number;
34
30
  /**
35
31
  * SearchBar height
36
32
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.56",
3
+ "version": "1.1.58",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -41,13 +41,9 @@ export type ResponsibleContainerProps<
41
41
  /**
42
42
  * Height will be deducted
43
43
  * @param height Current calcuated height
44
+ * @param rect Current rect data
44
45
  */
45
- adjustHeight?: (height: number) => number;
46
-
47
- /**
48
- * Top height
49
- */
50
- topHeight?: number;
46
+ adjustHeight?: (height: number, rect: DOMRect) => number;
51
47
 
52
48
  /**
53
49
  * Columns
@@ -182,7 +178,6 @@ export function ResponsibleContainer<
182
178
  fields,
183
179
  fieldTemplate,
184
180
  height,
185
- topHeight,
186
181
  loadData,
187
182
  mRef,
188
183
  paddings = MUGlobal.pagePaddings,
@@ -277,16 +272,13 @@ export function ResponsibleContainer<
277
272
  } else {
278
273
  // Auto calculation
279
274
  heightLocal =
280
- document.documentElement.clientHeight -
281
- (topHeight ?? Math.round(rect.bottom + 1));
275
+ document.documentElement.clientHeight - Math.round(rect.bottom + 1);
282
276
 
283
277
  const style = window.getComputedStyle(dimensions[0][1]!);
284
278
  const boxMargin = parseFloat(style.marginBottom);
285
279
  if (!isNaN(boxMargin)) heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
286
280
 
287
- if (adjustHeight != null) {
288
- heightLocal -= adjustHeight(heightLocal);
289
- }
281
+ if (adjustHeight != null) heightLocal -= adjustHeight(heightLocal, rect);
290
282
  }
291
283
 
292
284
  if (showDataGrid) {
@@ -1,24 +1,24 @@
1
1
  import {
2
- GridDataGet,
3
- GridLoadDataProps,
4
- ScrollerGridForwardRef,
5
- useCombinedRefs,
6
- useDimensions
7
- } from '@etsoo/react';
8
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
9
- import { Box, Stack } from '@mui/material';
10
- import React from 'react';
11
- import { DataGridEx } from '../DataGridEx';
12
- import { MUGlobal } from '../MUGlobal';
13
- import { SearchBar } from '../SearchBar';
14
- import { CommonPage } from './CommonPage';
15
- import { DataGridPageProps } from './DataGridPageProps';
2
+ GridDataGet,
3
+ GridLoadDataProps,
4
+ ScrollerGridForwardRef,
5
+ useCombinedRefs,
6
+ useDimensions
7
+ } from "@etsoo/react";
8
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
9
+ import { Box, Stack } from "@mui/material";
10
+ import React from "react";
11
+ import { DataGridEx } from "../DataGridEx";
12
+ import { MUGlobal } from "../MUGlobal";
13
+ import { SearchBar } from "../SearchBar";
14
+ import { CommonPage } from "./CommonPage";
15
+ import { DataGridPageProps } from "./DataGridPageProps";
16
16
 
17
17
  interface LocalStates<T> {
18
- data?: FormData;
19
- element?: HTMLElement;
20
- height?: number;
21
- ref?: ScrollerGridForwardRef<T>;
18
+ data?: FormData;
19
+ element?: HTMLElement;
20
+ height?: number;
21
+ ref?: ScrollerGridForwardRef<T>;
22
22
  }
23
23
 
24
24
  /**
@@ -27,114 +27,112 @@ interface LocalStates<T> {
27
27
  * @returns Component
28
28
  */
29
29
  export function DataGridPage<
30
- T extends object,
31
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
32
- D extends DataTypes.Keys<T> = IdDefaultType<T>
30
+ T extends object,
31
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
32
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
33
33
  >(props: DataGridPageProps<T, F, D>) {
34
- // Destruct
35
- const {
36
- adjustHeight,
37
- fields,
38
- fieldTemplate,
39
- height,
40
- loadData,
41
- mRef,
42
- sizeReadyMiliseconds = 100,
43
- pageProps = {},
44
- ...rest
45
- } = props;
46
-
47
- pageProps.paddings ??= MUGlobal.pagePaddings;
48
-
49
- // States
50
- const [states, setStates] = React.useReducer(
51
- (currentState: LocalStates<T>, newState: Partial<LocalStates<T>>) => {
52
- return { ...currentState, ...newState };
53
- },
54
- {
55
- height
56
- }
57
- );
58
-
59
- const refs = useCombinedRefs<ScrollerGridForwardRef<T>>(
60
- mRef,
61
- (ref: ScrollerGridForwardRef<T> | null | undefined) => {
62
- if (ref == null) return;
63
- states.ref = ref;
64
- //setStates({ ref });
65
- }
66
- );
34
+ // Destruct
35
+ const {
36
+ adjustHeight,
37
+ fields,
38
+ fieldTemplate,
39
+ height,
40
+ loadData,
41
+ mRef,
42
+ sizeReadyMiliseconds = 100,
43
+ pageProps = {},
44
+ ...rest
45
+ } = props;
46
+
47
+ pageProps.paddings ??= MUGlobal.pagePaddings;
48
+
49
+ // States
50
+ const [states, setStates] = React.useReducer(
51
+ (currentState: LocalStates<T>, newState: Partial<LocalStates<T>>) => {
52
+ return { ...currentState, ...newState };
53
+ },
54
+ {
55
+ height
56
+ }
57
+ );
58
+
59
+ const refs = useCombinedRefs<ScrollerGridForwardRef<T>>(
60
+ mRef,
61
+ (ref: ScrollerGridForwardRef<T> | null | undefined) => {
62
+ if (ref == null) return;
63
+ states.ref = ref;
64
+ //setStates({ ref });
65
+ }
66
+ );
67
+
68
+ // On submit callback
69
+ const onSubmit = (data: FormData, _reset: boolean) => {
70
+ setStates({ data });
71
+ };
72
+
73
+ const localLoadData = (props: GridLoadDataProps) => {
74
+ const data = GridDataGet(props, fieldTemplate);
75
+ return loadData(data);
76
+ };
77
+
78
+ // Watch container
79
+ const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
80
+ const rect = dimensions[0][2];
81
+
82
+ React.useEffect(() => {
83
+ if (rect != null && rect.height > 50 && height == null) {
84
+ let gridHeight =
85
+ document.documentElement.clientHeight -
86
+ Math.round(rect.top + rect.height + 1);
87
+
88
+ const style = window.getComputedStyle(dimensions[0][1]!);
89
+ const paddingBottom = parseFloat(style.paddingBottom);
90
+ if (!isNaN(paddingBottom)) gridHeight -= paddingBottom;
91
+
92
+ if (adjustHeight != null) gridHeight -= adjustHeight(gridHeight, rect);
93
+
94
+ if (gridHeight !== states.height) setStates({ height: gridHeight });
95
+ }
96
+ }, [rect]);
97
+
98
+ const list = React.useMemo(() => {
99
+ const gridHeight = states.height;
100
+ if (gridHeight == null) return;
67
101
 
68
- // On submit callback
69
- const onSubmit = (data: FormData, _reset: boolean) => {
70
- setStates({ data });
71
- };
72
-
73
- const localLoadData = (props: GridLoadDataProps) => {
74
- const data = GridDataGet(props, fieldTemplate);
75
- return loadData(data);
76
- };
77
-
78
- // Watch container
79
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
80
- const rect = dimensions[0][2];
81
-
82
- React.useEffect(() => {
83
- if (rect != null && rect.height > 50 && height == null) {
84
- let gridHeight =
85
- document.documentElement.clientHeight -
86
- Math.round(rect.top + rect.height + 1);
87
-
88
- const style = window.getComputedStyle(dimensions[0][1]!);
89
- const paddingBottom = parseFloat(style.paddingBottom);
90
- if (!isNaN(paddingBottom)) gridHeight -= paddingBottom;
91
-
92
- if (adjustHeight != null) {
93
- gridHeight -= adjustHeight(gridHeight);
94
- }
95
-
96
- if (gridHeight !== states.height) setStates({ height: gridHeight });
97
- }
98
- }, [rect]);
99
-
100
- const list = React.useMemo(() => {
101
- const gridHeight = states.height;
102
- if (gridHeight == null) return;
103
-
104
- return (
105
- <DataGridEx<T, D>
106
- autoLoad={false}
107
- height={gridHeight}
108
- loadData={localLoadData}
109
- mRef={refs}
110
- outerRef={(element?: HTMLDivElement) => {
111
- if (element != null) setStates({ element });
112
- }}
113
- {...rest}
114
- />
115
- );
116
- }, [states.height]);
117
-
118
- const { ref, data } = states;
119
- React.useEffect(() => {
120
- if (ref == null || data == null) return;
121
- ref.reset({ data });
122
- }, [ref, data]);
123
-
124
- // Layout
125
102
  return (
126
- <CommonPage {...pageProps} scrollContainer={states.element}>
127
- <Stack>
128
- <Box
129
- ref={dimensions[0][0]}
130
- sx={{
131
- paddingBottom: pageProps.paddings
132
- }}
133
- >
134
- <SearchBar fields={fields} onSubmit={onSubmit} />
135
- </Box>
136
- {list}
137
- </Stack>
138
- </CommonPage>
103
+ <DataGridEx<T, D>
104
+ autoLoad={false}
105
+ height={gridHeight}
106
+ loadData={localLoadData}
107
+ mRef={refs}
108
+ outerRef={(element?: HTMLDivElement) => {
109
+ if (element != null) setStates({ element });
110
+ }}
111
+ {...rest}
112
+ />
139
113
  );
114
+ }, [states.height]);
115
+
116
+ const { ref, data } = states;
117
+ React.useEffect(() => {
118
+ if (ref == null || data == null) return;
119
+ ref.reset({ data });
120
+ }, [ref, data]);
121
+
122
+ // Layout
123
+ return (
124
+ <CommonPage {...pageProps} scrollContainer={states.element}>
125
+ <Stack>
126
+ <Box
127
+ ref={dimensions[0][0]}
128
+ sx={{
129
+ paddingBottom: pageProps.paddings
130
+ }}
131
+ >
132
+ <SearchBar fields={fields} onSubmit={onSubmit} />
133
+ </Box>
134
+ {list}
135
+ </Stack>
136
+ </CommonPage>
137
+ );
140
138
  }
@@ -1,24 +1,25 @@
1
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
- import { DataGridExProps } from '../DataGridEx';
3
- import { SearchPageProps } from './SearchPageProps';
1
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
2
+ import { DataGridExProps } from "../DataGridEx";
3
+ import { SearchPageProps } from "./SearchPageProps";
4
4
 
5
5
  /**
6
6
  * DataGrid page props
7
7
  */
8
8
  export type DataGridPageProps<
9
- T extends object,
10
- F extends DataTypes.BasicTemplate,
11
- D extends DataTypes.Keys<T> = IdDefaultType<T>
9
+ T extends object,
10
+ F extends DataTypes.BasicTemplate,
11
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
12
12
  > = SearchPageProps<T, F> &
13
- Omit<DataGridExProps<T, D>, 'loadData' | 'height'> & {
14
- /**
15
- * Height will be deducted
16
- * @param height Current calcuated height
17
- */
18
- adjustHeight?: (height: number) => number;
13
+ Omit<DataGridExProps<T, D>, "loadData" | "height"> & {
14
+ /**
15
+ * Height will be deducted
16
+ * @param height Current calcuated height
17
+ * @param rect Current rect data
18
+ */
19
+ adjustHeight?: (height: number, rect: DOMRect) => number;
19
20
 
20
- /**
21
- * Grid height
22
- */
23
- height?: number;
24
- };
21
+ /**
22
+ * Grid height
23
+ */
24
+ height?: number;
25
+ };
@@ -1,18 +1,18 @@
1
1
  import {
2
- GridDataGet,
3
- GridLoadDataProps,
4
- ScrollerListForwardRef,
5
- useCombinedRefs,
6
- useDimensions
7
- } from '@etsoo/react';
8
- import { DataTypes, IdDefaultType } from '@etsoo/shared';
9
- import { Box, Stack } from '@mui/material';
10
- import React from 'react';
11
- import { MUGlobal } from '../MUGlobal';
12
- import { ScrollerListEx } from '../ScrollerListEx';
13
- import { SearchBar } from '../SearchBar';
14
- import { CommonPage } from './CommonPage';
15
- import { ListPageProps } from './ListPageProps';
2
+ GridDataGet,
3
+ GridLoadDataProps,
4
+ ScrollerListForwardRef,
5
+ useCombinedRefs,
6
+ useDimensions
7
+ } from "@etsoo/react";
8
+ import { DataTypes, IdDefaultType } from "@etsoo/shared";
9
+ import { Box, Stack } from "@mui/material";
10
+ import React from "react";
11
+ import { MUGlobal } from "../MUGlobal";
12
+ import { ScrollerListEx } from "../ScrollerListEx";
13
+ import { SearchBar } from "../SearchBar";
14
+ import { CommonPage } from "./CommonPage";
15
+ import { ListPageProps } from "./ListPageProps";
16
16
 
17
17
  /**
18
18
  * Fixed height list page
@@ -20,122 +20,117 @@ import { ListPageProps } from './ListPageProps';
20
20
  * @returns Component
21
21
  */
22
22
  export function FixedListPage<
23
- T extends object,
24
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
25
- D extends DataTypes.Keys<T> = IdDefaultType<T>
23
+ T extends object,
24
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
25
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
26
26
  >(
27
- props: ListPageProps<T, F, D> & {
28
- /**
29
- * Height will be deducted
30
- * @param height Current calcuated height
31
- */
32
- adjustHeight?: (height: number) => number;
33
- }
27
+ props: ListPageProps<T, F, D> & {
28
+ /**
29
+ * Height will be deducted
30
+ * @param height Current calcuated height
31
+ * @param rect Current rect data
32
+ */
33
+ adjustHeight?: (height: number, rect: DOMRect) => number;
34
+ }
34
35
  ) {
35
- // Destruct
36
- const {
37
- adjustHeight,
38
- fields,
39
- fieldTemplate,
40
- loadData,
41
- mRef,
42
- sizeReadyMiliseconds = 0,
43
- pageProps = {},
44
- ...rest
45
- } = props;
46
-
47
- pageProps.paddings ??= MUGlobal.pagePaddings;
48
-
49
- // States
50
- const [states] = React.useState<{
51
- data?: FormData;
52
- ref?: ScrollerListForwardRef<T>;
53
- }>({});
54
-
55
- // Scroll container
56
- const [scrollContainer, updateScrollContainer] = React.useState<
57
- HTMLElement | undefined
58
- >();
59
-
60
- const refs = useCombinedRefs(
61
- mRef,
62
- (ref: ScrollerListForwardRef<T> | null | undefined) => {
63
- if (ref == null) return;
64
-
65
- const first = states.ref == null;
66
-
67
- states.ref = ref;
68
-
69
- if (first) reset();
70
- }
71
- );
72
-
73
- const reset = () => {
74
- if (states.data == null || states.ref == null) return;
75
- states.ref.reset({ data: states.data });
76
- };
77
-
78
- // On submit callback
79
- const onSubmit = (data: FormData, _reset: boolean) => {
80
- states.data = data;
81
- reset();
82
- };
83
-
84
- const localLoadData = (props: GridLoadDataProps) => {
85
- const data = GridDataGet(props, fieldTemplate);
86
- return loadData(data);
87
- };
88
-
89
- // Watch container
90
- const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
91
- const rect = dimensions[0][2];
92
- const list = React.useMemo(() => {
93
- if (rect != null && rect.height > 50) {
94
- let height =
95
- document.documentElement.clientHeight -
96
- Math.round(rect.top + rect.height + 1);
97
-
98
- if (adjustHeight != null) {
99
- height -= adjustHeight(height);
100
- }
101
-
102
- return (
103
- <Box
104
- id="list-container"
105
- sx={{
106
- height: height + 'px'
107
- }}
108
- >
109
- <ScrollerListEx<T, D>
110
- autoLoad={false}
111
- height={height}
112
- loadData={localLoadData}
113
- mRef={refs}
114
- oRef={(element) => {
115
- if (element != null) updateScrollContainer(element);
116
- }}
117
- {...rest}
118
- />
119
- </Box>
120
- );
121
- }
122
- }, [rect]);
123
-
124
- const { paddings, ...pageRest } = pageProps;
125
-
126
- // Layout
127
- return (
128
- <CommonPage
129
- {...pageRest}
130
- paddings={{}}
131
- scrollContainer={scrollContainer}
36
+ // Destruct
37
+ const {
38
+ adjustHeight,
39
+ fields,
40
+ fieldTemplate,
41
+ loadData,
42
+ mRef,
43
+ sizeReadyMiliseconds = 0,
44
+ pageProps = {},
45
+ ...rest
46
+ } = props;
47
+
48
+ pageProps.paddings ??= MUGlobal.pagePaddings;
49
+
50
+ // States
51
+ const [states] = React.useState<{
52
+ data?: FormData;
53
+ ref?: ScrollerListForwardRef<T>;
54
+ }>({});
55
+
56
+ // Scroll container
57
+ const [scrollContainer, updateScrollContainer] = React.useState<
58
+ HTMLElement | undefined
59
+ >();
60
+
61
+ const refs = useCombinedRefs(
62
+ mRef,
63
+ (ref: ScrollerListForwardRef<T> | null | undefined) => {
64
+ if (ref == null) return;
65
+
66
+ const first = states.ref == null;
67
+
68
+ states.ref = ref;
69
+
70
+ if (first) reset();
71
+ }
72
+ );
73
+
74
+ const reset = () => {
75
+ if (states.data == null || states.ref == null) return;
76
+ states.ref.reset({ data: states.data });
77
+ };
78
+
79
+ // On submit callback
80
+ const onSubmit = (data: FormData, _reset: boolean) => {
81
+ states.data = data;
82
+ reset();
83
+ };
84
+
85
+ const localLoadData = (props: GridLoadDataProps) => {
86
+ const data = GridDataGet(props, fieldTemplate);
87
+ return loadData(data);
88
+ };
89
+
90
+ // Watch container
91
+ const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
92
+ const rect = dimensions[0][2];
93
+ const list = React.useMemo(() => {
94
+ if (rect != null && rect.height > 50) {
95
+ let height =
96
+ document.documentElement.clientHeight -
97
+ Math.round(rect.top + rect.height + 1);
98
+
99
+ if (adjustHeight != null) height -= adjustHeight(height, rect);
100
+
101
+ return (
102
+ <Box
103
+ id="list-container"
104
+ sx={{
105
+ height: height + "px"
106
+ }}
132
107
  >
133
- <Stack>
134
- <Box ref={dimensions[0][0]} sx={{ padding: paddings }}>
135
- <SearchBar fields={fields} onSubmit={onSubmit} />
136
- </Box>
137
- {list}
138
- </Stack>
139
- </CommonPage>
140
- );
108
+ <ScrollerListEx<T, D>
109
+ autoLoad={false}
110
+ height={height}
111
+ loadData={localLoadData}
112
+ mRef={refs}
113
+ oRef={(element) => {
114
+ if (element != null) updateScrollContainer(element);
115
+ }}
116
+ {...rest}
117
+ />
118
+ </Box>
119
+ );
120
+ }
121
+ }, [rect]);
122
+
123
+ const { paddings, ...pageRest } = pageProps;
124
+
125
+ // Layout
126
+ return (
127
+ <CommonPage {...pageRest} paddings={{}} scrollContainer={scrollContainer}>
128
+ <Stack>
129
+ <Box ref={dimensions[0][0]} sx={{ padding: paddings }}>
130
+ <SearchBar fields={fields} onSubmit={onSubmit} />
131
+ </Box>
132
+ {list}
133
+ </Stack>
134
+ </CommonPage>
135
+ );
141
136
  }
@@ -37,11 +37,6 @@ export type SearchPageProps<
37
37
  */
38
38
  sizeReadyMiliseconds?: number;
39
39
 
40
- /**
41
- * Top height
42
- */
43
- topHeight?: number;
44
-
45
40
  /**
46
41
  * SearchBar height
47
42
  */